Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shopware Update 6.5 #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -44,5 +44,10 @@
"de-DE":"https://shapeandshift.dev",
"en-GB":"https://shapeandshift.dev"
}
},
"config": {
"allow-plugins": {
"symfony/runtime": true
}
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/routes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<import resource="../../Storefront/Controller" type="annotation" />
<import resource="../../Storefront/Controller/*Controller.php" type="annotation" />
</routes>
5 changes: 4 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
</service>

<service id="SasVariantSwitch\Storefront\Controller\VariantSwitchController" public="true">
<argument type="service" id="Shopware\Storefront\Page\Product\Configurator\ProductCombinationFinder"/>
<argument type="service" id="Shopware\Core\Content\Product\SalesChannel\FindVariant\FindProductVariantRoute"/>
<argument type="service" id="sales_channel.product.repository"/>
<argument type="service" id="Shopware\Core\Checkout\Cart\SalesChannel\CartService"/>
<argument type="service" id="Shopware\Core\Checkout\Cart\LineItemFactoryRegistry"/>
<argument type="service" id="event_dispatcher"/>
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
<call method="setTwig">
<argument type="service" id="twig"/>
</call>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% endblock %}
</label>
{% block component_offcanvas_product_details_variant_switch_configurator_select %}
<select id="{{ group.id }}" name="options[{{ group.id }}]" class="custom-select js-offcanvas-cart-switch-option sas-product-configurator-select-input">
<select id="{{ group.id }}" name="options[{{ group.id }}]" class="form-select js-offcanvas-cart-switch-option sas-product-configurator-select-input">
{% for option in group.options %}

{% set selected = false %}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}

<div class="sas-product-configurator-offcanvas-wrapper" data-wrapper-id="sas-product-configurator-group-wrapper-{{ lineItem.referencedId }}" data-variant-cart-switch="true">
<form action="{{ path('sas.frontend.lineItem.variant.switch', {'id': lineItem.id}) }}" method="post">

{% block component_offcanvas_product_details_variant_switch_form_redirect %}
<input type="hidden"
name="redirectTo"
value="frontend.cart.offcanvas"/>
{% endblock %}

{% block component_offcanvas_product_details_variant_switch_parent_id %}
<input type="hidden"
name="parentId"
value="{{ parentId }}"/>
{% endblock %}

{% block component_offcanvas_product_details_variant_switch_switched %}
<input type="hidden"
class="form-switched"
name="switched"/>
{% endblock %}

{% for group in lineItem.extensions.groups %}
{% set groupIdentifier = [lineItem.referencedId, group.id]|join('-') %}

{% block component_offcanvas_product_details_variant_switch_configurator_group %}
<div class="sas-product-configurator-group">
{% sw_include '@Storefront/storefront/component/checkout/group/box-card-group-select.html.twig' %}
</div>
{% endblock %}
{% endfor %}
</form>
</div>
{% endif %}
{% endblock %}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
<div data-wrapper-id="sas-product-configurator-group-wrapper-{{ lineItem.referencedId }}" data-variant-cart-switch="true">
<form action="{{ path('sas.frontend.lineItem.variant.switch', {'id': lineItem.id}) }}" method="post" data-form-auto-submit="true">

{% block page_checkout_item_info_features_variant_switch_form_csrf %}
{{ sw_csrf('sas.frontend.lineItem.variant.switch') }}
{% endblock %}

{% block page_checkout_item_quantity_redirect %}
<input type="hidden"
name="redirectTo"
Expand Down
50 changes: 25 additions & 25 deletions src/Storefront/Controller/VariantSwitchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@
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\SalesChannelRepositoryInterface;
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\Storefront\Page\Product\Configurator\ProductCombinationFinder;
use Shopware\Core\Content\Product\SalesChannel\FindVariant\FindProductVariantRoute;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use SasVariantSwitch\Storefront\Event\ProductBoxLoadedEvent;

/**
* @RouteScope(scopes={"storefront"})
*/
#[Route(defaults: ['_routeScope' => ['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
Expand All @@ -49,10 +45,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 {
Expand Down Expand Up @@ -81,9 +74,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

Expand Down Expand Up @@ -131,10 +129,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;
Expand All @@ -145,9 +140,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

Expand Down
13 changes: 8 additions & 5 deletions src/Storefront/Page/ProductListingConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
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;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class ProductListingConfigurationLoader
{
private EntityRepositoryInterface $configuratorRepository;
private EntityRepository $configuratorRepository;
private Connection $connection;

public function __construct(
EntityRepositoryInterface $configuratorRepository,
EntityRepository $configuratorRepository,
Connection $connection
) {
$this->configuratorRepository = $configuratorRepository;
Expand Down Expand Up @@ -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([
Expand Down
6 changes: 3 additions & 3 deletions src/Subscriber/CartPageLoadedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
Expand Down