我有一个链接到其他产品 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/