0

Below is my code in question. I will list a few things below it.

if ($product->getTypeId() == 'configurable') {
    $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
    $product = $child;
}
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$response['status'] = 'SUCCESS';
$response['message'] = $message;
$this->loadLayout();
$topCart = $this->getLayout()->getBlock('topCart')->toHtml();
$response['topCart'] = $topCart;
$response['image'] = (string)Mage::helper('catalog/image')->init($product, 'thumbnail');
$response['name'] = $product->getname();
$response['price'] = Mage::helper('core')->formatPrice($product->getPrice(), true);

When $product is a simple product outright, there is no issue. The functions $product->getname(), $product->getPrice(), and init($product, 'thumbnail'), all return valid results.

When $product is found to be configurable, it's child product replaces it. I can then get the name, thumbnail but when I call the getprice function I get no results.

I don't understand why this would be. Anyone out there care to elucidate?

2
  • what value is given by $product->getPrice()
    – Amit Bera
    Commented Oct 21, 2014 at 15:41
  • @AmitBera When it is removed from the formatprice() it is returning nothing. Within formatprice I am getting 0.00. However, like I said, this only happens when the product is the child of a configurable product. When it is a simple product outright it is working as intended. Commented Oct 21, 2014 at 15:44

1 Answer 1

0

Mage_Catalog_Model_Product_Type_Configurable::getProductByAttributes uses Mage_Catalog_Model_Product_Type_Configurable::getUsedProductCollection to load items, this collection does not load the price from eav. So you have to load the product:

$child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
$product = Mage::getModel('catalog/product')->load($child->getId());

Now use $product->getFinalPrice(), this also implemets catalog price rules etc.

Regards

3
  • $product->getFinalPrice() still returns $0.00. Commented Oct 22, 2014 at 12:25
  • Hei, i edit my preview post, try this. worked on a local test. Regards Commented Oct 22, 2014 at 12:50
  • You are 'the man' Stefan. Commented Oct 22, 2014 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.