From 8ca63a521257e7e015e72c75e2e71f669e516aa6 Mon Sep 17 00:00:00 2001 From: Luka Andelic Date: Thu, 14 Dec 2023 09:20:06 +0100 Subject: [PATCH 1/2] Shopware Update 6.5 --- composer.json | 11 ++-- src/Resources/config/routes.xml | 2 +- src/Resources/config/services.xml | 5 +- .../group/box-card-group-select.html.twig | 2 +- .../line-item/type/product.html.twig | 52 +++++++++++++++++++ .../page/checkout/checkout-item.html.twig | 4 -- .../Controller/VariantSwitchController.php | 48 +++++++++-------- .../ProductListingConfigurationLoader.php | 13 +++-- src/Subscriber/CartPageLoadedSubscriber.php | 6 +-- 9 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 src/Resources/views/storefront/component/line-item/type/product.html.twig diff --git a/composer.json b/composer.json index 3c708d1..910b08c 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description":"Show a variant switch within the listing and cart", "type":"shopware-platform-plugin", "license":"MIT", - "version":"1.1.1", + "version":"2.0.0", "keywords":[ "variant", "shopware" @@ -21,8 +21,8 @@ } }, "require":{ - "shopware/core":"^6.4", - "shopware/storefront":"^6.4" + "shopware/core":"^6.5", + "shopware/storefront":"^6.5" }, "extra":{ "shopware-plugin-class":"SasVariantSwitch\\SasVariantSwitch", @@ -44,5 +44,10 @@ "de-DE":"https://shapeandshift.dev", "en-GB":"https://shapeandshift.dev" } + }, + "config": { + "allow-plugins": { + "symfony/runtime": true + } } } diff --git a/src/Resources/config/routes.xml b/src/Resources/config/routes.xml index bbf7380..2d76a11 100644 --- a/src/Resources/config/routes.xml +++ b/src/Resources/config/routes.xml @@ -5,5 +5,5 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - + diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index b78fe6c..e178005 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -24,7 +24,7 @@ - + @@ -32,6 +32,9 @@ + + + diff --git a/src/Resources/views/storefront/component/checkout/group/box-card-group-select.html.twig b/src/Resources/views/storefront/component/checkout/group/box-card-group-select.html.twig index 6591a28..6895356 100644 --- a/src/Resources/views/storefront/component/checkout/group/box-card-group-select.html.twig +++ b/src/Resources/views/storefront/component/checkout/group/box-card-group-select.html.twig @@ -6,7 +6,7 @@ {% endblock %} {% block component_offcanvas_product_details_variant_switch_configurator_select %} - {% for option in group.options %} {% set selected = false %} diff --git a/src/Resources/views/storefront/component/line-item/type/product.html.twig b/src/Resources/views/storefront/component/line-item/type/product.html.twig new file mode 100644 index 0000000..2fdea01 --- /dev/null +++ b/src/Resources/views/storefront/component/line-item/type/product.html.twig @@ -0,0 +1,52 @@ +{% sw_extends '@Storefront/storefront/component/line-item/type/product.html.twig' %} + +{% block component_line_item_type_product_variant_characteristics %} + {% if lineItem.type != 'product' or not config('SasVariantSwitch.config.showOnOffCanvasCart') %} + {{ parent() }} + {% endif %} +{% endblock %} + +{% block component_line_item_type_product_details %} + {{ parent() }} + {% if lineItem.type == 'product' and config('SasVariantSwitch.config.showOnOffCanvasCart') %} + {% block component_offcanvas_product_details_variant_switch %} + {% if lineItem.extensions.groups %} + {% set optionIds = lineItem.payload.optionIds %} + {% set parentId = lineItem.payload.parentId %} + +
+
+ + {% block component_offcanvas_product_details_variant_switch_form_redirect %} + + {% endblock %} + + {% block component_offcanvas_product_details_variant_switch_parent_id %} + + {% endblock %} + + {% block component_offcanvas_product_details_variant_switch_switched %} + + {% endblock %} + + {% for group in lineItem.extensions.groups %} + {% set groupIdentifier = [lineItem.referencedId, group.id]|join('-') %} + + {% block component_offcanvas_product_details_variant_switch_configurator_group %} +
+ {% sw_include '@Storefront/storefront/component/checkout/group/box-card-group-select.html.twig' %} +
+ {% endblock %} + {% endfor %} +
+
+ {% endif %} + {% endblock %} + {% endif %} +{% endblock %} diff --git a/src/Resources/views/storefront/page/checkout/checkout-item.html.twig b/src/Resources/views/storefront/page/checkout/checkout-item.html.twig index a5e8462..99d1221 100644 --- a/src/Resources/views/storefront/page/checkout/checkout-item.html.twig +++ b/src/Resources/views/storefront/page/checkout/checkout-item.html.twig @@ -21,10 +21,6 @@
- {% block page_checkout_item_info_features_variant_switch_form_csrf %} - {{ sw_csrf('sas.frontend.lineItem.variant.switch') }} - {% endblock %} - {% block page_checkout_item_quantity_redirect %} ['storefront']])] class VariantSwitchController extends StorefrontController { - private ProductCombinationFinder $combinationFinder; - private SalesChannelRepositoryInterface $productRepository; + private FindProductVariantRoute $combinationFinder; + private SalesChannelRepository $productRepository; private CartService $cartService; private LineItemFactoryRegistry $lineItemFactory; private EventDispatcherInterface $dispatcher; public function __construct( - ProductCombinationFinder $combinationFinder, - SalesChannelRepositoryInterface $productRepository, + FindProductVariantRoute $combinationFinder, + SalesChannelRepository $productRepository, CartService $cartService, LineItemFactoryRegistry $lineItemFactory, EventDispatcherInterface $dispatcher @@ -49,10 +47,7 @@ public function __construct( $this->lineItemFactory = $lineItemFactory; } - /** - * @HttpCache - * @Route("/sas/line-item/switch-variant/{id}", name="sas.frontend.lineItem.variant.switch", methods={"POST"}, defaults={"XmlHttpRequest": true}) - */ + #[Route(path: '/sas/line-item/switch-variant/{id}', name: 'sas.frontend.lineItem.variant.switch', defaults: ['XmlHttpRequest' => true], methods: ['POST'])] public function switchLineItemVariant(Cart $cart, string $id, Request $request, SalesChannelContext $context): Response { try { @@ -81,9 +76,14 @@ public function switchLineItemVariant(Cart $cart, string $id, Request $request, $switchedOption = $request->query->has('switched') ? (string) $request->query->get('switched') : null; try { - $redirect = $this->combinationFinder->find($productId, $switchedOption, $options, $context); - - $productId = $redirect->getVariantId(); + $redirect = $this->combinationFinder->load($productId, new Request( + [ + 'switchedGroup' => $switchedOption, + 'options' => $options, + ] + ), $context); + + $productId = $redirect->getFoundCombination()->getVariantId(); } catch (ProductNotFoundException $productNotFoundException) { //nth @@ -131,10 +131,7 @@ public function switchLineItemVariant(Cart $cart, string $id, Request $request, return $this->createActionResponse($request); } - /** - * @HttpCache - * @Route("/sas/switch-variant/{productId}", name="sas.frontend.variant.switch", methods={"GET"}, defaults={"XmlHttpRequest": true}) - */ + #[Route(path: '/sas/switch-variant/{productId}', name: 'sas.frontend.variant.switch', defaults: ['XmlHttpRequest' => true], methods: ['GET'])] public function switchVariant(string $productId, Request $request, SalesChannelContext $context): Response { $switchedOption = $request->query->has('switched') ? (string) $request->query->get('switched') : null; @@ -145,9 +142,14 @@ public function switchVariant(string $productId, Request $request, SalesChannelC $newOptions = $options !== '' ? json_decode($options, true) : []; try { - $redirect = $this->combinationFinder->find($productId, $switchedOption, $newOptions, $context); - - $productId = $redirect->getVariantId(); + $redirect = $this->combinationFinder->load($productId, new Request( + [ + 'switchedGroup' => $switchedOption, + 'options' => $newOptions, + ] + ), $context); + + $productId = $redirect->getFoundCombination()->getVariantId(); } catch (ProductNotFoundException $productNotFoundException) { //nth diff --git a/src/Storefront/Page/ProductListingConfigurationLoader.php b/src/Storefront/Page/ProductListingConfigurationLoader.php index 513c56c..af057b6 100644 --- a/src/Storefront/Page/ProductListingConfigurationLoader.php +++ b/src/Storefront/Page/ProductListingConfigurationLoader.php @@ -15,7 +15,7 @@ use Shopware\Core\Content\Property\PropertyGroupEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\Doctrine\FetchModeHelper; -use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface; +use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter; use Shopware\Core\Framework\Uuid\Uuid; @@ -23,11 +23,11 @@ class ProductListingConfigurationLoader { - private EntityRepositoryInterface $configuratorRepository; + private EntityRepository $configuratorRepository; private Connection $connection; public function __construct( - EntityRepositoryInterface $configuratorRepository, + EntityRepository $configuratorRepository, Connection $connection ) { $this->configuratorRepository = $configuratorRepository; @@ -279,12 +279,15 @@ static function (PropertyGroupOptionEntity $a, PropertyGroupOptionEntity $b) use $collection = new PropertyGroupCollection($sorted); // check if product has an individual sorting configuration for property groups - $config = $product->getConfiguratorGroupConfig(); + $config = $product->getVariantListingConfig(); + if($config) { + $config = $config->getConfiguratorGroupConfig(); + } if (!$config) { $collection->sortByPositions(); return $collection; - } else if ($product->getMainVariantId() === null) { + } elseif (($listingConfig = $product->getVariantListingConfig()) && $listingConfig->getMainVariantId() === null) { foreach ($config as $item) { if (\array_key_exists('expressionForListings', $item) && $item['expressionForListings'] && $collection->has($item['id'])) { $collection->get($item['id'])->assign([ diff --git a/src/Subscriber/CartPageLoadedSubscriber.php b/src/Subscriber/CartPageLoadedSubscriber.php index 381d66b..3c1a473 100644 --- a/src/Subscriber/CartPageLoadedSubscriber.php +++ b/src/Subscriber/CartPageLoadedSubscriber.php @@ -8,7 +8,7 @@ use Shopware\Core\Content\Product\ProductCollection; use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; -use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface; +use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Shopware\Core\System\SystemConfig\SystemConfigService; use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent; @@ -20,11 +20,11 @@ class CartPageLoadedSubscriber implements EventSubscriberInterface { private ProductListingConfigurationLoader $listingConfigurationLoader; - private SalesChannelRepositoryInterface $productRepository; + private SalesChannelRepository $productRepository; private SystemConfigService $systemConfigService; public function __construct( - SalesChannelRepositoryInterface $productRepository, + SalesChannelRepository $productRepository, ProductListingConfigurationLoader $listingConfigurationLoader, SystemConfigService $systemConfigService ) { From 1bfa413a6e4a3408f9e551920f9f9c6c6e9c88b4 Mon Sep 17 00:00:00 2001 From: Luka Andelic Date: Thu, 14 Dec 2023 09:47:58 +0100 Subject: [PATCH 2/2] Shopware Update 6.5 - Klassen entfernt --- src/Storefront/Controller/VariantSwitchController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Storefront/Controller/VariantSwitchController.php b/src/Storefront/Controller/VariantSwitchController.php index 085317e..655da85 100644 --- a/src/Storefront/Controller/VariantSwitchController.php +++ b/src/Storefront/Controller/VariantSwitchController.php @@ -12,11 +12,9 @@ use Shopware\Core\Content\Product\Exception\ProductNotFoundException; use Shopware\Core\Content\Product\SalesChannel\Sorting\ProductSortingCollection; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; -use Shopware\Core\Framework\Routing\Annotation\RouteScope; use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Shopware\Storefront\Controller\StorefrontController; -use Shopware\Storefront\Framework\Cache\Annotation\HttpCache; use Shopware\Core\Content\Product\SalesChannel\FindVariant\FindProductVariantRoute; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request;