Call variant price on main product page

  • Posts: 50
  • Thank you received: 1
12 years 6 months ago #50355

Hi,

Is there any way I can place the variant pricing anywhere in the main product page? What code do I have to use?

I'm doing a book retail so we have characteristics like:
Format available: Paperback, eBook.

For example, let's say-
Main Product: Book A
Variant #1: Book A [Paperback] $15
Variant #2: Book A [eBook] $5

So what we want to do is to place the pricing somewhere in the product/show layout:

Paperback $15
eBook $5

What code do I have to use to put those two variant prices into the main product page?

Thanks.

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

  • Posts: 13201
  • Thank you received: 2322
12 years 6 months ago #50393

Hi hawkeyentjc,

You can use this code to display the pricing of each variants in your main product page:

	echo "<table>";
	foreach($this->element->variants as $variant){
		echo "<tr>";
		if($variant->prices[0]->price_value != null){
			echo "<td>".$variant->product_code."</td>";
			echo "<td>".$variant->prices[0]->price_value."</td>";
		}
		echo "</tr>";
	}
	echo "</table>";

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

  • Posts: 50
  • Thank you received: 1
12 years 6 months ago #50608

Hi Xavier,

The coding works great.

As of now, it doesn't display the currency symbol and the decimal point can go up to 5 points. Example:

Paperback 15.00000
eBook 5.00000

Is there any way to tweak the code so that it can display with currency symbol and also 2 decimal point only?

Paperback $ 15.00
eBook $ 5.00

Thanks!

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

  • Posts: 50
  • Thank you received: 1
12 years 6 months ago #50616

Hi,

This is another side question.

The code given above I believe only works for Product/Show page.

Is there any code to call the variant price into the Product --> listing_table view?

Many thanks!

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

  • Posts: 82822
  • Thank you received: 13368
  • MODERATOR
12 years 6 months ago #50687

You can use that code:
echo $this->currencyHelper->format($variant->prices[0]->price_value,$variant->prices[0]->price_currency_id)

instead of:
$variant->prices[0]->price_value

for that.

Regarding the products listing, that won't be possible as the data is not loaded on the products listings for variants (that would be too resource intensive on big websites and it's not necessary in the default views we have).

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

  • Posts: 50
  • Thank you received: 1
12 years 6 months ago #50746

Cool. It works great!

Thanks!

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

Time to create page: 0.072 seconds
Powered by Kunena Forum