Magento - Cronjob outside magento to update shipme

2020-07-30 06:03发布

I am working on a script which is out of magento framework and will be programmed to get all shipments and tracking number.

After getting these shipments and tracking number i will check with shipping provider and update the status of shipment and order based on if its dispatched / scanned or delivered.

following is half done code and I am stuck,

<?php
    require_once 'app/Mage.php';
    Mage::app('default');

$myShipment=Mage::getModel('sales/order_shipment'); 
$shipment=Mage::getResourceModel('sales/order_shipment_collection')
    ->addAttributeToSelect('*');

$allIds=$shipment->getAllIds();
foreach($allIds as $thisId) {
    $myShipment->load($thisId)->getAllTrackings();
    echo "<pre>";
    print_r($myShipment);
    echo "</pre>";

}

Please help,

Thanks and Regards, Saurabh

标签: magento
2条回答
叛逆
2楼-- · 2020-07-30 06:12

You can set shipment status - there's a field for it that's set to NULL for me when you query via the shipment.list API

Here's a dump:

Array
(
    [0] => Array
        (
            [store_id] => 1
            [total_weight] => 
            [total_qty] => 1.0000
            [email_sent] => 1
            [order_id] => 3
            [customer_id] => 1
            [shipping_address_id] => 6
            [billing_address_id] => 5
            [shipment_status] => 
            [increment_id] => 100000001
            [created_at] => 2010-11-11 15:41:41
            [updated_at] => 2010-11-11 15:44:05
            [shipment_id] => 1
        )

It doesn't look like you can set it via the WS API, which means that you'll need to include mage.php in your external script and then update the shipment via magento (as silvo has shown above). Sorry, I don't have the syntax to hand but I suspect you would update based on the shipment ID as opposed to the order. This means that you will need to create a shipment first (again, this can be done via the webservices API via the shipment.create method (details on the same page as the prior link).

I hope this sets you on the right path. If anyone has any working code for doing this (which brought me to this post originally) PLEASE feel free to share. :)

查看更多
Deceive 欺骗
3楼-- · 2020-07-30 06:31

Once shipment and invoice are created for an order it is set to a status of "Complete". Not sure what you want to change there, but if you have some custom statuses set up in your magento installation you can use the setStatus() method of the order class.

$myShipment->getOrder()->setStatus("YourCustomStatus");

I don't think shipments have statuses, but you can add a comment to a shipment by calling addComment($comment, $notifyCustomer), where first variable is a string and second is bool.

$myShipment->addComment("01/01/2010 06:55, Out for delivery", true);

You can also add a comment to the order using a similar method:

$myShipment->getOrder()->addComment("01/01/2010 06:55, Out for delivery", true);
查看更多
登录 后发表回答