Linking to product variants from cart

  • Posts: 11
  • Thank you received: 0
12 years 5 months ago #29679

I have created a new product, let's call it "widget". Widget has two characteristics, "blue" and "red". I have also created two related products "foo" and "bar", which are in an upublished category.

On the product page for widget, the related pruducts foo and bar are displayed.

When the widget is added to the cart, it is actually product widget:blue or widget:red that is added and when the user clicks on the product from within the cart, the variant product page is displayed - not the original product.

However, the variants are not linked to the related products so they do not appear on the product page.

Either, the link from the cart should go to the parent product instead of the variant OR the variant should also have the ability to specify related products.

What do you think?

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

  • Posts: 11
  • Thank you received: 0
12 years 5 months ago #29700

I got this to work the I want by modifying the cart view as follows:

Replace this:
<tbody>
<?php
$k = 0;
$this->cart_product_price = true;
$group = $this->config->get('group_options',0);
foreach($this->rows as $i => $row){
if(empty($row->cart_product_quantity)) continue;
if($group && $row->cart_product_option_parent_id) continue;
}
?>

With this:
<tbody>
<?php
$k = 0;
$this->cart_product_price = true;
$group = $this->config->get('group_options',0);
foreach($this->rows as $i => $row){
if(empty($row->cart_product_quantity)) continue;
if($group && $row->cart_product_option_parent_id) continue;

$prodlink_id = $row->product_id;
foreach($this->rows as $j => $r) {
if ($row->cart_product_parent_id == $r->cart_product_id) {
$prodlink_id = $r->product_id;
continue;
}
}
?>

My only worry is that this might cause performance problems if there are a large number of products - what do you think?

Last edit: 12 years 5 months ago by tjsan.

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

  • Posts: 81562
  • Thank you received: 13071
  • MODERATOR
12 years 5 months ago #29718

No problem with performances for that modification.

That indeed something we didn't think of.
The ideal solution would be to handle that case on the product page so that related products are displayed even if it's the variant id in the URL.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum