Saturday Delivery option UPS extension Magento

1.2k Views Asked by At

I am using Magento Enterprise.

I am trying to pull the Saturday delivery option from the UPS API on my checkout page on the frontend. I can't seem to get anywhere with it at the moment. I have the option enabled on the admin and when I try to call the getAvailableMethods() function and print the result I get the Saturday delivery option on the array but I can't get the option to display on the frontend. I have modified the UPS model to include the code of the saturday delivery (which after a lot of research I've found out that does not work that way anymore) but it is still not doing anything. Is there a way in which I can get the delivery option on my frontend checkout page?

Here's some of the code I'm using

in my UPS Model

I've included the Saturday delivery option under my originShipment array

'originShipment'=>array(
                // United States Domestic Shipments
                'United States Domestic Shipments' => array(
                    '01' => Mage::helper('usa')->__('UPS Next Day Air'),
                    '02' => Mage::helper('usa')->__('UPS Second Day Air'),
                    '03' => Mage::helper('usa')->__('UPS Ground'),
                    '07' => Mage::helper('usa')->__('UPS Worldwide Express'),
                    '08' => Mage::helper('usa')->__('UPS Worldwide Expedited'),
                    '11' => Mage::helper('usa')->__('UPS Standard'),
                    '12' => Mage::helper('usa')->__('UPS Three-Day Select'),
                    '13' => Mage::helper('usa')->__('UPS Next Day Air Saver'),
                    '14' => Mage::helper('usa')->__('UPS Next Day Air Early A.M.'),
                    '54' => Mage::helper('usa')->__('UPS Worldwide Express Plus'),
                    '59' => Mage::helper('usa')->__('UPS Second Day Air A.M.'),
                    '65' => Mage::helper('usa')->__('UPS Saver'),
                    '33' => Mage::helper('usa')->__('UPS Saturday Delivery'),
                ),

and under my method array

    'method'=>array(
        '1DM'    => Mage::helper('usa')->__('Next Day Air Early AM'),
        '1DML'   => Mage::helper('usa')->__('Next Day Air Early AM Letter'),
        '1DA'    => Mage::helper('usa')->__('Next Day Air'),
        '1DAL'   => Mage::helper('usa')->__('Next Day Air Letter'),
        '1DAPI'  => Mage::helper('usa')->__('Next Day Air Intra (Puerto Rico)'),
        '1DP'    => Mage::helper('usa')->__('Next Day Air Saver'),
        '1DPL'   => Mage::helper('usa')->__('Next Day Air Saver Letter'),
        '2DM'    => Mage::helper('usa')->__('2nd Day Air AM'),
        '2DML'   => Mage::helper('usa')->__('2nd Day Air AM Letter'),
        '2DA'    => Mage::helper('usa')->__('2nd Day Air'),
        '2DAL'   => Mage::helper('usa')->__('2nd Day Air Letter'),
        '3DS'    => Mage::helper('usa')->__('3 Day Select'),
        'GND'    => Mage::helper('usa')->__('Ground'),
        'GNDCOM' => Mage::helper('usa')->__('Ground Commercial'),
        'GNDRES' => Mage::helper('usa')->__('Ground Residential'),
        'STD'    => Mage::helper('usa')->__('Canada Standard'),
        'XPR'    => Mage::helper('usa')->__('Worldwide Express'),
        'WXS'    => Mage::helper('usa')->__('Worldwide Express Saver'),
        'XPRL'   => Mage::helper('usa')->__('Worldwide Express Letter'),
        'XDM'    => Mage::helper('usa')->__('Worldwide Express Plus'),
        'XDML'   => Mage::helper('usa')->__('Worldwide Express Plus Letter'),
        'XPD'    => Mage::helper('usa')->__('Worldwide Expedited'),
        'SAT'   => Mage::helper('usa')->__('Saturday Delivery'),
    ),
'containers_filter' => array(
                array(
                    'containers' => array('00'), // Customer Packaging
                    'filters'    => array(
                        'within_us' => array(
                            'method' => array(
                                '01', // Next Day Air
                                '13', // Next Day Air Saver
                                '12', // 3 Day Select
                                '59', // 2nd Day Air AM
                                '03', // Ground
                                '14', // Next Day Air Early AM
                                '02', // 2nd Day Air
                                '33', // Saturday Delivery
                            )
                        ),
                        'from_us' => array(
                            'method' => array(
                                '07', // Worldwide Express
                                '54', // Worldwide Express Plus
                                '08', // Worldwide Expedited
                                '65', // Worldwide Saver
                                '11', // Standard
                                '33', // Saturday Delivery
                            )
                        )
                    )
                ),

And I've enabled all options from my admin. Now in theory this should bring the saturday delivery on my frontend unless I'm using the wrong code for the Saturday delivery option. I'm not sure what I'm doing wrong here.

Thanks

1

There are 1 best solutions below

0
On

This is an old question, but still a relevant one who's solution isn't readily available in my experience.

The issue with the above code is that it is assuming that Saturday delivery is a rate from UPS. However in the UPS API documentation they state that it is instead a shipping option. If you add this shipping option to the API request it will return ALL of the rates in that request with Saturday delivery applied.

For that reason the solution to this issue in Magento is to make two requests to the UPS API - once for non-Saturday rates and once for Saturday rates.

I've put together a module to add this functionality that can be found here.

https://github.com/PromInc/Magento-1.x-UPS-Saturday-Delivery

But for the sake of ensuring we understand what is happening I'll explain the code here (using the Core files for an example - of course don't overwrite your core files!!!):

app/code/core/Mage/Shipping/Model/Shipping.php

Add a carrier to the carrier list - copying UPS.

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    ...

    $limitCarrier = $request->getLimitCarrier();
    if (!$limitCarrier) {
        $carriers = Mage::getStoreConfig('carriers', $storeId);

        /*
        For UPS Saturday Shipping, add an additional carrier that will have the saturday delivery option added in Shipping/Carrier/Ups.php
        Saturday delivery is an option in the API request and applies to ALL shipping rates in that result.
        So we make 2 requests to UPS - once for non-saturday and once for Saturday.
        NOTE: system configuration used for getting Admin configured options
        */
        if( Mage::getStoreConfig('shipping/saturday_delivery_ups/enabled') && in_array( date('w'), explode( ",", Mage::getStoreConfig('shipping/saturday_delivery_ups/days_enabled') ) ) ) {
            $carriers['upssaturday'] = $carriers['ups'];
        }

        foreach ($carriers as $carrierCode => $carrierConfig) {
            $this->collectCarrierRates($carrierCode, $request);
        }
    } else {
        ...
    }

    return $this;
}

Set the carrier code for the new carrier (upssaturday) to ups to ensure we load the right class and make the request to UPS.

Also set a variable to flag that this carrier has the Saturday delivery option enabled.

public function collectCarrierRates($carrierCode, $request)
{
    /* @var $carrier Mage_Shipping_Model_Carrier_Abstract */
    // $carrier = $this->getCarrierByCode($carrierCode, $request->getStoreId());
    $carrierCodeForLoad = $carrierCode;
    if( $carrierCode == 'upssaturday' ) {
        $carrierCodeForLoad = 'ups';
    }
    $carrier = $this->getCarrierByCode($carrierCodeForLoad, $request->getStoreId());

    if (!$carrier) {
        return $this;
    }

    // Tell the UPS request to set the Saturday delivery option
    if( $carrierCode == 'upssaturday' ) {
        $carrier->setSaturdayDelivery(true);
    }

    $carrier->setActiveFlag($this->_availabilityConfigField);
    ...
    return $this;
}

app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php

When parsing the XML response, modify the method code and display name to reflect that it is a Saturday delivery shipping method.

protected function _parseXmlResponse($xmlResponse)
{
    ...
    } else {
        if( $this->getSaturdayDelivery() ) {
            $saturdayShippingMethods = explode( ",", Mage::getStoreConfig('shipping/saturday_delivery_ups/allowed_methods') );
        }
        foreach ($priceArr as $method=>$price) {
            if( $this->getSaturdayDelivery() && !in_array( $method, $saturdayShippingMethods ) ) {
                continue;
            }

            $rate = Mage::getModel('shipping/rate_result_method');
            $rate->setCarrier('ups');
            $rate->setCarrierTitle($this->getConfigData('title'));
            // $rate->setMethod($method);
            $rate->setMethod( $method . ( $this->getSaturdayDelivery() ? '_sat' : '' ) );
            // $method_arr = $this->getShipmentByCode($method);  // string
            $method_arr = $this->getShipmentByCode($method) . ( $this->getSaturdayDelivery() ? ' Saturday' : '' );  // string
            $rate->setMethodTitle($method_arr);
            $rate->setCost($costArr[$method]);
            $rate->setPrice($price);

            $result->append($rate);
        }
    }
    return $result;
}

Add the Saturday delivery option to the XML request for obtaining quotes if enabled for this rate.

protected function _getXmlQuotes()
{
    ....
    if ($serviceCode !== null) {
        $xmlRequest .= "<Service>" .
            "<Code>{$serviceCode}</Code>" .
            "<Description>{$serviceDescription}</Description>" .
            "</Service>";
    }

if( $this->getSaturdayDelivery() ) {
  $xmlRequest .= <<< XMLRequest
<ShipmentServiceOptions>
    <SaturdayDelivery/>
</ShipmentServiceOptions>
XMLRequest;
}
  $xmlRequest .= <<< XMLRequest
  <Shipper>
XMLRequest;
    ...
}