我正在尝试在 shopware 6 中构建此页面:
但由于在 shopware 中 6 种具有变异的产品是分开的(下图),我无法做到这一点。
我需要将具有变体的产品分组到父产品下。 有人有想法吗?
我现在正在处理的订阅者:
use Shopware\Core\Checkout\Cart\Event\BeforeLineItemAddedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddDataToPage implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [BeforeLineItemAddedEvent::class => 'onLineItemAdded'];
}
/**
* @param onLineItemAdded $event
* @throws \Shopware\Core\Checkout\Cart\Exception\InvalidPayloadException
*/
public function onLineItemAdded(BeforeLineItemAddedEvent $event)
{
$lineitems = $event->getLineItem();
// I need a [IF] here: if product has a variation and parent product id is the same add the code below
$lineitems->setPayloadValue("myVar", "test2");
}
最佳答案
我建议采取以下步骤:
- 装饰AbstractCartItemAddRoute
- 获取将要添加的产品的父产品,并为其添加广告
- 将实际变体添加为子变体
- 添加一个 CartProcessor 或修饰 ProductProcessor 以使用父产品计算第一级项目的价格。这应该是所有变体位置的总和
当然,您应该在第 2 步中检查父项或变体子项是否存在并更新它。
关于symfony - 商店用品 6 : How to add Products with variation as childrens to Parent Products in LineItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68127239/