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

Private methods in Vanilo\Cart\Models\Cart #9

Closed
j-dohnalek opened this issue May 3, 2019 · 5 comments
Closed

Private methods in Vanilo\Cart\Models\Cart #9

j-dohnalek opened this issue May 3, 2019 · 5 comments
Assignees
Labels

Comments

@j-dohnalek
Copy link

Vanilo Cart 0.5.1

I have a special type of product in database for which I need to insert the product into the cart from the product.show page as new item not to update the quantity every time I insert it like it is standard for inserting the same product. Therefore, I have extended the Cart model to modify the addItem(Buyable $product, $qty = 1, $params = []). The only issue that I had implementing it that there are two methods that are private in the Vanilo\Cart\Models\Cart

getDefaultCartItemAttributes(Buyable $product, $qty)
getExtraProductMergeAttributes(Buyable $product)

I just had to copy and paste them around from the parent class. Do you have a particular reason these methods are private please? Is it possible that the methods can be protected instead? Thank you for help.

@yusufkandemir
Copy link

I don't know if I got you correct but as I understand, you have a special item that needs to have exactly 1 as quantity when it is in cart. As addItem() returns you the CartItem that has been created or modified, you can just do $item->quantity = 1; to set it's quantity as 1 after calling addItem(), and if you want to remove it you can do that by removeItem($item). If I got you wrong, please provide some code samples so we can understand better what you are trying to achieve.

@j-dohnalek
Copy link
Author

Thank you for the question. I do not know if I have explained it well. So I have a SKU in inventory. The SKU represents a item that is customisable (let say volume in this example). I do not know which volume the customer will pick. Let's say I have product SKU1 a customer comes into the shop selects he wants SKU1 with volume 1, subsequently he selected SKU1 with volume 2. The target of the logic is to add SKU1 with volume 1 to the cartItems as record 1 and add SKU1 with volume 2 as record 2. Keeping the logic of the code as it is now would add SKU1 volume 1 and SKU1 volume 2 as same record and just increment the quantity to 2 because they are the same product. I need to be able to adjust quantity of SKU1 volume 1 separately of the SKU1 volume 2 quantity in the cart. It is very strange requirement but it is what we need. Lastly, please consider also width of the volume range can be too great to just put it as a property of the item. I am open to suggestions, as I am not sure that this is the best solution, but it is the best solution I have come up with now.

@fulopattila122
Copy link
Member

I would say in general it's the best to use different product entries for different products. SKU is "Stock Keeping Unit" so in case you have different volumes of the same product use different SKUs for them. A common practice is to use SKU suffxing eg. "skuxyz-1kg" skuxyz-5kg" or something like that.

@fulopattila122
Copy link
Member

The methods are now protected on the master/1.0-dev branch. Use composer version 1.0@dev to get it. Sorry, it should've been fixed much, much faster. My bad... :(

@j-dohnalek
Copy link
Author

No worries, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants