Display 2 products on same page (with tabs)

  • Posts: 73
  • Thank you received: 1
11 years 8 months ago #90324

I am working on a customization of a webshop where I want the following.

There is a page which contains 2 products. They are separated by tabs. So we have product 1 and product 2 on a single page and both can be costumized (color etc) on that same page but they are in different tabs. To make it a bit more clear. They are ankle braces and one is for the left foot and the other is for the right foot. Each has a variaty of customizations such as color, padding etc etc. In hikashop they are 2 different products but I want to put them on a single page and have the user switch through them with tabs

[Product 1 | Product 2]

Any ideas how I should go about doing this? I understand that it involves PHP but i'm wondering if I need to modify any controllers for this.

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

  • Posts: 73
  • Thank you received: 1
11 years 8 months ago #90429

bump please

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

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #90588

Hi,

I think that the easiest way is to create a custom field in the product table, in this custom field set the id of the corresponding item. (itemA custom field value = id of itemB, itemB custom field value = id of itemA).
You will certainly have to edit the file "components/com_hikashop/views/product/view.html.php" to add a request, if there is a value in the custom field, so get the other product.
Then edit the view "product / show", if there is two items, add the tabber tags and call each view of products in each tabber.

Hope this will help you.

The following user(s) said Thank You: Ortix

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

  • Posts: 73
  • Thank you received: 1
11 years 8 months ago #90737

that's absolutely genius! Thanks!

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

  • Posts: 73
  • Thank you received: 1
11 years 8 months ago #90751

Just another question.

To make the second request, what would you recommend? Should I copy the contents of the show() function and use the content of the custom field as the $product_ID?

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

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #90861

Yes you can copy it, and remove all the parts not needed. In the show() function, if the field is not empty, call the showBis() function and do it to make it return the product object.
And with an Assignref ... submit the object to the show view.

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

  • Posts: 73
  • Thank you received: 1
11 years 8 months ago #91465

I got this semi-working. I'm able to get the entire product object to the show.php file, however the loadTemplate method renders the primary product again and not the fetched product.

$this->setLayout($this->brace_productlayout);
echo $this->loadTemplate();

I appended every refferenced variable with brace_ and in the object everything appears correctly (when i use print_r()) however it's not rendered correctly.

Is it because the layout is still set as the original one and that brace_productlayout does not exist?

Last edit: 11 years 8 months ago by Ortix.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #91641

To use your custom view, in the "product / show" view you have to call it when you have 2 products, to call it you can use:

        $this->productLayout = 'show_custom';

	$this->setLayout($this->productlayout);
	echo $this->loadTemplate();
In this case the custom view is 'show_custom'

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

  • Posts: 73
  • Thank you received: 1
11 years 8 months ago #91975

I'm confused. This custom view you are talking about.. I did not create any custom view, and when i load show_custom it throws a 500 error.

In the view.html file I created a new method called showBrace(). This method is called inside the standard show() function as soon as the element object is created which contains the custom field that holds the ID of the other product. In the showBrace method I basically coppied the entire show() function and appended the object names with brace_ so they don't overwrite anything.

Then in the show.php file I copy pasted the part which displays the product and changed the object names accordingly (append with brace_). So now I'm wondering what the setLayout function does. Well... I kind of do understand, but I find it strange that all the necessary variables are not echoed in the show.php file but are rather set as a template.

I also would like to mention that all the objects/parameters/variables ARE passed to the view. They are in fact present in $this

You could take a looksie here:
pastebin.com/yTacMyFa

Thank you for your time in advance :)

EDIT:

I think i figured it out. I didn't realize there was a show_default view.. I thought it was some sort of a parameter. I'll try this out!

Last edit: 11 years 8 months ago by Ortix.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #92012

Isn't it easiest to display the products in a listing with only the two products ?

Because to display 2 products on the same page you have to change all the ids to not have any id duplicated, to add a product to cart the button add to cart must take the quantity set in the good input, etc.

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

Time to create page: 0.083 seconds
Powered by Kunena Forum