News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

SOLVED: Dynamic pricing text on category view, based on product category.

Started by OliviaH, March 30, 2016, 16:44:00 PM

Previous topic - Next topic

OliviaH

Joomla 3.0.12
Virtuemart 3.4.8

At the moment on the category view I have a base price and unit price showing. (see attached image)

What I am trying to do is make the base price have text before it such as "Pack price: £10.00" but only for products that are in Category 1, all other products it would say perhaps "Unit Price: £10.00"

Would I need to make a sublayout for this, or could it be done in a template overwrite?


Cheers
Dan

jenkinhill

Looking at the image it appears that you are already using template overrides.  You could do that by editing the current prices.php sublayout to check for the category then echo the relevant price label.

Or you could create a new additional overrides for sublayouts/prices.php and one for category/default.php but using different filenames, so that the Category 1 uses those overrides and the other categories use whatever is set up as your default.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

OliviaH

Yea the problem I am having is I can't figure out how to check what category the product is in, as they are all in multiple categories.
How would I check for the Category ID in the array.

OliviaH

Solved it myself.


$cats = $product->categories;
if (in_array("106", $cats) || in_array("60", $cats) || in_array("130", $cats)) {$pricelabel = 'Pack Price: ';} else { $pricelabel = 'Price: ';}


On the categories/default.php I got the categories array then checked for the category IDs that i wanted to change the wording on the price shown.
echo $this->currency->createPriceDiv ('priceWithoutTax', $pricelabel, $product->prices);

Ghost

Use array_intersect instead of multiple in_array.

$cats = array(106, 60, 130);
if(array_intersect($cats, $product->categories)) ...

OliviaH

Cheers Ghost, worked like a charm.
Thought there might have been a more elegant way.