pimcore / ecommerce-framework-bundle

Ecommerce Framework community bundle provides e-commerce functionality such as product listing and filtering, pricing, carts and checkouts for Pimcore.
https://pimcore.com/docs/platform/Ecommerce_Framework/
Other
8 stars 28 forks source link

Add possibility to set custom properties to cart item #143

Closed dblaichinger closed 5 months ago

dblaichinger commented 7 months ago

Overview

The suggested change would make it easier to extend CartItem class and provide the property in Cart::addItem() as $params afterwards.

Extend CartItem

The $params parameter in AbstractCart::addItem is currently unused in this method, but the doc-block suggests that it's possible to add additional data.

In src/CartManager/CartInterface.php:

/**

  • @param CheckoutableInterface $product
  • @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 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;

Also see:

github-actions[bot] commented 7 months ago

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

bluvulture commented 7 months ago

Hey @dblaichinger

Could you plase sign cla and then re-trigger the check?

Tnx

dblaichinger commented 7 months ago

recheck

dblaichinger commented 7 months ago

I have read the CLA Document and I hereby sign the CLA

fashxp commented 7 months ago

Can we do that without changing an interface? As it is now it would be a bc break

dblaichinger commented 7 months ago

Hi @fashxp,

I've removed the interface change in this PR and added a method_exists check instead. However, I still think it's cleaner to extend the interface, so I've added a new https://github.com/pimcore/ecommerce-framework-bundle/pull/146. Can you please add the BC-BREAK label there and remove it from this one?

Thank you!

fashxp commented 5 months ago

@dblaichinger thx very much. added some docs, can you please double check? also thought that it might be really cool, if the custom properties would be stored automatically and extending Cart/CartItem isn't even necessary. But that might require a bit more refactoring.

dblaichinger commented 5 months ago

Hi @fashxp

added some docs, can you please double check?

I've added some details, please check https://github.com/pimcore/ecommerce-framework-bundle/pull/143/commits/b43fa91b230f4891bfa1d4d388705e76a899caa4

also thought that it might be really cool, if the custom properties would be stored automatically and extending Cart/CartItem isn't even necessary.

Can this be achieved without changing CartItemInterface and breaking compatibility?

I've added $customProperties to AbstractCartItem in the BC-BREAK tagged PR: https://github.com/pimcore/ecommerce-framework-bundle/pull/146/files. Maybe that's a better approach when already breaking compatibility.

Thanks!

fashxp commented 5 months ago

I've added $customProperties to AbstractCartItem in the BC-BREAK tagged PR: https://github.com/pimcore/ecommerce-framework-bundle/pull/146/files. Maybe that's a better approach when already breaking compatibility.

not sure if we really need to add an additional parameter, of if we just add a generic functionality to the existing cart implementations, which persists the data passed via $params parameter to their storage. Let's continue the discussion over there in the other PR.

This one looks good now. Thx very much!!