Extra required product when selecting an item

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13274

Hey Nicolas,

first of all; the great compliments of building such a great shopping cart! It is really well thought. Keep going on :)

now my question; I am building a webshop for a mudflap company where they can sell mudflaps (see www.beuze.com/_A/spatlappen )
Now here is the thing: When someone orders one or more mudflaps a 115euro a piece, there have to be set up costs to design the mudflaps: This is a standard amount of 30 euro per design (no matter whether they order 1, 10 or 1000 mudflaps). Is there an option that there will automatically be an item 'graphic design mudflap' of 30 euro's put in the shopping cart per order of mudflaps?

I could not find the option in the documentation..

hope to hear from you,

kind regards,
Han

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13305

Hi,

Maybe you could use a shipping method as graphic design mudflap ?
The shipping method would be added to the order automatically with a 30euros price tag. Now, if you also need to handle shipping, that method won't be possible.

In that case, you would have to automatically add a product to the cart using some custom code in the file cart of the view checkout.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13320

hey Nicolas,

thanks for your reply. I guess we also handle the shipping, so it will be the last option. Can you tell me exactly how to put a extra product at the checkout like you said?

regards!

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13330

Suppose that your extra product has the code "extra_product" and the id XX, you would add something like this in the file cart of the view checkout via the menu Display->Views :

$already = false;
foreach($this->rows as $i => $row){
 if($row->product_code =='extra_product') $already = true;
}
if(!$already){
 $app =& JFactory::getApplication();
 $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=XX&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13349

ok, and what is the string then for 'the mudflap product'?

for example: the product 'graphical_setup' will only be adjusted only when someone orders a product from the mudflap category.

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13355

That was not in your previous messages. If you want to add the extra product only if there is a product of a special category, that will complicate a bit the code. You need first to load the categories of all the products in the cart. Suppose that YY is the id of the category mudflap:

$already = false;
$ids = array();
foreach($this->rows as $i => $row){
 if($row->product_code =='extra_product') $already = true;
 $ids[]=$row->product_id;
}
$db=&JFactory::getDBO();
$db->setQuery('SELECT * FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).') AND category_id=YY');
$entry = $db->loadResult();
if(!$already && !empty($entry)){
 $app =& JFactory::getApplication();
 $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=XX&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}

Last edit: 13 years 7 months ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13400

ok, that makes sense. Where do I have to put the code exactly in de file 'cart' of the checkout view? And do I have to add any more PHP code before or after the code you placed here above?

thanks for you reply!

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13460

That code should be enough. You need to put it after the first <?php tag of the file.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13517

I can get it work with the first code you gave, but not with the second code; it does not load the product 'setup' when I order a product from the category mudflap. And it messes up my template after adjusting the code..

This is what I added after the first <?php

$already = false; 
$ids = array(); 
foreach($this->rows as $i => $row){ 
 if($row->product_code =='setup') $already = true; 
 $ids[]=$row->product_id; 
} 
$db=&JFactory::getDBO(); 
$db->setQuery('SELECT * FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).') AND category_id=12'); 
$entry = $db->loadResult(); 
if(!$already && !empty($result)){ 
 $app =& JFactory::getApplication(); 
 $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=106&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())))); 
}

with replacing
one time: 'extra_product' with the code 'setup' of the extra product
one time: 'YY' with '12' as the category ID of the mudflap category
one time: 'XX' with '106' as the product id of the extra product 'setup'.

what do i miss?

thanks for your reply.

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13547

It should be:
if(!$already && !empty($entry)){
and not:
if(!$already && !empty($result)){

I've fixed it in the code of my message.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13577

Now it is working; but only when I put a lower level product category..How can I add another (top)product category with subcategories with products in it?

for example:
One top-category mudflaps = 12

2 lower level categories under top-category mudflaps (12):
mudflaps for trucks = 13
mudflaps for trailers = 14

I want the extra product shown for products both in categories 13 en 14 for example.

Last edit: 13 years 7 months ago by hanterkeurs. Reason: updated troubleshooting

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13599

That code does not handle undirect sub categories. That's why it doesn't work like you want...
In that case you need to change:
category_id=12
to:
category_id IN (13,14)

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13612

It works perfectly!

ok, latest question :) what if for every item they put on the cart (no matter the amount), an extra amount of the setup product will be adjusted?

so 1 piece of a mudflap for a trailer (= 1 setup product)
and 1 (or 2 or 3) pieces of a mudflap for a car (= so that will make 2 setup products; one for every item on the cart).

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13637

Like this:

$already = false; 
$ids = array(); 
$qty = 0;
foreach($this->rows as $i => $row){ 
 if($row->product_code =='setup') $already = true; 
 else $qty+=$row->cart_product_quantity;
 $ids[]=$row->product_id; 
} 
$db=&JFactory::getDBO(); 
$db->setQuery('SELECT * FROM '.hikashop::table('product_category').' WHERE product_id IN ('.implode(',',$ids).') AND category_id IN (13,14)'); 
$entry = $db->loadResult(); 
if(!$already && !empty($entry)){ 
 $app =& JFactory::getApplication(); 
 $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=106&quantity='.$qty.'&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())))); 
}

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13926

thanks, but unfortunately it's not working; it messes up the template again & it does not add any extra product from the loaded categories. Something wrong with the quantity string?

regards!

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13934

Mmm. The code seems fine to me. Could you give the URL of your website so that we can see the problem ?

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #13936

Please Log in or Create an account to join the conversation.

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
13 years 7 months ago #13942

That happens because of a fatal error in the code. Could you activate the display of errors in your php.ini so that we can see the error message ?
You can edit your php.ini file and search for the string parameter display_errors.
This parameter should be turned On : display_errors = On.
If it's not the case, please edit your php.ini file, modify this line, save your file and try again.
If you don't know where your php.ini is, you should ask your hosting company.

Most of the time, they allow you to have your own php.ini at the root of your website.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
13 years 7 months ago #14308

Hey Nicolas,

ok, I don't know how to do that with the php.ini, so i decide that I'll try it with the latest working solution. When this is not suffient anymore, I'll come back on this topic.
thanks for all the help!

regards,
Han

Please Log in or Create an account to join the conversation.

Time to create page: 0.089 seconds
Powered by Kunena Forum