Page 1 of 1
Adding Additional Details to Product Cards
Posted: Fri Feb 11, 2022 4:59 pm
by levelup
I'm attempting to update an old version (1.0.5) to the latest version and there are some custom buttons/details we need to add to the product card for the product listing page.
So, for example, we want to add a model number and manufacturer info to the cards. How would we add this info exactly? I'd hate to overwrite any core code.
I see the following snippet in "templates/default/includes/components/product_card.php":
Code: Select all
<h5 class="card-title"><a href="<?= $product->get('link') ?>"><?= $product->get('name') ?></a></h5>
How can I create something like "$product->get('model_number')"? Or, could I still use something like $listing['products_model'] here?
Re: Adding Additional Details to Product Cards
Posted: Fri Feb 11, 2022 9:31 pm
by Kofod95
levelup wrote: ↑Fri Feb 11, 2022 4:59 pm
"templates/default/includes/components/product_card.php":
Copy that file to the override-template or whatever you might have as selected template.
Says from the
class "product" execute the function "get" on the key inside the "()"
Returning to product_card.php I see that it just uses the name of what it wants in the "get-function"
and
So I thought; Why not just try:
Code: Select all
<h6><?= $product->get('model') ?> </h6>
and it worked. I would expect it to work like that with any entries in the products and the products_description tables.
Manufacturers would be a little more complicated, as the data needed for the manufacturer is in the manufacturers table, but I think this should show the name of the manufacuter:
Code: Select all
<h6><?= $product->get('brand')->getData('manufacturers_name') ?> </h6>
(Might throw error if no manufacturer is set)
//Daniel
Re: Adding Additional Details to Product Cards
Posted: Mon Feb 14, 2022 3:21 pm
by levelup
Kofod95 wrote: ↑Fri Feb 11, 2022 9:31 pm
levelup wrote: ↑Fri Feb 11, 2022 4:59 pm
"templates/default/includes/components/product_card.php":
Copy that file to the override-template or whatever you might have as selected template.
Says from the
class "product" execute the function "get" on the key inside the "()"
Returning to product_card.php I see that it just uses the name of what it wants in the "get-function"
and
So I thought; Why not just try:
Code: Select all
<h6><?= $product->get('model') ?> </h6>
and it worked. I would expect it to work like that with any entries in the products and the products_description tables.
Manufacturers would be a little more complicated, as the data needed for the manufacturer is in the manufacturers table, but I think this should show the name of the manufacuter:
Code: Select all
<h6><?= $product->get('brand')->getData('manufacturers_name') ?> </h6>
(Might throw error if no manufacturer is set)
//Daniel
Amazing and detailed post, thank you so much for your time. I'll look into it further from here, I really appreciate your insight!
Re: Adding Additional Details to Product Cards
Posted: Mon Feb 14, 2022 5:09 pm
by Kofod95
Happy to help!
//Daniel