1

We have Support certain Pin code only if customer try to enter un support pincode i want to send a mail how to send that

 <?php
    class Webkul_Mpperproductshipping_Model_Carrier_LocalDelivery extends Mage_Shipping_Model_Carrier_Abstract
    {

        protected $_code = 'mpperproductshipping';

        public function collectRates(Mage_Shipping_Model_Rate_Request $request){        
        $postCode = $request->getDestPostcode();
        $restrictedCodes = array(




    110001,
    110002,

); //restricted values. they can come from anywhere
    if (!in_array($postCode, $restrictedCodes)) { 
         return false;

    }   

        $result = Mage::getModel('shipping/rate_result');

        /* Edited by vikas_mageworx */
        $postcode=$request->getDestPostcode();
        $countrycode=$request->getDestCountry();
        $items=$request->getAllItems();
        /* End Editing by vikas_mageworx */

        $postcode=str_replace('-', '', $postcode);
        $shippingdetail=array();

        /*  one start */
        $shippostaldetail=array('countrycode'=>$countrycode,'postalcode'=>$postcode,'items'=>$items);
       /*  one end  */

         /* tt start - ship charges never work  
         $shippostaldetail=array('countrycode'=>$countrycode,'postalcode'=>$postcode);
         tt end */


        foreach($items as $item) {
            $proid=$item->getProductId();
            $options=$item->getProductOptions();
            $mpassignproductId=$options['info_buyRequest']['mpassignproduct_id'];
            if(!$mpassignproductId) {
                foreach($item->getOptions() as $option) {
                    $temp=unserialize($option['value']);
                    if($temp['mpassignproduct_id']) {
                        $mpassignproductId=$temp['mpassignproduct_id'];
                    }
                }
            }
            if($mpassignproductId) {
                $mpassignModel = Mage::getModel('mpassignproduct/mpassignproduct')->load($mpassignproductId);
                $partner = $mpassignModel->getSellerId();
            } else {
                $collection=Mage::getModel('marketplace/product')
                    ->getCollection()->addFieldToFilter('mageproductid',array('eq'=>$proid));
                foreach($collection as $temp) {
                    $partner=$temp->getUserid();
                }
            }

            $product=Mage::getModel('catalog/product')->load($proid)->getWeight();
            $weight=$product*$item->getQty();
            if(count($shippingdetail)==0){
                array_push($shippingdetail,array('seller_id'=>$partner,'items_weight'=>$weight,'product_name'=>$item->getName(),'qty'=>$item->getQty(),'item_id'=>$item->getId()));
            }else{
                $shipinfoflag=true;
                $index=0;
                foreach($shippingdetail as $itemship){
                    if($itemship['seller_id']==$partner){
                        $itemship['items_weight']=$itemship['items_weight']+$weight;
                        $itemship['product_name']=$itemship['product_name'].",".$item->getName();
                        $itemship['item_id']=$itemship['item_id'].",".$item->getId();
                        $itemship['qty']=$itemship['qty']+$item->getQty();
                        $shippingdetail[$index]=$itemship;
                        $shipinfoflag=false;
                    }
                    $index++;
                }
                if($shipinfoflag==true){
                    array_push($shippingdetail,array('seller_id'=>$partner,'items_weight'=>$weight,'product_name'=>$item->getName(),'qty'=>$item->getQty(),'item_id'=>$item->getId()));
                }
            }
        }
        $shippingpricedetail=$this->getShippingPricedetail($shippingdetail,$shippostaldetail);

        if($shippingpricedetail['errormsg']!==""){
            Mage::getSingleton('core/session')->setShippingCustomError($shippingpricedetail['errormsg']);
            return $result;
        }
        /*store shipping in session*/
        $shippingAll=Mage::getSingleton('core/session')->getData('shippinginfo');
        $shippingAll[$this->_code]=$shippingpricedetail['shippinginfo'];
        Mage::getSingleton('core/session')->setData('shippinginfo',$shippingAll);

        $method = Mage::getModel('shipping/rate_result_method');
        $method->setCarrier($this->_code);
        $method->setCarrierTitle(Mage::getStoreConfig('carriers/'.$this->_code.'/title'));
        /* Use method name */
        $method->setMethod($this->_code);
        $method->setMethodTitle(Mage::getStoreConfig('carriers/'.$this->_code.'/name'));
        $method->setCost($shippingpricedetail['handlingfee']);
        $method->setPrice($shippingpricedetail['handlingfee']); 
        $result->append($method);
        return $result; 
    }

.phtml

<?php $_shippingRateGroups = $this->getShippingRates(); ?>
<?php if (!$_shippingRateGroups): ?>
    <p><?php echo $this->__('Sorry, We cannot Deliver Product to Your Shipping Address, Please Change the "Shipping address and Pincode" and Tryagain.') ?></p>
<?php else: ?>

---------

<?php endif;?>
1

add email code in your after error

if($shippingpricedetail['errormsg']!==""){
                Mage::getSingleton('core/session')->setShippingCustomError($shippingpricedetail['errormsg']);
               $body = "Hi there, here is some plaintext body content";
    $mail = Mage::getModel('core/email');
    $mail->setToName('John Customer');
    $mail->setToEmail('customer@email.com');
    $mail->setBody($body);
    $mail->setSubject('The Subject');
    $mail->setFromEmail('yourstore@url.com');
    $mail->setFromName("Your Name");
    $mail->setType('text');// You can use 'html' or 'text'

    try {
    $mail->send();
    Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
    $this->_redirect('');
    }
    catch (Exception $e) {
    Mage::getSingleton('core/session')->addError('Unable to send.');
    $this->_redirect('');
    }
     return $result;
            }
  • No i didn't got mail – Magento 2 Mar 15 '16 at 10:36
  • did it show error unable to send?? – Qaisar Satti Mar 15 '16 at 10:38
  • No message ..... – Magento 2 Mar 15 '16 at 10:40
  • if (!in_array($postCode, $restrictedCodes)) { return false; } add code here maybe return from here – Qaisar Satti Mar 15 '16 at 10:42
  • Ya i got it it redirct to shooping cart i don't want to redirct to shopping cart – Magento 2 Mar 15 '16 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.