EDIT: Basically, my problem is that I need to get the minimal_price of an configurable product in category view. Previously, this worked by using
$_product = $this->getProduct();
$_product->getMinimalPrice();
However, it doesn't work anymore. I noticed, that when it still worked dumping $_product
would contain 'minimal_price'. Now, this is not the case anymore. Does anyone know what the reason could be?
OLD: I am currently struggling with a really weird error. I updated to magento 1.9 but not everything was working as expected. The category pages became really slow. So I downgraded again to 1.8 which was working fine on our test development server, but now the price of the configurable products, wouldn't display any more on the category sites. Even on a clean magento install 1.7 (with the same database!) it doesn't work.
What I found out is, that first, the price.phtml got changed im Magento 1.9 and two more calls were added, which lead to the increased loading time:
$_convertedFinalPrice = $_store->roundPrice($_store->convertPrice($_product->getFinalPrice()));
$_specialPriceStoreLabel = $this->getProductAttribute('special_price')->getStoreLabel();
The main problem for me is that prices aren't displayed anymore. I noticed the following:
When I dump $_product->debug();
it doesn't contain minimal_price anymore. That is most likely the reason why getMinimalPrice()
is not working anymore.
The weird part is, that like I said on a different test development site it is still working and $_product->debug();
still contains minimal_price.
Does someone have an explanation why on one page minimal_price is still included, but on a different site it's not?
Thanks
Remember to enable flat catalog and flat category ;)
I looked a little deeper into Magento's code and tracked down how Magento loads the products of the product list. When viewing the product list, the product collection is loaded by the model Mage_Catalog_Model_Layer, which adds the minimal price and other stuff to the products in the collection by adding joins to the collection’s SQL, but I have not yet found a model that does the same thing for single products instead of collections.
Because I don’t want to use a direct SQL query, I checked out the CatalogIndex module, but that module seems not to be working at all because all its indexing tables are empty or even corrupted.
$data_grouped = Mage::getModel("catalogindex/data_grouped"); $minimal = $data_grouped->getMinimalPrice(array($_product->getId()), Mage::app()->getStore());
looked good at first but it gives me the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_product_index_price.value' in 'field list'
The CatalogIndex module is either deprecated or I’m just too stupid to enable it.
However, I have now created a workaround in my price.phtml template, which uses the same method to retrieve the minimal price and tax percents as the product list does: At the beginning of the template I added the following:
$this->setProduct(Mage::getModel("catalog/product")->getCollection() ->addAttributeToSelect(Mage::getSingleton("catalog/config")->getProductAttributes()) ->addAttributeToFilter("entity_id", $this->getProduct()->getId()) ->setPage(1, 1) ->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() ->load() ->getFirstItem() );
which may not be the perfect solution, but it does the job and it does it a little cleaner than iterating over all child products and finding the minimal price that way.