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=================








                     

Monday, 17 August 2015

Phone number validation

<script type="text/javascript">
//<![CDATA[

  
    Validation.add('validate-mobile','<?php echo Mage::helper('contacts')->__('Please enter your mobile number.'); ?>',function (v, elm) {
          
        var reMax = new RegExp(/^maximum-length-[0-9]+$/);
        var reMin = new RegExp(/^minimum-length-[0-9]+$/);
      
        var result = true;
      
        if(Validation.get('IsEmpty').test(v))
        {
           result =false;
        }
      
      
        $w(elm.className).each(function(name, index) {
            if (name.match(reMax) && result) {
               var length = name.split('-')[2];
               result = (v.length <= length);
            }
            if (name.match(reMin) && result && !Validation.get('IsEmpty').test(v)) {
                var length = name.split('-')[2];
                result = (v.length >= length);
            }
          
        });
        return result;
    });
  
  
    var contactForm = new VarienForm('mobile_appForm',false);
  
  
  
 
//]]>
jQuery(document).ready(function(){
    var contactForm = new VarienForm('mobile_appForm',false);
    jQuery("#mobileappbuttom").click(function(e){
            if(contactForm.validator && contactForm.validator.validate()){
                e.preventDefault();
                var base_url=jQuery.trim(jQuery("#base_url").val());
                var mobile_number=jQuery("#mobile_number").val();
                jQuery.ajax({
                    url: base_url+'contacts/index/mobileapp/',
                    type:        'post',
                    data:({'mobile_number':mobile_number}),
                    success: function(msg){
                       jQuery("#aleart-text").text(msg);
                       //jQuery("#aleart-texterror").hide();
                        Effect.Appear('aleart-text', { duration: 0.2, delay: 1 });
                    }
                });
              
            }else {
                jQuery("#aleart-text").css({"display":"none"});
              //  jQuery("#aleart-texterror").text("Please enter your mobile number.");
            }
          
          
        });
  
    });
</script>

Thursday, 6 August 2015

How to write mobile number length validation in magento by prototype

<input type="text" id="mobile" name="mobile" title="Mobile" class="input-text required-entry validate-length maximum-length-10 minimum-length-10 validate-digits">

how to get parent Category Id by sub category - Magento

echo $cat_idd = $this->getCurrentCategory()->getParentCategory()->getId();

=============================================
$pre_cat        =       Mage::getModel('catalog/category')->load($catarry[0]);
       
        $cat_idd   = $pre_cat->getParentCategory()->getId();

Monday, 13 July 2015

Category attributed remove

 require_once("app/Mage.php");
 Mage::app('default');
 Mage::app()->setCurrentStore(
Mage_Core_Model_App::ADMIN_STORE_ID);
 $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
 $entityTypeId = $setup->getEntityTypeId('catalog_category');

 $setup->removeAttribute($entityTypeId,'category_video');

Wednesday, 8 July 2015

Custom mail send

      //send coupon code by email start
                $to= $customer_mail;
                $sender=Mage::getStoreConfig('trans_email/ident_general/email');
                $subject="Dokan.in Coupon Code for FB Like";
                $logo_img= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'/email/dokan-logo.png';
                $baseurl= Mage::getBaseUrl();
               
                $message .='<body style="font-family: Arial;">
                                <table cellpadding="0" cellspacing="0" border="0" width="650" align="center" style="border:1px solid #ccc;background:#ffffff">
                                    <tr><td height="20"></td></tr>
                                    <tr><td style="text-align: center;"><a href="'.$baseurl.'" target="_blank"><img src="'.$logo_img.'" alt="" /></a></td></tr>
                                    <tr><td style="font-weight: bold; font-size: 30px; color: #e32915; text-align: center;">Apply '.$couponCode.'in your next purchase.</td></tr>
                                    <tr><td height="50"></td></tr>
                                    <tr><td height="18"></td></tr>
                                    <tr><td style="text-align: center;"><a href="'.$baseurl.'" target="_blank" style="font-weight: bold; font-size: 44px; color: #0849ca; text-decoration: none;">www.dokan.in</a></td></tr>
                                    <tr><td style="padding:2px 0; font-size: 15px; font-weight: bold; color: #333; text-align: center;">BUY GROCERY &amp; VEGETABLES ONLINE</td></tr>
                                    <tr><td height="20"></td></tr>
                                    <tr><td style="padding:12px 0 10px; font-size: 15px; font-weight: bold; color: #333; text-align: center; background: #ffd21d;">DELIVERY AREA: CHANDANNAGAR, CHINSURAH, MANKUNDU</td></tr>
                                </table>
                            </body>';
                                    
                   $headers = "MIME-Version: 1.0" . "\r\n";
                   $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                   $headers .= 'From:Dokan.in coupon code<'.$sender . ">\r\n";
                   mail($to,$subject,$message,$headers);
               

Programmatically coupon code created in magento

                  $couponCode=Mage::helper('core')->getRandomString(16);
               
              
                $coupon = Mage::getModel('salesrule/rule');
                $coupon->setName("Coupon for ".$customer_mail." on ".date('Y-m-d H:i:s'))
               ->setDescription(null)
               ->setFromDate(date('Y-m-d'))
               ->setCouponType(2)
               ->setCouponCode($couponCode)
               ->setUsesPerCoupon(1)
               ->setUsesPerCustomer(1)
               ->setCustomerGroupIds(array(1,2,3,4))
               ->setIsActive(1)
               ->setStopRulesProcessing(0)
               ->setIsAdvanced(1)
               ->setProductIds('')
               ->setSortOrder(0)
               ->setSimpleAction('by_fixed')
               ->setDiscountAmount(250)
               ->setDiscountQty(null)
               ->setDiscountStep('0')
               ->setSimpleFreeShipping('0')
               ->setApplyToShipping('0')
               ->setIsRss(0)
               ->setWebsiteIds(array(1));
                $coupon->loadPost($coupon->getData());
                $coupon->save();