Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/CartManager/AbstractCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -91,15 +91,15 @@ 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);
}

/**
* @param CheckoutableInterface&Concrete $product
* @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();
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 9 additions & 8 deletions src/CartManager/AbstractCartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
8 changes: 4 additions & 4 deletions src/CartManager/CartInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/CartManager/CartItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ public function setAddedDateTimestamp(int $time): void;
*
*/
public function getName(): string;

public function getCustomProperties(): array;

public function setCustomProperties(array $customProperties): void;
}
4 changes: 2 additions & 2 deletions src/CartManager/CartManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/CartManager/MultiCartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Loading