2

I've been searching for a solution to this. Basically what is happening here is each item in the inventory has it's own shipping price set.

When these items are added to a cart, the shipping is calculated and returned by the model shipping/carrier_flatrate, then added to an array.

I can't seem to find where this is totaled up. I've heard that the arrays can be sorted wrong in some cases, however, this seems to be a different situation causing this entirely. Any ideas are greatly appreciated.

I've been searching Google for days trying to make sense of this.

  • Can you give an example with numbers? It's kind of hard (at least for me) to understand. The 'Flat Fixed Per Item' shipping should be very simple. You set a cost for delivery for an item, the same price for all items (let's say 5$). If you have in cart 2 products, P1 with qty 2 and P2 with qty 4 the cost should be 2 * 5 + 4 * 5 = 30....or am I wrong? – Marius May 13 '13 at 16:29
  • The system has an odd setup,I haven't been able to figure out what the previous developers set up. Let me see if I can explain it better. Item 1 is set to have 5.98 Shipping, item 2 in the cart is 4.98 shipping, and item 3 is 29.98 shipping. The total shipping comes to 28.66. I'm not sure how it's getting these numbers. Each item in this inventory has it's own shipping price set. The shipping methods enabled in admin panel are Fixed (set to 5$, and seems to tie into the calculation somehow) and M2ePro shipping (disabled on frontend). Could these be conflicting? – DWils May 13 '13 at 22:43
  • Oh. I don't think I can help you much here and I doubt that anyone can without the looking at the code. From you question I understood that there is a problem with the default 'flat shipping', but it seams there is custom code involved. The flat shipping is supposed to work like I described in the comment above. Try disabling the extension that overrides this behavior and see if the error reproduces. – Marius May 14 '13 at 6:40
1

I believe you are looking for

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

Which looks like

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }

        $freeBoxes = 0;
        if ($request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {

                if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                    continue;
                }

                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
                            $freeBoxes += $item->getQty() * $child->getQty();
                        }
                    }
                } elseif ($item->getFreeShipping()) {
                    $freeBoxes += $item->getQty();
                }
            }
        }
        $this->setFreeBoxes($freeBoxes);

        $result = Mage::getModel('shipping/rate_result');
        if ($this->getConfigData('type') == 'O') { // per order
            $shippingPrice = $this->getConfigData('price');
        } elseif ($this->getConfigData('type') == 'I') { // per item
            $shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
        } else {
            $shippingPrice = false;
        }

        $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);

        if ($shippingPrice !== false) {
            $method = Mage::getModel('shipping/rate_result_method');

            $method->setCarrier('flatrate');
            $method->setCarrierTitle($this->getConfigData('title'));

            $method->setMethod('flatrate');
            $method->setMethodTitle($this->getConfigData('name'));

            if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
                $shippingPrice = '0.00';
            }


            $method->setPrice($shippingPrice);
            $method->setCost($shippingPrice);

            $result->append($method);
        }

        return $result;
    }

If there is custom code involved in calculating the shipping rates, I would look for a module that is rewriting the collectRates method, there is also a couple other events they could have hooked into to re-calculate the shipping costs, I would also look at the config.xml files of any custom modules that have been written.

Hope this helps

  • Thanks, this is exactly what I needed. I ran a grep in ssh and found the custom code written for this particular client. Looks like the previous dev wrote a switch case for shipping discounts. Thanks again! – DWils May 15 '13 at 19:32
  • Glad I could help =] – Jeffrey L. Roberts May 15 '13 at 20:31

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.