2

I'd love to have two "Estimate Shipping and Tax" blocks:

  1. One to display domestic rates to a default address. This one would have no form and would be displayed at all times.
  2. The other to estimate international shipping would be just the standard form + rates.

I've got the layout and template part of it working, but I don't seem to be able to customize the functionality of checkout/cart_shipping block. I was planning on adding a method (setAddress) to set the default address to be use for calculation.

However, going through the code, the cart_shipping, quote and it's shipping_address objects appear to be all wired through and I see no easy way to create two Estimate Shipping blocks for two different addresses.

Any suggestions much appreciated.

4
  • "To a default address" - do you mean the customer's default shipping address, or an example address like your store?
    – philwinkle
    Feb 14 '13 at 4:48
  • I mean an admin-configured address not modifiable by frontend user (as opposed to the block #2). Default store address should do if it makes things easier.
    – Jan Tomka
    Feb 14 '13 at 5:39
  • I don't think pulling an actual shipping quote would be necessary, then. Why not create a static block that mimics the look of the shipping quote box with your rates prepopulated? If the store address won't change very frequently, neither will the rates you're intending to display.
    – philwinkle
    Feb 14 '13 at 15:03
  • Store address won't change, but shipping rates may, when you set up a couple of price rules (e.g. free shipping based on quote total). Anyway, I may end up doing just what you're suggesting, even though I was after something you can set and forget. Static block is not quite that.
    – Jan Tomka
    Feb 14 '13 at 22:28
2

As you've noticed, there's extensive coupling among the custom, address, quote, and shipping objects which hampers what you are trying to accomplish. However, if you dig into the carrier, rate_request and rate_result models, the architecture is pretty simple. You only need to know which methods apply to your default address, and you may need to also know order total, weight, and/or number of packages. Then you can construct the rate_request object which Magento expects; see Mage_Shipping_Model_Shipping::collectRatesByAddress():

public function collectRatesByAddress(Varien_Object $address, $limitCarrier = null)
{
    /** @var $request Mage_Shipping_Model_Rate_Request */
    $request = Mage::getModel('shipping/rate_request');
    $request->setAllItems($address->getAllItems());
    $request->setDestCountryId($address->getCountryId());
    $request->setDestRegionId($address->getRegionId());
    $request->setDestPostcode($address->getPostcode());
    $request->setPackageValue($address->getBaseSubtotal());
    $request->setPackageValueWithDiscount($address->getBaseSubtotalWithDiscount());
    $request->setPackageWeight($address->getWeight());
    $request->setFreeMethodWeight($address->getFreeMethodWeight());
    $request->setPackageQty($address->getItemQty());
    $request->setStoreId(Mage::app()->getStore()->getId());
    $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
    $request->setBaseCurrency(Mage::app()->getStore()->getBaseCurrency());
    $request->setPackageCurrency(Mage::app()->getStore()->getCurrentCurrency());
    $request->setLimitCarrier($limitCarrier);

    $request->setBaseSubtotalInclTax($address->getBaseSubtotalInclTax());

    return $this->collectRates($request);
}

I think that you can just handle this with a custom block type, and note that there is a result cache which should be honored. Various factors for your instance can affect the complexity of this customization (currencies, multiple carriers, complex shipment pricing, etc).

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.