symfony - 如何在 Controller 中向 Shopware 6 产品添加新的交叉销售?

标签 symfony criteria shopware

我有一个链接到其他产品 ID 的产品 ID 字典。对于每个产品,我想使用上述关系中的 id 创建新的交叉销售(产品列表)。 是否可以在 Controller 中更新产品交叉销售?
应该通过更新方法还是其他方法来完成?

$this->productRepository->update([$productData], Context::createDefaultContext());

更新或更新似乎也不会对产品执行任何操作。

 $crossSellingData = [
    'id' => $crossSellingIds[0],
    'name' => 'First Cross Selling',
    'position' => 1,
    'type' => 'productList',
    'active' => true,
    'assignedProducts' => [
        [
            'productId' => "5f5365e2adb446f6958faa4257c0af6d",
            'position' => 1
        ]
    ],
];
$productRepository->upsert([['id' => $productId, 'crossSelling' => $crossSellingData]], Context::createDefaultContext());

最佳答案

您可以使用productCrossSellingRepository(表:product_cross_looking)来实现此目的。

$newCrossSelling = [
    'productId' => $mainProductId,
    'active' => true,
    'name' => 'First Cross Selling',
    'type' => 'productList',
    'position' => 1,
    'assignedProducts' => [
        [
            'productId' => $firstCrossSellingProductId,
            'position' => 1,
        ],
        [
            'productId' => $secondCrossSellingProductId,
            'position' => 2,
        ],
    ]
];

$this->productCrossSellingRepository->create([$newCrossSelling], Context::createDefaultContext());

关于symfony - 如何在 Controller 中向 Shopware 6 产品添加新的交叉销售?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66407439/

相关文章:

php - symfony2 payum paypal express 简单结账

php - 类型为 SINGLE_COLLECTION 架构的 ODM 继承文档创建错误

php - Symfony2,登录表单 - CSRF 保护

grails - Grails-条件查询中的 'in'节点-groovy.lang.IntRange无法转换为java.lang.Integer

java - 如何使用条件生成器使用多个过滤器进行搜索

shopware - 在 Shopware 产品列表页面上显示评论数

php - 无法覆盖 Symfony ConstraintViolationList 的 JMS 序列化程序的默认处理程序

java - Hibernate sql 查询条件

商店软件 6 : how to route shopware unit test output from fixture to original folder?

symfony - Shopware 6 授权客户