SalesChannelContextFactory创建上下文而没有规则

发布于 2025-02-13 05:24:19 字数 431 浏览 0 评论 0原文

我有一些通过CLI命令执行的代码,并创建订单并发送确认邮件。因此,需要考虑订单约束销售渠道规则ID。因此,我正在使用Shopware和Shopware使用的SalesChannelContextFactory创建SalesChannelContext。

$ saleschannelcontext = $ this-> saleschannelcontextfactory-> create( '',, $ salesChannElentity-> getId(), [salesChannelContextService :: Lagans_id => $ salesChannElentity-> getLanguageId()] );

但是,这创建了saleschannelcontext不包含任何配置的规则。我是否需要手动加载它们,还是有某种方法告诉工厂该创建的上下文应包含规则?

I have some code which is executed via cli command and creates orders and sends confirmation mail. Therefor the order bound sales channel rule ids need to be considered. So I'm creating a Saleschannelcontext with the SalesChannelContextFactory given and used by Shopware.

$salesChannelContext = $this->salesChannelContextFactory->create(
'',
$salesChannelEntity->getId(),
[SalesChannelContextService::LANGUAGE_ID => $salesChannelEntity->getLanguageId()]
);

But this created salesChannelContext doesn't contain any configured ruleIds. Do I need to load these manually or is there some way to tell the factory that this created context should contain rules?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2025-02-20 05:24:19

您需要注入Shopware \ Core \ Checkout \ CART \ CARTRULELOLODADER并调用loadbyToken。这将保湿规则ID的数组。如果要考虑评估购物车内容的规则,您也可以调用loadBycart

$options = [
    SalesChannelContextService::LANGUAGE_ID => $languageId,
    SalesChannelContextService::CUSTOMER_ID => $customerId,
    SalesChannelContextService::CUSTOMER_GROUP_ID => $groupId,
];

$token = Uuid::randomHex();
$salesChannelContext = $this->factory->create(
    $token,
    $salesChannelId,
    $options
);

$this->cartRuleLoader->loadByToken($salesChannelContext, $token);

如果您的起点是现有订单,则可以更实用地注入shopware \ core \ system \ saptleChannel \ salestchannel \ context \ saleschannelcontextrestorer并使用该服务来还原并返回salesChannelContext由现有订单构建。此实例还将包括规则ID:

$salesChannelContext = $this->salesChannelContextRestorer->restoreByOrder($orderId, $context);

You need to inject Shopware\Core\Checkout\Cart\CartRuleLoader and call loadByToken. This will hydrate the array of rule IDs. You may also call loadByCart if you want to consider rules evaluating a cart's content.

$options = [
    SalesChannelContextService::LANGUAGE_ID => $languageId,
    SalesChannelContextService::CUSTOMER_ID => $customerId,
    SalesChannelContextService::CUSTOMER_GROUP_ID => $groupId,
];

$token = Uuid::randomHex();
$salesChannelContext = $this->factory->create(
    $token,
    $salesChannelId,
    $options
);

$this->cartRuleLoader->loadByToken($salesChannelContext, $token);

If your starting point is an existing order it might also be more practical to inject Shopware\Core\System\SalesChannel\Context\SalesChannelContextRestorer and use that service to restore and return a SalesChannelContext built from an existing order. This instance will also include the rule IDs:

$salesChannelContext = $this->salesChannelContextRestorer->restoreByOrder($orderId, $context);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文