2

How can I more quickly test different shipping scenarios?

I have a client that is asking for some changes to some [already] very complex shipping logic. We are using a module to "override" the shipping methods' availability and price.

I have been testing each weight class manually, by adjusting the quantity of a product to get my cart to have a specific total weight.

In theory, I should be able to make a utility that shows me each outcome on a single page, but so far all my attempts have failed.

I have already tried to:

  1. Set the weight on a pre-existing quote object, then collect the rates.

    $address = $quote->getShippingAddress();
    $address->setWeight($my_custom_weight)->collectShippingRates();
    

    This does not work because collectShippingRates re-collects the product weights before actually summing everything up.

  2. I have also tried to create my own shipping/rate_request object, and call Mage::getModel('shipping/shipping')->collectRates($request);.

    This won't work for me because the override rules are applied by an overridden Mage_Sales_Model_Quote_Address_Rate class, which never gets called unless you request the rates through the address model.

  3. I have tried to programmatically modify my quote such that the product quantity gives me the desired weight (for example, I have a product that weighs 1lb, I want to "test" 10lb, so it sets the qty to 10, saves the quote, then requests the shipping rates.) This seems to work at first, but not when I try to do it 4 times in a row. Each subsequent request pulls the rates from the sales_flat_quote_shipping_rate table, showing the same rates as the first test.

  4. Last resort (haven't tried yet) is to create 4 separate carts/quotes, then loading the quote by ID to get the shipping options. I really don't like this solution because it isn't very reusable.

Background: To create the logic initially, I opened 3 browser windows (Firefox + Chrome + Incognito) in order to have 3 different carts (with 3 different weights.) This made it very easy to test and make sure that all 3 weight classes work as specified by the client. Previously there were 3 weight classes, but now there are 4, each with different available methods/pricing overrides/markups. Now that they have a 4th weight class, it seems like I should find a more efficient way of doing this.

Your Answer

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

Browse other questions tagged or ask your own question.