Friday, July 19, 2013

Magento price lowest to highest in product view

In your sites/something/app/design/frontend/default/themename/template/catalog/product/view, add the following code and modify as appropriate. Thanks to someone who helped me.
if ($this->hasOptions() && $_product->getTypeId() === 'configurable') { $arrPrices = array(); $conf = Mage::getModel('catalog/product_type_configurable') ->setProduct($_product); $col = $conf->getUsedProductCollection() ->addAttributeToSelect('*')->addFilterByRequiredOptions(); if(count($col) > 0) { foreach($col as $simple_product) { $prod = Mage::getModel('catalog/product') ->load( $simple_product->getId() ); $price = trim($prod->getPrice()); if(!empty($price) && is_numeric($price)) { $arrPrices[] = number_format($price, 2,',',''); } } sort($arrPrices, SORT_NUMERIC); if (!empty($arrPrices) && $arrPrices[0] != end($arrPrices)) { echo "
"."R". $arrPrices[0]." - "."R".end($arrPrices).'
'; } } }
Then on the list page you can try playing with the following codes

if ($_product->getTypeId() === 'configurable') { $product = Mage::getModel('catalog/product')->load($_product->getId()); $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product); if(count($childProducts) > 0) { $arrPrices = array(); foreach ($childProducts as $child) $arrPrices[] = number_format($child->getPrice(), 2,',', ''); sort($arrPrices, SORT_NUMERIC); if ($arrPrices[0] != end($arrPrices)) { echo '
'. ''. ''."R".$arrPrices[0]." - "."R".end($arrPrices).''. ''.'
'; } else { echo $this->getPriceHtml($_product, true); } } else { echo $this->getPriceHtml($_product, true); } } else { echo $this->getPriceHtml($_product, true); }

No comments:

Post a Comment