0

I need help please!

My client is working with a third party that updates programatically the status of orders with the SOAP API. When they do, Magento sends an email to inform customer that order has been shipped. Then they add the tracking number and nothing is sent to inform customer.

Their system uses the functions Create and addtrack in app/code/core/Mage/Sales/Model/Order/Shipment/Api.php

So I created a custom module to modify these functions. Unfortunately, nothing is happening. Customers just receive the shipment email without tracking number.

I've checked and my module devm2w_trackship is showing in Magento backend > system > configuration > advanced so i assume the declaration of the module is good. Edit-- here is my declaration in etc/modules/

<?xml version="1.0" ?>
<config>
    <modules>
        <devm2w_trackship>
            <active>true</active>
            <codePool>local</codePool>
        </devm2w_trackship>
    </modules>
</config>

Here is my config.xml in app/code/local/devm2w/trackship/

    <?xml version="1.0"?>
<config>
    <global>
        <models>
            <sales>
                <rewrite>
                    <order_shipment_api>devm2w_trackship_Model_Sales_Order_Shipment_Api</order_shipment_api>
                </rewrite>
            </sales>
        </models>
    </global>
</config>

And here is my Api.php file in Model/Sales

<?php

class devm2w_trackship_Model_Sales_Order_Shipment_Api extends Mage_Sales_Model_Order_Shipment_Api
{

     public function create($orderIncrementId, $itemsQty = array(), $comment = null, $email = false,
        $includeComment = false
    ) {
        $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);

        /**
          * Check order existing
          */
        if (!$order->getId()) {
             $this->_fault('order_not_exists');
        }

        /**
         * Check shipment create availability
         */
        if (!$order->canShip()) {
             $this->_fault('data_invalid', Mage::helper('sales')->__('Cannot do shipment for order.'));
        }

         /* @var $shipment Mage_Sales_Model_Order_Shipment */
        $shipment = $order->prepareShipment($itemsQty);
        if ($shipment) {
            $shipment->register();
            $shipment->addComment($comment, $email && $includeComment);
            if ($email) {
                $shipment->setEmailSent(true);
            }
            $shipment->getOrder()->setIsInProcess(true);
            try {
                $transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($shipment)
                    ->addObject($shipment->getOrder())
                    ->save();
               /* $shipment->sendEmail($email, ($includeComment ? $comment : '')); */
            } catch (Mage_Core_Exception $e) {
                $this->_fault('data_invalid', $e->getMessage());
            }
            return $shipment->getIncrementId();
        }
        return null;
    }

    /**
     * Add tracking number to order
     *
     * @param string $shipmentIncrementId
     * @param string $carrier
     * @param string $title
     * @param string $trackNumber
     * @return int
     */
    public function addTrack($shipmentIncrementId, $carrier, $title, $trackNumber)
    {
        $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId);

        /* @var $shipment Mage_Sales_Model_Order_Shipment */

        if (!$shipment->getId()) {
            $this->_fault('not_exists');
        }

        $carriers = $this->_getCarriers($shipment);

        if (!isset($carriers[$carrier])) {
            $this->_fault('data_invalid', Mage::helper('sales')->__('Invalid carrier specified.'));
        }

        $track = Mage::getModel('sales/order_shipment_track')
                    ->setNumber($trackNumber)
                    ->setCarrierCode($carrier)
                    ->setTitle($title);

        $shipment->addTrack($track);

        try { 
            $shipment->save(); 
            $track->save(); 
            $email=true; 
            $shipment->sendEmail($email,’’); 
        } catch (Mage_Core_Exception $e) { 
            $this->_fault(’data_invalid’, $e->getMessage()); 
        }
        return $track->getId();
    }


}

Please help,

thanks

1
  • I tried my code by copying it in the local folder and evrything works fine. do I have a conflict anywhere?
    – Antho Ny
    Mar 9, 2015 at 19:08

1 Answer 1

1

It sounds to me that you file in app/etc/modules/Your_Module.xml is pointing to the local codePool.

And beside that you have to use the MagentoFirstWordCasing so Magento bootstrap can load you models correctly.

Maybe you are developing on Windows, which is case insensitive and your production server is not.

References

1
  • Thanks Jeroen, I edited my question with my etc/modules file. Do you see anything weird? About First Case, I will try it, see if it changes anything.
    – Antho Ny
    Mar 12, 2015 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.