Customizable Products: Pizza Store
Learn how to create your own pizza store using customizable products in Drupal Commerce. I show you how to create your own custom line item type, assign it to a Product Display, add a field to your new line item type that references a taxonomy list. Each term has it's own price and your customers get a simple check "configuration" that adds costs to the final total.
// Steps taken
1) Install Customizable Products http://drupal.org/project/commerce_custom_product
2) Add a custom line item
3) Add a custom product type
4) Create a Taxonomy, "Pizza Toppings"
5) Add price field (with currency) called "Price"
6) Add a few terms with prices
7) Add a Taxonomy term reference field "Pizza Toppings" to custom line item type
8) Configure the display of the add to cart form on the custom product type to use the custom line item type
9)Create a Pricing rule
10) Add a Entity has field condition for the line item entity to have the "Pizza Toppings"
11) Create a loop on the commerce-line-item:field-pizza-toppings
12) Add an action to the loop for the "Add an amount to the unit price" for the current-pizza-topping:field-pizza-topping-price:amount field
Comments
Cant get Amount field while adding amount to the unit price.
First of all thanks for this wonderful video. It solved 90% of my problem and I need your help for right approach of my remaining problem.
My problem is when I add 2 different Taxonomy term reference fields(for ex. 1 Pizza toppings 2. Bread type) to custom line item type, I don't get amount field in pricing rules configuration for Bread type. It works fine if I only add one pricing rule of Pizza toppings but when I add pricing rule for Bread type to reflect unit price I cant see proper amount field. In data selector it displays :-
::0:amount
::1:amount
::2:amount
::3:amount
while it should display :
::amount
like pizza topping pricing rule.
Also note that pizza toppings pricing rule affect the unit price as expected but 2nd rule of Bread type didn't work at all.
Any help will be appreciated.
Thanks!!
Deal with half and whole pizzas
Hi Josh, how can i deal with half and whole pizzas? It's possible to combine 2 products into 1 when adding to cart? is there another solution to achieve this functionality?
Thanksss!!!!
Pending Ajax update prices
Hello,
First of all thank you for this very helpful video.
For what you said at the end of the video, I use the https://drupal.org/project/auto_entitylabel and https://drupal.org/project/token modules to add (+1,50€) to my taxonomy terms so the user understands that the toppings aren't free, waiting to find a good solution to update price with ajax.
Hope this help.
Toufic.
How I edited a template file to only show certain taxonomy terms
Hi Guys, I found out a way to only show certain terms using your product node template file.
I had a client who sold photos by photo packages, e.g.
Packages:
But he takes thousands of photos for each Race/Marathon event that he attends. We use feeds to deal with such large amounts of products. Additionally, he wanted each race to include different combinations of packages, e.g. some Marathons he only wanted packages A, C, & D, others he would want D,F, & B. To solve this I created a text field called "Selected Packages" for the Product Reference Node which is letters separated by commas an example value would be "A,C,B,D,F", a field that is easily imported via feeds. Because the title for all my product packages starts with a letter e.g. "A - ", "B - ", I can then edit the template file for the Product Reference Node Type like so:
//Use php function "explode" to create an array from the values in field "Selected Packages"
$packagestoshow = explode(",", t($content['field_selected_packages'][0]['#markup']));//hide($content['field_produtcts_to_display'][0]['line_item_fields']['field_photo_packages']['und']);
//Iterate through each product package
foreach (element_children($content['field_produtcts_to_display'][0]['line_item_fields']['field_photo_packages']['und']) as $key => $value){
//Check if that particular product package is in the array we created earlier from the field "Selected Packages"
if (!in_array(t($content['field_produtcts_to_display'][0]['line_item_fields']['field_photo_packages']['und'][$value]['#title'][0]),$packagestoshow)){
//Hide the product package since it is not in the "Selected Packages" array
unset($content['field_produtcts_to_display'][0]['line_item_fields']['field_photo_packages']['und'][$value]);
}
}
//Render the content of the page
print render($content);
I'm not sure if this is best practice, but because I am relatively new to drupal this was the best I could come up with. I just put this up there in hopes that it would help someone who was in a similar situation. Feel free, anyone, to supplement this or explain a better way to do it.