Skip to content

Commit a668fec

Browse files
Merge pull request #2380 from dpfaffenbauer/issue/2375
[Core] re-add mainObjectId and objectId
2 parents 792e317 + 039693e commit a668fec

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
"vimeo/psalm": "^4.10"
131131
},
132132
"conflict": {
133-
"jms/serializer-bundle": "4.1.0"
133+
"jms/serializer-bundle": "4.1.0",
134+
"league/csv": ">= 9.11"
134135
},
135136
"suggest": {
136137
"dpfaffenbauer/process-manager": "Allows to start Processes from within Pimcore UI and also tracks the status."

src/CoreShop/Component/Core/Model/OrderItemInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ public function setItemWeight(?float $itemWeight);
4949
public function getTotalWeight(): ?float;
5050

5151
public function setTotalWeight(?float $totalWeight);
52+
53+
public function getObjectId(): ?float;
54+
55+
public function setObjectId(?float $objectId);
56+
57+
public function getMainObjectId(): ?float;
58+
59+
public function setMainObjectId(?float $objectId);
5260
}

src/CoreShop/Component/Core/Order/Processor/CartTextProcessor.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
namespace CoreShop\Component\Core\Order\Processor;
2020

21+
use CoreShop\Component\Core\Model\OrderItemInterface;
2122
use CoreShop\Component\Order\Model\OrderInterface;
2223
use CoreShop\Component\Order\Model\PurchasableInterface;
2324
use CoreShop\Component\Order\Processor\CartProcessorInterface;
2425
use CoreShop\Component\Resource\Translation\Provider\TranslationLocaleProviderInterface;
26+
use Pimcore\Model\DataObject\AbstractObject;
2527

2628
final class CartTextProcessor implements CartProcessorInterface
2729
{
@@ -32,12 +34,38 @@ public function __construct(
3234

3335
public function process(OrderInterface $cart): void
3436
{
37+
/**
38+
* @var OrderItemInterface $item
39+
*/
3540
foreach ($cart->getItems() as $item) {
41+
$product = $item->getProduct();
42+
43+
if (!$product instanceof PurchasableInterface) {
44+
continue;
45+
}
46+
3647
foreach ($this->localeProvider->getDefinedLocalesCodes() as $locale) {
37-
if ($item->getProduct() instanceof PurchasableInterface) {
38-
$item->setName($item->getProduct()->getName($locale), $locale);
39-
}
48+
$item->setName($product->getName($locale), $locale);
49+
}
50+
51+
$item->setObjectId((float)$product->getId());
52+
53+
if (($product instanceof AbstractObject) && $product->getType() === AbstractObject::OBJECT_TYPE_VARIANT) {
54+
$mainProduct = $this->findVariantMain($product);
55+
$item->setMainObjectId((float)$mainProduct->getId());
4056
}
4157
}
4258
}
59+
60+
private function findVariantMain(AbstractObject $object): AbstractObject
61+
{
62+
$master = $object;
63+
while ($master->getType() === AbstractObject::OBJECT_TYPE_VARIANT) {
64+
if ($master->getParent() instanceof $master) {
65+
$master = $master->getParent();
66+
}
67+
}
68+
69+
return $master;
70+
}
4371
}

0 commit comments

Comments
 (0)