Friday, 18 September 2015

Configurable product add to cart on custom page in magento


==============================Price============

 Price section :- <span class="con_price">
                <?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>
                </span>

=============================================
 <?php /*********Configurable product add to cart **********/ ?>
                               <?php
            $productAttributeOptions = $_product->getTypeInstance(true)
            ->getConfigurableAttributesAsArray($_product);
            $super_attributedcode='';
            $super_attributedfrontend_label='';
            $super_a_id='';
            foreach($productAttributeOptions as $supperattributed){
                $super_attributedcode=$supperattributed['attribute_code'];
                $super_a_id=$supperattributed['attribute_id'];
                $super_attributedfrontend_label=$supperattributed['frontend_label'];
            }
           
            $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
            $childProducts = $conf->getUsedProductCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('status', array('eq' => 1))
            ->addFilterByRequiredOptions();
            ?>
           
            <span class="attributed_label"><?php echo $super_attributedfrontend_label; ?>: </span>
            <select class="con_productselectoption" name="con_productselectoption" id="con_product__<?php echo $_product->getId(); ?>">
            <?php
            foreach($childProducts as $_simproduct)
            {
                $sim_productid=$_simproduct->getId();
                $_sproduct= Mage::getModel('catalog/product')->load($sim_productid);
                $childPrice =  number_format($_sproduct->getPrice(),2);
                $childRetailPrice = number_format($_sproduct->getRetailPrice(),2);
                $childFinalPrice = number_format($_sproduct->getFinalPrice(),2);
               
                $attr = $_sproduct->getResource()->getAttribute($super_attributedcode);
                $option_id = $attr->getSource()->getOptionId($_sproduct->getAttributeText($super_attributedcode));
               
                $params = array(
               
                'product'=> $_product->getId(),
                Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core/url')->getEncodedUrl(),
                'form_key'=>Mage::getSingleton('core/session')->getFormKey()
                );
               
                $addToCartUrl= $this->getUrl("checkout/cart/add/", $params ).'?super_attribute['.$super_a_id.']='.$option_id;
               
            ?>
                 <option value="<?php echo $option_id; ?>" data-formatedprice="<?php echo Mage::helper('core')->currency($childFinalPrice, true, false); ?>" data-price="<?php echo $childFinalPrice; ?>"  data-carturl="<?php echo $addToCartUrl ?>"  ><?php echo $_sproduct->getAttributeText($super_attributedcode); ?></option>
                <?php
            }
           
            ?>
            </select>
           
            <a href="#" class="cls-add-to-cart" ><span><span><?php echo $this->__("Add To cart") ?></span></span></a>

================JQury=========================


    jQuery(document).ready(function(){
        var superattributedid='';
        var con_productid='';
        var option_price='';
   
    jQuery(".con_productselectoption").each(function(){
       
        option_price=jQuery(this).find("option:selected").data("formatedprice");
        jQuery(this).closest("li").find(".con_price").html(option_price);
        jQuery(this).closest("li").find(".cls-add-to-cart").attr("href",jQuery(this).find("option:selected").data("carturl"));
       
    });
   
    jQuery(".con_productselectoption").change(function(){
        option_price=jQuery(this).find("option:selected").data("formatedprice");
        jQuery(this).closest("li").find(".con_price").html(option_price);
        jQuery(this).closest("li").find(".cls-add-to-cart").attr("href",jQuery(this).find("option:selected").data("carturl"));
       
    });
    });

======================End=================








                     

No comments:

Post a Comment