Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

how to update an order with tracking number programatically?

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 11-14-2018, 06:51 AM
 
ira@mdycommunications.com ira@mdycommunications.com is offline
 

Newbie
  
Join Date: Nov 2018
Posts: 1
 

Default how to update an order with tracking number programatically?

we are trying to update the orders with tracking number programmatically.




here is the order that we are using
update shipping method
update tracking number
change shippingstatus


pls see code below


after we run this code - order updating sucessfully - but the shipping email we get do not have a linkg to track the order.
the email has only tracking number with no link.


Can someone help us to do it properly so we gwt a notification email with tracking link
what is the order of events we have to follow
is there a specific property that we have to update ?
any specific API that should be used?
in what conditions the tracking link gets into the email?

// -------------------------------------------------------------
// UPDATE SHIPPING ID/ METHOD ID TO ORDER
$model = \XLite\Core\Database::getRepo('XLite\Model\Shippin g\Method');
$qb = $model->createQueryBuilder();
$qb
->select('m.method_id')
->andWhere('translations.name = :name')
->andWhere('m.processor = :processor')
->setParameter('name', $carrier_subcode)
->setParameter('processor', $carrier_code);

$methodId = $qb->getSingleScalarResult();
if ($methodId) :
$this->_print($orderId . ': Shipping method id found ' . $methodId);
$order->setLastShippingId($methodId);
$order->setShippingId($methodId);
$order->setShippingMethodName($carrier_subcode);
else :
$this->_print($orderId . ': Shipping method Id not found from carrier subcode: ' . $carrier_code);
endif;
\XLite\Core\Database::getEM()->persist($order);
// ================================================== ===========

// -----------------------------------------------------------------
// UPDATE TRACKING NUMBER
// ================================================== ===============
//var_dump($new_tracking_number);
$order = $orderModel->findOneByOrderNumber($orderId); // findOneByOrderNumber
foreach ($order->getTrackingNumbers() as $number) {
//var_dump($number->getValue());
if ($new_tracking_number === $number->getValue()) {
$trackingObject = $number;
$this->_print($orderId . ': tracking number ' . $new_tracking_number . ' exists.');
break;
}
}

if ($trackingObject) :
//$trackingObject->setTrackingId($new_tracking_number);
$trackingObject->setValue($new_tracking_number);
$this->_print($orderId . ': setting up tracking number ' . $new_tracking_number);
\XLite\Core\Database::getEM()->persist($trackingObject);
else :
$trackingObject = new XLite\Model\OrderTrackingNumber();
$trackingObject->setValue($new_tracking_number);
$trackingObject->setOrder($order);

$this->_print($orderId . ': new tracking number ' . $new_tracking_number . '');
\XLite\Core\Database::getEM()->persist($trackingObject);
$this->_print($orderId . ': saved');

$order->addTrackingNumbers($trackingObject);
\XLite\Core\Database::getEM()->persist($order);
$this->_print($orderId . ': saved new tracking to order');
endif;

// -----------------------------------------------------------------
// UPDATE SHIPPING STATUS
// ================================================== ===============
$order = $orderModel->findOneByOrderNumber($orderId); // findOneByOrderNumber
$order->setShippingStatus(\XLite\Model\Order\Status\Shipp ing::STATUS_SHIPPED);
$this->_print($orderId . ': shipping status is set to shipped');
\XLite\Core\Database::getEM()->persist($order);

//\XLite\Core\Database::getEM()->persist($order);
//\XLite\Core\Database::getEM()->persist($trackingObject);
\XLite\Core\Database::getEM()->flush();


$this->_print($orderId . ': imported ');
$this->xmllog->log($orderId, "success", "");

/* } catch (Exception $ex) {
$this->_print($ex->getMessage());
$this->xmllog->log($orderNumber, "error", $ex->getMessage());
//continue;
} */

unset($order);
} //Next order to process for tracking..

//\XLite\Core\Database::getEM()->flush();
//\XLite\Core\Database::getEM()->clear();
}
__________________
ira
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:20 AM.

   

 
X-Cart forums © 2001-2020