0

I used Below code for send mail if customer enter Unsupport pincode. It's working fine:

<?php

class Webkul_Mpperproductshipping_Model_Carrier_LocalDelivery extends Mage_Shipping_Model_Carrier_Abstract
{
    /*  Use group alias */
    protected $_code = 'mpperproductshipping';

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

        $customer = Mage::getSingleton('customer/session')->getCustomer();
        $name = $customer->getName();
        $email = $customer->getEmail();
        $restrictedCodes = [
            110001,
            110002,

        ]; //restricted values. they can come from anywhere
        if (!in_array($postCode, $restrictedCodes)) {
            $body = 'Hi admin, '
                . 'I am ' . $name . ($email) . ' I try to Place Order with this Pincode ' . $postCode . ' But I cant able to place order please check with it';
            $mail = Mage::getModel('core/email');
            $mail->setToName($name);
            $mail->setToEmail('mymail@gmail.com');
            $mail->setBody($body);


            $mail->setSubject('Not Support Pincode');
            $mail->setFromEmail('domain.com');
            $mail->setFromName($name);
            $mail->setType('html');// 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 false;

        }

I try to send a mail with shopping cart item also with this code:

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
    $productName = $item->getProduct()->getName();

}

But it show only one items not all items.

1
$cart = Mage::getSingleton('checkout/cart')->getQuote();
$productName = array();
$skus = array();
foreach ($cart->getAllItems() as $item) {
    $productName[] = $item->getProduct()->getName();
    $skus[] = $item->getProduct()->getSku()
}

$productNames = implode(', ', $productName);
$productSkus = implode(', ', $skus); // or do something else...

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.