VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: Agaton on September 15, 2017, 10:03:10 AM

Title: Showing Low/High price band in Structure data file snippets.php
Post by: Agaton on September 15, 2017, 10:03:10 AM
I am currently working on improving the snippets.php file in my overrides.

I am trying to extract the low price and high price but am struggling to do so to include tax.

My code looks like this

$allPrices = VmModel::getModel('product')->loadProductPrices($product->virtuemart_product_id, 0,$virtuemart_shoppergroup_ids,true);
print_r($allPrices);

foreach($allPrices as $prices) {
if ($prices['price_quantity_end'] == '0') {
$jsonLast = $prices['product_price'];
}
if ($prices['price_quantity_start'] == '1' ) {
$jsonFirst = $prices['product_price'];
}
}
echo $jsonLast . ' to ' . $jsonFirst;


My feeling is that I am missing a setting in

VmModel::getModel('product')->loadProductPrices($product->virtuemart_product_id, 0,$virtuemart_shoppergroup_ids,true);

But searches for both answers in forum and documentation are not being fruitful... Can anyone help?
Title: Re: Showing Low/High price band in Structure data file snippets.php
Post by: Milbo on September 20, 2017, 11:15:54 AM
The prices are already loaded. Please use the vmdebug to take a look on your products.


vmdebug('my product',$myProduct);


Then you will see that the "prices" array is a kind of fallback, directly mapped to $myProduct->allPrices[$myProduct->selectedPrice]. Take a look on the allPrices. I am not sure if the other prices have already the calculated values. If not, you need to execute the calculation just for the other "selectedPrice". Kind of that. [/code]
Title: Re: Showing Low/High price band in Structure data file snippets.php
Post by: Agaton on September 21, 2017, 14:31:54 PM
Quote from: Milbo on September 20, 2017, 11:15:54 AM
The prices are already loaded. Please use the vmdebug to take a look on your products.


vmdebug('my product',$myProduct);


Then you will see that the "prices" array is a kind of fallback, directly mapped to $myProduct->allPrices[$myProduct->selectedPrice]. Take a look on the allPrices. I am not sure if the other prices have already the calculated values. If not, you need to execute the calculation just for the other "selectedPrice". Kind of that. [/code]

Thanks for the reply. Yes I have already run a print of my array and seen that the prices exist including tax with the exception of quantity dependant prices. They are not presented with tax...
Title: Re: Showing Low/High price band in Structure data file snippets.php
Post by: Milbo on September 22, 2017, 10:27:33 AM
Ah yes, because the quantity and the date are directly used in the sql to load the right prices. hmmm.

then you need to use this function

public function loadProductPrices($productId,$virtuemart_shoppergroup_ids,$front){

and use for the last parameters false! then it loads all prices. for example loadProductPrices($productId, false, false){