Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setCustomProperties method to CartItemInterface #146

Open
wants to merge 11 commits into
base: 1.x
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions src/CartManager/AbstractCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -100,21 +100,21 @@ 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);
}

/**
* @param string $itemKey
* @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();
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/CartManager/AbstractCartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
8 changes: 4 additions & 4 deletions src/CartManager/CartInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/CartManager/CartItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/CartManager/CartManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/CartManager/MultiCartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
Loading