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 possibility to set custom properties to cart item #143

Merged
merged 11 commits into from
Feb 5, 2024

Conversation

dblaichinger
Copy link
Contributor

@dblaichinger dblaichinger commented Dec 14, 2023

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:

Copy link

github-actions bot commented Dec 15, 2023

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

@bluvulture
Copy link
Contributor

Hey @dblaichinger

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

Tnx

Co-authored-by: Sebastian Blank <sebastian.bl@gmx.de>
@dblaichinger
Copy link
Contributor Author

recheck

…chinger/ecommerce-framework-bundle into add-custom-properties-to-cart-item
…chinger/ecommerce-framework-bundle into add-custom-properties-to-cart-item
@dblaichinger
Copy link
Contributor Author

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

…chinger/ecommerce-framework-bundle into add-custom-properties-to-cart-item
…chinger/ecommerce-framework-bundle into add-custom-properties-to-cart-item
@fashxp
Copy link
Member

fashxp commented Dec 15, 2023

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

@dblaichinger
Copy link
Contributor Author

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 #146. Can you please add the BC-BREAK label there and remove it from this one?

Thank you!

@fashxp
Copy link
Member

fashxp commented Jan 29, 2024

@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
Copy link
Contributor Author

Hi @fashxp

added some docs, can you please double check?

I've added some details, please check b43fa91

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
Copy link
Member

fashxp commented Feb 5, 2024

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!!

@fashxp fashxp added this to the 1.1.0 milestone Feb 5, 2024
@fashxp fashxp merged commit 7fd7dfc into pimcore:1.x Feb 5, 2024
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 2024
@dblaichinger dblaichinger deleted the add-custom-properties-to-cart-item branch February 5, 2024 10:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants