2

I have different kinds of products, USPS Media mail is good for books, but not for all products. How can i restrict Media Mail Not allowed for other products.

Condition:

1) If cart consists both book and other kind products media mail option will should not come,

2) And Show POPUP message like, If you want to use Media Mail shipping, Please be in your cart consist Books Only, and place another order for remaining products. and this popup is only for optional.

0

If cart consists both book and other kind products, then to hide USPS Media mail shipping method, you need to override Model file of USPS into your local folder.

app\code\local\Mage\Usa\Model\Shipping\Carrier\Usps.php

Go to the line no :517 with function _parseXmlResponse.

//to get order is placed from admin side or frontend
  $module_name = Mage::app()->getRequest()->getModuleName();
        $adminUrl = Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');
        if ($module_name == $adminUrl) {
            $quote_obj = new Mage_Adminhtml_Model_Sales_Order_Create();
        } else {
            $quote_obj = new Mage_Checkout_Model_Type_Onepage();
        }
        $Quote = $quote_obj->getQuote();

        $isContainBook = false;
        foreach ($Quote->getAllItems() as $ext_cart_item) {
            //get ur cart item contain only book or not
            $isContainBook = true;
        }
        foreach ($priceArr as $method => $price) {
            $rate = Mage::getModel('shipping/rate_result_method');
            $rate->setCarrier('usps');

            if ($method == "6" && !$isContainBook) {
                continue;
            }

to get the method code for Media Mail Parcel, Go to the line no 576 within function getCode in the same file.

 public function getCode($type, $code = '')
 {
    $codes = array(
         'method' => array(
             '0_FCLE' => Mage::helper('usa')->__('First-Class Mail Large Envelope'),
             '0_FCL'  => Mage::helper('usa')->__('First-Class Mail Letter'),
             '0_FCSL' => Mage::helper('usa')->__('First-Class Mail Stamped Letter'),
             '0_FCP'  => Mage::helper('usa')->__('First-Class Package Service - Retail'),
             '0_FCPC' => Mage::helper('usa')->__('First-Class Mail Postcards'),
             '1'      => Mage::helper('usa')->__('Priority Mail'),
             '2'      => Mage::helper('usa')->__('Priority Mail Express Hold For Pickup'),
             '3'      => Mage::helper('usa')->__('Priority Mail Express'),
             '4'      => Mage::helper('usa')->__('Retail Ground'),
             '6'      => Mage::helper('usa')->__('Media Mail Parcel'),
             '7'      => Mage::helper('usa')->__('Library Mail Parcel'),

you can get the all methods codes from this funtion.

  • In my case there are two categories only consists books, so how can i give my category id for restriction condition. – zus May 29 '18 at 5:47
  • @zus you can get the category id of products which are in the cart and compare that category with your categories consists books(you can get these category id either static or dynamic) for dynamic you can create a configuration setting for store category id which contain books...hope this will help you. – shilpi Singh May 29 '18 at 12:16
  • From above code, where i can add category id's, – zus May 29 '18 at 12:31
  • Let me explain, i need to enter my categories id, so that, selected kind of categories Products ship only Media Mail, i need to know where i can enter the categories id. – zus May 29 '18 at 12:36
  • You can use config data to store and get categories. To store config data Mage::getModel('core/config')->saveConfig('my/path/whatever', $value); and to get config data Mage::getStoreConfig('my/path/whatever'); If you have already created module then you can easily create system configuration otherwise it would be lengthy process. – shilpi Singh May 29 '18 at 13:44

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.