How to show variant selector on product list item

  • Posts: 202
  • Thank you received: 13
  • Hikashop Business
9 years 6 months ago #233366

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.4.45

A client wants to show the variant selector and accompanying total price on the product list pages. So I'm looking at customizing the listing_title.php file. The context ($this->element) for this page is a product category. And the variant content is at the product level. Also the 'characteristic_display' parameter doesn't exist here. Other than finding / implementing all the right code, is there any "can't get there from here" issues to adding this custom capability?

It would be nice if I could just somehow include the option.php template and it would work, but that's where the context of this page is an issue. So I'm thinking I need to load the product context then modify the code from the option.php file (included in the override listing_title.php file) to use the new product element rather than the $this->element that it is using in option.php.

Any and all help would be appreciated.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 84307
  • Thank you received: 13701
  • MODERATOR
9 years 6 months ago #233370

Hi,

It's indeed not a small job. You need to load all the necessary data from the database and then display the elements.
Another issue is that the code in option.php is based on the fact that you're displaying the options for one product on the page.
If you display the option file multiple times, you'll have the problem that the HTML elements will have the same ids. First, it's not valid in HTML, and second when you select something in the options, it will always refresh the HTML of the last product on the page.
So I would actually recommend not to use option.php but just :
- load the data you need
- display it the way you need it with your own HTML
- add custom javascript to do the refresh with your HTML

The following user(s) said Thank You: 3by400

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

  • Posts: 202
  • Thank you received: 13
  • Hikashop Business
9 years 5 months ago #234236

Do you think there is a way to make this work by rendering the add_to_cart_listing.php template as a modal window for each of the products? If so, how best to render that without all the page content, just the add_to_cart_listing.php content?


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 84307
  • Thank you received: 13701
  • MODERATOR
9 years 5 months ago #234250

Hi,

add_to_cart_listing.php doesn't display characteristics. It's done in the show_default view. So no, that won't help.
In that case, you would have to load the whole product page in the popup.
That could actually be an easy solution:
- use a popup to open the URL of the product page with the parameter tmpl=component added to the URL (that parameter will tell joomla to only display the content of the product page, not the modules or the template around)
- you can further edit the show_default view file to remove the parts you don't want to be displayed when you have the parameter "tmpl" set to "component" in the $_REQUEST.
That would actually be quite easy to achieve.

The following user(s) said Thank You: 3by400

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

  • Posts: 202
  • Thank you received: 13
  • Hikashop Business
9 years 5 months ago #234289

Just FYI. The modal approach does work. But turns out it isn't acceptable to the client. So back to my original plan. Thanks though for your insights.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 202
  • Thank you received: 13
  • Hikashop Business
9 years 5 months ago #234946

Still working on this. So Nicolas if you're still with me...

I've got the variant information displaying on the product listing page for each product by adding a plugin to get and place that information. Now I'm looking at the add_to_cart_listing.php file to figure out how it decides between the quantity box plus 'Add to Cart' button and the 'Choose Options' button. Since the quantity box and 'Add to Cart' button can already safely show on a product listing page (just not for products with variants), how is the best way to not break stuff, but show the quantity box and 'Add to Cart' when a product does have variants. Of course once that's done I still have to have some JS that updates the specific quantity box and makes sure the 'Add to Cart' adds the correct variant.

Thanks.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 84307
  • Thank you received: 13701
  • MODERATOR
9 years 5 months ago #234952

Hi,

That's actually quite easy to change. But you need to do it in the "quantity" view file.
Hint: It's these lines:
if(!empty($this->row->has_options)) {

The following user(s) said Thank You: 3by400

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

  • Posts: 202
  • Thank you received: 13
  • Hikashop Business
9 years 5 months ago #235299

Nicolas, I've got most of this working. The final step seems to be dealing with the Add to Cart button. Since there will be multiple buttons, one per product, on the product list page I need to uniquely identify them. So I'm not finding a good way to add a unique id or class to the input element. The button is created in the cart.php file in the displayButton function. I don't want to modify the cart.php or helper.php core files. I've already made overrides to the quantity.php, listing_title.php, and listing_price.php view templates. Is there anything I'm missing to add a unique class or id to the Add to Cart submit input button?


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 84307
  • Thank you received: 13701
  • MODERATOR
9 years 5 months ago #235319

The 6th parameter of the displayButton function allows you to specify extra attributes you need for your buttons.

For example:
echo $this->cart->displayButton(JText::_('ADD_TO_CART'), 'add', $this->params, $url, $this->ajax, 'id="unique_id_of_my_add_to_cart_button"', $max, $min);

The following user(s) said Thank You: 3by400

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

Time to create page: 0.066 seconds
Powered by Kunena Forum