Oggi vi propongo una selezione gustosa di mostri di codice con cui il team di sviluppo MageSpecialist, si è scontrato negli ultimi mesi: codice di terze parti relativo al frontend di Magento capace di far mettere le mani nei capelli a qualsiasi sviluppatore degno di questo nome!

ATTENZIONE DISCLAIMER MEDICO: il codice visualizzato qui sotto potrebbe, in alcuni casi, creare reazioni isteriche, sanguinamento agli occhi e depressione professionale! 😀
Se siete deboli di cuore non andate oltre!


#1 – CDATA

         <reference name="after_content">
             <block type="cms/block" name="brands">
                 <action method="setBlockId">
                     <block_id>brands</block_id>
                 </action>
             </block>
             <block type="core/text" name="your.block.name">
                 <action method="setText">
                     <text>
                         <![CDATA[
                             <script type="text/javascript">
                                 jQuery(function(){
                                     jQuery("#brands_slider").slick({
                                         infinite: false,
                                         speed: 300,
                                         slidesToShow: 6,
                                         slidesToScroll: 6,
                                         responsive: [
                                             {
                                               breakpoint: 1024,
                                               settings: {
                                                 slidesToShow: 4,
                                                 slidesToScroll: 4,
                                                 infinite: true,
                                                 dots: true
                                               }
                                             },
                                             {
                                               breakpoint: 600,
                                               settings: {
                                                 slidesToShow: 3,
                                                 slidesToScroll: 3
                                               }
                                             },
                                             {
                                               breakpoint: 480,
                                               settings: {
                                                 slidesToShow: 2,
                                                 slidesToScroll: 2
                                               }
                                             }
                                             // You can unslick at a given breakpoint now by adding:
                                             // settings: "unslick"
                                             // instead of a settings object
                                           ]
                                     });
                                 });
                             </script>
                         ]]>
                     </text>
                 </action>
             </block>
         </reference>

#2 – Parents

$jq(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find('.product-image');

#3 – Grand Parents

if(!img.length) {
        img = $jq(this).closest('.actions').parent().find('.product-image');
        if(!img.length){
            img = $jq(this).closest('.actions').parent().parent().find('.product-image');
        }
        if(!img.length){
            img = $jq(this).closest('.actions').parent().parent().parent().find('.product-image');
        }
        if(!img.length){
            img = $jq(this).closest('.actions').parent().parent().parent().parent().find('.product-image');
        }
        if(!img.length){
            img = $jq(this).parent().parent().parent().parent().parent().find('.product-image');
        }
        if(!img.length){
            img = $jq(this).parent().parent().parent().parent().parent().parent().find('.product-image');
        }
        if(!img.length){
            img = $jq(this).parent().parent().parent().parent().parent().parent().parent().find('.product-image');
        }
        if(!img.length){
            img = $jq(this).parent().parent().parent().parent().parent().parent().parent().parent().find('.product-image');
        }

                            if(!img.length){
            img = $jq(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find('.product-image');
        }
}

#4 – Children

    jQuery('.col-main .products-grid li:nth-child(2n)').addClass('nth-child-2n');
    jQuery('.col-main .products-grid li:nth-child(2n+1)').addClass('nth-child-2np1');
    jQuery('.col-main .products-grid li:nth-child(3n)').addClass('nth-child-3n');
    jQuery('.col-main .products-grid li:nth-child(3n+1)').addClass('nth-child-3np1');
    jQuery('.col-main .products-grid li:nth-child(4n)').addClass('nth-child-4n');
    jQuery('.col-main .products-grid li:nth-child(4n+1)').addClass('nth-child-4np1');
    jQuery('.col-main .products-grid li:nth-child(5n)').addClass('nth-child-5n');
    jQuery('.col-main .products-grid li:nth-child(5n+1)').addClass('nth-child-5np1');
    jQuery('.col-main .products-grid li:nth-child(6n)').addClass('nth-child-6n');
    jQuery('.col-main .products-grid li:nth-child(6n+1)').addClass('nth-child-6np1');
    jQuery('.col-main .products-grid li:nth-child(7n)').addClass('nth-child-7n');
    jQuery('.col-main .products-grid li:nth-child(7n+1)').addClass('nth-child-7np1');
    jQuery('.col-main .products-grid li:nth-child(8n)').addClass('nth-child-8n');
    jQuery('.col-main .products-grid li:nth-child(8n+1)').addClass('nth-child-8np1');

#5 – Single

Mage::getSingleton('catalog/product')->load(14)->clearInstance()->getIdBySku('AKS/6')

#6 – Automation

< ?php /* AUTOSHIPPING */?>
< ?php if ($this->getQuote() && $this->getQuote()->getId())
    {
    $storeCode = strtoupper(Mage::app()->getStore()->getCode());
    $shippingAddress = $this->getQuote()->getShippingAddress();
    if ($shippingAddress->getCountryId()=='')
        {
        if ($storeCode=='EN') {$storeCode=='GB';};
        $shippingAddress->setCountryId($storeCode)->save();
        if ($storeCode=='IT') {$shippingAddress->setRegion('Lombardia')->save();};
        $shippingAddress->setShippingMethod('tablerate_bestway')->save();
        $this->getQuote()->save();
        Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart/'));
        }
    }
?>