diff --git a/src/CartManager/AbstractCart.php b/src/CartManager/AbstractCart.php index 92144864..a159bf82 100644 --- a/src/CartManager/AbstractCart.php +++ b/src/CartManager/AbstractCart.php @@ -81,7 +81,7 @@ abstract protected function getCartCheckoutDataClassName(): string; * @param AbstractSetProductEntry[] $subProducts * */ - public function addItem(CheckoutableInterface $product, int $count, ?string $itemKey = null, bool $replace = false, array $params = [], array $subProducts = [], ?string $comment = null): string + public function addItem(CheckoutableInterface $product, int $count, ?string $itemKey = null, bool $replace = false, array $customProperties = [], array $subProducts = [], ?string $comment = null): string { if (empty($itemKey)) { $itemKey = (string) $product->getId(); @@ -91,7 +91,7 @@ public function addItem(CheckoutableInterface $product, int $count, ?string $ite } } - return $this->updateItem($itemKey, $product, $count, $replace, $params, $subProducts, $comment); + return $this->updateItem($itemKey, $product, $count, $replace, $customProperties, $subProducts, $comment); } /** @@ -99,7 +99,7 @@ public function addItem(CheckoutableInterface $product, int $count, ?string $ite * @param AbstractSetProductEntry[] $subProducts * */ - public function updateItem(string $itemKey, CheckoutableInterface $product, int $count, bool $replace = false, array $params = [], array $subProducts = [], ?string $comment = null): string + public function updateItem(string $itemKey, CheckoutableInterface $product, int $count, bool $replace = false, array $customProperties = [], array $subProducts = [], ?string $comment = null): string { //load items first in order to lazyload items (if they are lazy loaded) $this->getItems(); @@ -143,9 +143,7 @@ public function updateItem(string $itemKey, CheckoutableInterface $product, int $item->setSubItems($subItems); } - if (method_exists($item, 'setCustomProperties')) { - $item->setCustomProperties($params); - } + $item->setCustomProperties($customProperties); $this->items[$itemKey] = $item; diff --git a/src/CartManager/AbstractCartItem.php b/src/CartManager/AbstractCartItem.php index 11b5f220..6a24b0f0 100644 --- a/src/CartManager/AbstractCartItem.php +++ b/src/CartManager/AbstractCartItem.php @@ -53,6 +53,8 @@ abstract class AbstractCartItem extends \Pimcore\Model\AbstractModel implements */ protected ?int $addedDateTimestamp = null; + protected array $customProperties = []; + public function __construct() { $this->setAddedDate(new \DateTime()); @@ -292,15 +294,14 @@ public function setIsLoading(bool $isLoading): void /** * Sets custom properties to CartItem when provided in AbstractCart::addItem * - * */ - public function setCustomProperties(array $params): void + public function setCustomProperties(array $customProperties): void { - foreach ($params as $key => $value) { - $method = 'set' . ucfirst($key); - if (method_exists($this, $method)) { - $this->{$method}($value); - } - } + $this->customProperties = $customProperties; + } + + public function getCustomProperties(): array + { + return $this->customProperties; } } diff --git a/src/CartManager/CartInterface.php b/src/CartManager/CartInterface.php index ed07eedf..88063c9d 100644 --- a/src/CartManager/CartInterface.php +++ b/src/CartManager/CartInterface.php @@ -64,20 +64,20 @@ public function getGiftItem(string $itemKey): ?CartItemInterface; /** * @param bool $replace replace if item with same key exists - * @param array $params optional additional item information + * @param array $customProperties optional additional item information * @param AbstractSetProductEntry[] $subProducts * * @return string $itemKey */ - public function addItem(CheckoutableInterface $product, int $count, ?string $itemKey = null, bool $replace = false, array $params = [], array $subProducts = [], ?string $comment = null): string; + public function addItem(CheckoutableInterface $product, int $count, ?string $itemKey = null, bool $replace = false, array $customProperties = [], array $subProducts = [], ?string $comment = null): string; /** * @param bool $replace replace if item with same key exists - * @param array $params optional additional item information + * @param array $customProperties optional additional item information * * @return string $itemKey */ - public function updateItem(string $itemKey, CheckoutableInterface $product, int $count, bool $replace = false, array $params = [], array $subProducts = [], ?string $comment = null): string; + public function updateItem(string $itemKey, CheckoutableInterface $product, int $count, bool $replace = false, array $customProperties = [], array $subProducts = [], ?string $comment = null): string; /** * updates count of specific cart item diff --git a/src/CartManager/CartItemInterface.php b/src/CartManager/CartItemInterface.php index 42fe324d..eb5d4cee 100644 --- a/src/CartManager/CartItemInterface.php +++ b/src/CartManager/CartItemInterface.php @@ -97,4 +97,8 @@ public function setAddedDateTimestamp(int $time): void; * */ public function getName(): string; + + public function getCustomProperties(): array; + + public function setCustomProperties(array $customProperties): void; } diff --git a/src/CartManager/CartManagerInterface.php b/src/CartManager/CartManagerInterface.php index 8e017d5d..76569881 100644 --- a/src/CartManager/CartManagerInterface.php +++ b/src/CartManager/CartManagerInterface.php @@ -35,7 +35,7 @@ public function getCartClassName(): string; * @param string|null $key - optional key of cart where the item should be added to * @param string|null $itemKey - optional item key * @param bool $replace - replace item if same key already exists - * @param array $params - optional addtional item information + * @param array $customProperties - optional additional item information * @param AbstractSetProductEntry[] $subProducts * * @return string - item key @@ -46,7 +46,7 @@ public function addToCart( ?string $key = null, ?string $itemKey = null, bool $replace = false, - array $params = [], + array $customProperties = [], array $subProducts = [], ?string $comment = null ): string; diff --git a/src/CartManager/MultiCartManager.php b/src/CartManager/MultiCartManager.php index a94d5910..1a830f84 100644 --- a/src/CartManager/MultiCartManager.php +++ b/src/CartManager/MultiCartManager.php @@ -118,7 +118,7 @@ public function addToCart( ?string $key = null, ?string $itemKey = null, bool $replace = false, - array $params = [], + array $customProperties = [], array $subProducts = [], ?string $comment = null ): string { @@ -130,7 +130,7 @@ public function addToCart( $cart = $this->carts[$key]; - $itemKey = $cart->addItem($product, $count, $itemKey, $replace, $params, $subProducts, $comment); + $itemKey = $cart->addItem($product, $count, $itemKey, $replace, $customProperties, $subProducts, $comment); $this->save(); return $itemKey;