Question

quick thing, to start, we have a module that is displayed in the sidebar and it gets the product id with the Mage::registry('current_product')->getId(); in the first time is rendering with no problem, but the problem is when you go from the cart to the product added (with product title link) then the sidebar is on the right side but all of the blocks gets rendered in the bottom of the page. What could be the problem?

Thanks A lot. if you need some code or anything to help us just say it.

EDIT !! CODE ADDED

    <reference name="right">
<block type="catalog/product_view" name="catalog.product.installation" as="installation_service" before="product.right.garantias.select" template="catalog/product/view/installation.phtml"/>
            </reference>
<?php 
$_product_instalation = NULL;
$_product_id = Mage::registry('current_product')->getId();
if($_product_id):
$_prod_current = Mage::getModel('gnfcatalog/product')->getInstallationProduct($_product_id);

$_is_installation = Mage::getModel('gnfcatalog/product')->getInstallationInCart();

?>

<?php if (isset($_prod_current)): ?>
    <?php 
    $_helper_loc = $this->helper('customerlocator');
    $_coreHelper = $this->helper('core');
    try{
        $customer_loc = Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress();//$_helper_loc->getCustomerAddress();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    ?>

<?php if (!$_is_installation) : ?>
    <div class="row-fluid add-to-links">
        <img src="<?php echo $this->getSkinUrl('images/logo_instalacion_segura_rojo.jpg'); ?>" alt="Instalación segura" style="max-height:45px; width: auto; border-radius:7px;" class="pull-left" />
        <p id="installationTitle">instalaci&oacute;n segura</p>
        <div class="block block-highlight installation" style="margin-top:10px;">
            <div class="block-content" style="padding-bottom:0;">
               <div>
                    <p>Una vez contratada aguardá el llamado de nuestro Instalador:</h3>
                    <ul id="installation_steps">
                        <li>Juntos coordinarán fecha y hora de la visita.</li>
                        <li>El día acordado, el instalador lleva e instala el artefacto.</li>
                        <li>Si tenés alguna duda, comunicate 
                        con nosotros al 0810 666 2887.</li>
                    </ul>
               </div>

                <?php endif ?>
                <br>
                <div class="pull-left">
                    <p><strong><?php echo $this->__('¿Querés comprar tu producto instalado?') ?></strong></p>
                    <label class="clearfix">
                        <input type="radio" class="related-checkbox" id="related-checkbox<?php echo $_prod_current->getId() ?>" name="related_products[]" 
                               value="<?php echo $_prod_current->getId() ?>" />
                        <?php echo $this->__('Lo quiero con Instalación Segura!') //$_prod_current->getName() ?>
                    </label>
                    <label class="clearfix">
                        <input type="radio" class="validate-one-required related-checkbox" name="related_products[]" value="" checked />
                        <?php echo $this->__("No, gracias") ?>
                    </label>
                </div>
                <div class="pull-right text-center" style="position: relative;">
                    <div style="padding-bottom: 5px;">
                        <?php if (!$_helper_loc->getCustomerAddress()->getRegionId()) : ?>
                        <?php echo $this->__('Desde') . '&nbsp;';?>
                        <?php endif; ?>
                        <?php echo $_coreHelper->currency($_prod_current->getFinalPrice(), true, true) ?>
                    </div>
                    <button id="view-price-installation" type="button" class="button btn-primary">
                        <span>
                            <span><?php echo $this->__('Cotizar')?></span>
                        </span>
                    </button>
                </div>
            </div>
        </div>
        <div class="validation-advice" id="advice-validate-one-required-by-name-related_products[]" style="display:none;"><?php echo $this->__('Seleccione una de las opciones.') ?></div>
    </div>
<?php endif; ?>

<script type="text/javascript">
    $jq = jQuery.noConflict();
    $jq(document).ready(function($){
        if ($('#view-price-installation').length){
            $('#view-price-installation').click(function(){
                var position = $(this).offset();
                $('#customer-location-installation')
                .css({position: 'absolute', left: position.left - 75, top: position.top + 32})
                .fadeToggle(500);
            });
        }
        //$jq('#view-price-installation').popover({content: $jq('#customer-location-installation').html(), html: true, placement: 'left'});
    });

    //<![CDATA[
    $$('.related-checkbox').each(function(elem){
        Event.observe(elem, 'change', addRelatedToProduct);
    });
    $$('.related-checkbox').invoke('observe', 'change', addRelatedToProduct);

    function addRelatedToProduct(elem){
        var checkboxes = $$('.related-checkbox');
        var values = [];
        for(var i=0;i<checkboxes.length;i++){
            if(checkboxes[i].checked) values.push(checkboxes[i].value);
        }
        if($('related-products-field')){
            $('related-products-field').value = values.join(',');
        }
    }
    //]]>
</script>
<?php endif; ?>
Was it helpful?

Solution

Mage::registry('current_product') is only define on the product detail page, therefore on the cart page you should getting a fetal error

Try changing your code to

...
if($_product = Mage::registry('current_product')){
  $_product_id = $_product->getId();
  $_prod_current = Mage::getModel('gnfcatalog/product')->getInstallationProduct($_product_id);

  $_is_installation = Mage::getModel('gnfcatalog/product')->getInstallationInCart();
  ...
} 
....

current_product is set only on the product page in using

    // Register current data and dispatch final events
    Mage::register('current_product', $product);
    Mage::register('product', $product);

Mage::registry('current_product') will return null. Take a look at Mage class

public static function registry($key)
{
    if (isset(self::$_registry[$key])) {
        return self::$_registry[$key];
    }
    return null;
}

Therefore you can not get the method ->getId() of null which will result in a Fatal Error - getId() on a non-object

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top