Try the Demo

Magento Forum

   
Getting variable from child
 
timonijhof
Jr. Member
 
Total Posts:  4
Joined:  2010-05-08
 

Hello there,

I have in my product view some extra options. These option are showed now but it messed up the layout when no extra options are available for a certain product. When I put the code somewhere else in the ordering of code the layout is good when no extra options are added but messed up when there are extra options.

So I thought to use a IF statement to look if there are any options, if not show the code earlier. But the variable I need is inside a child which is called within this piece of code. How can I get the variable out of it? Hope it’s clear, here is the code that add’s the extra options:

<div class="add-to-box"><?php if (!$this->hasOptions()):?>
<div>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getChildHtml('emjainteractive_externalproduct_link') ?>
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php endif; ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php endif; ?></div>

The variable I need is within product_type_data and called $_hasAssociatedProducts

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
jeffcustom
Member
 
Avatar
Total Posts:  67
Joined:  2012-11-29
Boulder, CO
 

$_hasAssociatedProducts is a local variable for the product data template --- you will not be able to see this in the product view template.

You can get the same data via

$_associated $_product->getTypeInstance(true)
            ->
getAssociatedProducts($_product);

$_hasAssociated count($_associated);

I found this by tracing the call to $_assocaitedProducts back to the grouped product view block.

Let me know if that\’s not what you\’re looking for!

 Signature 

Customer Paradigm
A Magento Silver Solutions Partner
Boulder, Colorado
Projects From 1 hour to 1,000+
Magento Certified Developers
Programmers Who Care.  Code That Works.
Call Us: 303.473.4400
Toll Free: 888.772.0777
Visit: CustomerParadigm.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
timonijhof
Jr. Member
 
Total Posts:  4
Joined:  2010-05-08
 

Dear Jeff,

thank you for your help!

The code is working but not entirely. It\\\\\\\’s working when a product has extra options, so that\\\\\\\’s good. But if a product doesn\\\\\\\’t have extra options, it cannot find the method. I got the debug code here:

Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getAssociatedProducts() in /home/users/sierqftp/sierbestratingsdeal.nl/app/design/frontend/default/sierbestratingsdeal/template/catalog/product/view.phtml on line 86

Tried to work around it but it seems I have to call the method in order for the code to work.

With kind regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
jeffcustom
Member
 
Avatar
Total Posts:  67
Joined:  2012-11-29
Boulder, CO
 

Yes, you need to check if the product is of a type that supports these options. Try:

if ($_product->getTypeId() == Mage_Catalog_Product_Type::TYPE_BUNDLE || 
    
$_product->getTypeId() == Mage_Catalog_Product_Type::TYPE_CONFIGURABLE ||
    
$_product->getTypeId() == Mage_Catalog_Product_Type::TYPE_GROUPED)
{
//Your type specific data here
    
$_associated $_product->getTypeInstance(true)
            ->
getAssociatedProducts($_product);

     
$_hasAssociated count($_associated);
}

 Signature 

Customer Paradigm
A Magento Silver Solutions Partner
Boulder, Colorado
Projects From 1 hour to 1,000+
Magento Certified Developers
Programmers Who Care.  Code That Works.
Call Us: 303.473.4400
Toll Free: 888.772.0777
Visit: CustomerParadigm.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
timonijhof
Jr. Member
 
Total Posts:  4
Joined:  2010-05-08
 

Thank you very much for your help.
The error became simpler but still is there:

Fatal error: Class ‘Mage_Catalog_Product_Type’ not found in /home/users/sierqftp/sierbestratingsdeal.nl/app/design/frontend/default/sierbestratingsdeal/template/catalog/product/view.phtml on line 86

Error.

 
Magento Community Magento Community
Magento Community
Magento Community
 
timonijhof
Jr. Member
 
Total Posts:  4
Joined:  2010-05-08
 

Did find out that we forgot model in the Mage_Catalog_Model_Product_Type. Everything working right now!

if ($_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE ||
$_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE ||
$_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED)
{

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top