News:

Support the VirtueMart project and become a member

Main Menu

Showing Low/High price band in Structure data file snippets.php

Started by Agaton, September 15, 2017, 10:03:10 AM

Previous topic - Next topic

Agaton

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?

Milbo

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]
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Agaton

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...

Milbo

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){
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/