diff --git a/src/CartManager/AbstractCart.php b/src/CartManager/AbstractCart.php index 4eb7213a..87bd9cf0 100644 --- a/src/CartManager/AbstractCart.php +++ b/src/CartManager/AbstractCart.php @@ -84,13 +84,13 @@ abstract protected function getCartCheckoutDataClassName(): string; * @param int $count * @param string|null $itemKey * @param bool $replace - * @param array $params + * @param array $customProperties * @param AbstractSetProductEntry[] $subProducts * @param string|null $comment * * @return string */ - 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(); @@ -100,7 +100,7 @@ public function addItem(CheckoutableInterface $product, int $count, string $item } } - return $this->updateItem($itemKey, $product, $count, $replace, $params, $subProducts, $comment); + return $this->updateItem($itemKey, $product, $count, $replace, $customProperties, $subProducts, $comment); } /** @@ -108,13 +108,13 @@ public function addItem(CheckoutableInterface $product, int $count, string $item * @param CheckoutableInterface&Concrete $product * @param int $count * @param bool $replace - * @param array $params + * @param array $customProperties * @param AbstractSetProductEntry[] $subProducts * @param string|null $comment * * @return string */ - 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(); @@ -158,6 +158,8 @@ public function updateItem(string $itemKey, CheckoutableInterface $product, int $item->setSubItems($subItems); } + $item->setCustomProperties($customProperties); + $this->items[$itemKey] = $item; // trigger cart has been modified diff --git a/src/CartManager/AbstractCartItem.php b/src/CartManager/AbstractCartItem.php index 883e72fa..d0d7f2c1 100644 --- a/src/CartManager/AbstractCartItem.php +++ b/src/CartManager/AbstractCartItem.php @@ -57,6 +57,8 @@ abstract class AbstractCartItem extends \Pimcore\Model\AbstractModel implements */ protected ?int $addedDateTimestamp = null; + protected array $customProperties = []; + public function __construct() { $this->setAddedDate(new \DateTime()); @@ -298,4 +300,23 @@ public function setIsLoading(bool $isLoading): void { $this->isLoading = $isLoading; } + + /** + * Sets custom properties to CartItem when provided in AbstractCart::addItem + * + * @param array $customProperties + * @return void + */ + public function setCustomProperties(array $customProperties): void + { + $this->customProperties = $customProperties; + } + + /** + * @return array + */ + public function getCustomProperties(): array + { + return $this->customProperties; + } } diff --git a/src/CartManager/CartInterface.php b/src/CartManager/CartInterface.php index 9bb17f1b..5c502797 100644 --- a/src/CartManager/CartInterface.php +++ b/src/CartManager/CartInterface.php @@ -70,26 +70,26 @@ public function getGiftItem(string $itemKey): ?CartItemInterface; * @param int $count * @param string|null $itemKey * @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 * @param string|null $comment * * @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 string $itemKey * @param CheckoutableInterface $product * @param int $count * @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 array $subProducts * @param string|null $comment * * @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 2c1c8a62..8232a07c 100644 --- a/src/CartManager/CartItemInterface.php +++ b/src/CartManager/CartItemInterface.php @@ -112,4 +112,11 @@ public function setAddedDateTimestamp(int $time): void; * @return string */ public function getName(): string; + + /** + * @return array + */ + public function getCustomProperties(): array; + + public function setCustomProperties(array $customProperties): void; } diff --git a/src/CartManager/CartManagerInterface.php b/src/CartManager/CartManagerInterface.php index 97bf4dad..cb984c40 100644 --- a/src/CartManager/CartManagerInterface.php +++ b/src/CartManager/CartManagerInterface.php @@ -40,7 +40,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 * @param string|null $comment * @@ -52,7 +52,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 bab0c63e..f426da11 100644 --- a/src/CartManager/MultiCartManager.php +++ b/src/CartManager/MultiCartManager.php @@ -116,7 +116,7 @@ protected function getAllCartsForCurrentUser(): ?array * @param string|null $key * @param string|null $itemKey * @param bool $replace - * @param array $params + * @param array $customProperties * @param array $subProducts * @param string|null $comment * @@ -130,7 +130,7 @@ public function addToCart( string $key = null, string $itemKey = null, bool $replace = false, - array $params = [], + array $customProperties = [], array $subProducts = [], string $comment = null ): string { @@ -142,7 +142,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;