Comments (7)
I’m sorry, we won’t add something like extras
to our Cart class in the near future.
I would suggest the following workaround:
Ice cream toppings should be own products. When you put your ice cream (with topping) into the cart you should – at the same time – put the topping product into the cart. When you add the topping product you can add a for
key to match the topping with the ice cream.
$cart = cart();
$cart->add([
'id' => 'vanilla-ice-cream',
]);
$cart->add([
'id' => 'chocolate-sprinkles',
'for' => 'vanilla-ice-cream',
]);
from merx.
I confirm my approach works for my case.
'Frame' is created as a separate product, and so it is included in merx calculations.
When adding a frame to the cart, the print this frame belongs to, receives a +1 on a 'frame' attribute, so we can keep track of how many frames are associated to each print among the total ammount of frames in the cart.
Finally it is often needed to filter 'frame' as a product, because we don't really want the customer to buy it separately,
from merx.
Thank you for the workaround.
Take care.
from merx.
@tobiasfabian I've just noticed a possible problem with this workaround.
- I add
vanilla-ice-cream
to the cart - I add
chocolate-sprinkes
to the cart with afor
keyvanilla-ice-cream
- I add
stracciatella-ice-cream
to the cart - I add
chocolate-sprinkes
to the cart with afor
keystracciatella-ice-cream
Since chocolate sprinkles is a product, adding it twice should just incremenet the quantity right?
I can't have two different instances of a product with two different for
keys, or can I ?
Danke
from merx.
Oops, I think you are right, this won’t work out.
The for
key could be an array. But this would be a quite shaky solution.
Maybe every product variant has to be its own product (I think this is the default behavior of shop systems, at least Magento works like this)
You can have a master product e.g. Vanilla Ice Cream. And each master product could have variants/children (e.g. Chocolate Sprinkles).
So you don’t have to create variants for each Ice Cream you could use Virtual Pages.
Untested Example
/site/models/product.php
<?php
class ProductPage extends Kirby\Cms\Page
{
public function children()
{
$variants = [];
foreach ($this->site()->variants()->toStructure() as $variant) {
$variants[] = [
'slug' => $variant->slug(),
'num' => 0,
'template' => 'product-variant',
'model' => 'product-variant',
'content' => [
'title' => $variant->title(),
'price' => $this->price()->toFloat() + $variant->additionalPrice()->toFloat(),
]
];
}
return Pages::factory($variants, $this);
}
}
If the customer wants Vanilla Ice Cream with Chocolate Sprinkles the code would look like this
$cart->add('vanilla-ice-cream/chocolate-sprinkles');
from merx.
So you are overriding the children() method of the page class for the product page, and you use ::factory method to return variants as virtual pages. That's very clever, I wouldn't have thought about it
It does not fit my use-case tho, which was not really about ice-cream ( It seemed to me that was a clearer example) but I thought about a way that does fit. This is my cart page
My only 'extra' or 'variant' is adding a frame to the print, so I could:
- Add 'Frame' as its own product
- Include 'frames' as key when adding a product to cart, or as a cart.field of the product page.
then
- When user clicks (+) on the frame section of the Cart Page
- I add +1 Frame product to the cart
- I add +1 to the 'frames' key of the associated product (Double Cherry, in the image)
As frames are products, their price is included in cart()'s calculations.
And with the 'Frames' key I can track how many frames for each product, which should make it relatively easy to associate frames and their price, and echo the data in the page, such as adding frames to the product total (they are already added to cart's total)
Any comments appreciated.
I'll come back when I test it.
Thank you
from merx.
this issue should be linked in the cookbook
from merx.
Related Issues (20)
- Syntax error with Starter Kit HOT 1
- No such payment_intent HOT 1
- Order validation on multi-language sites breaks on Kirby 3.6.4+ HOT 6
- Compatibility issue with Kirby 3.7.1 HOT 4
- Is it possible to disable online payments? HOT 1
- Upgrade to Paypal API v2 HOT 5
- Wagnerwagner\Merx\ProductList::__set(): Return type must be void when declared HOT 2
- Discount per product? HOT 1
- How do you add different types of sizes for a product? HOT 2
- Deprecated Stripe API
- Save orders in a specific language HOT 1
- Order pages with identical page num created HOT 3
- Declaration of Wagnerwagner\Merx\ProductList::__set(string $key, $value) must be compatible with Kirby HOT 1
- Cart and Checkout problem HOT 1
- Cart()->remove() not removing product - Issue with UUID's HOT 2
- Dynamic shipping prices (request) HOT 1
- Allow donation or 'pay what you want' HOT 11
- Success page language HOT 2
- Will this plugin be updated for kirby 4? HOT 1
- Merx and Kirby4 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from merx.