本文整理汇总了PHP中Magento\Framework\Event\Observer::getMerchantOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Observer::getMerchantOrder方法的具体用法?PHP Observer::getMerchantOrder怎么用?PHP Observer::getMerchantOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Event\Observer
的用法示例。
在下文中一共展示了Observer::getMerchantOrder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param \Magento\Framework\Event\Observer $observer
*
* @throws \Exception
* @throws bool
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$merchantOrder = $observer->getMerchantOrder();
if (!count($merchantOrder['shipments']) > 0) {
return;
}
$data = $observer->getPayment();
$order = $this->_coreModel->_getOrder($data["external_reference"]);
//if order has shipments, status is updated. If it doesn't the shipment is created.
if ($merchantOrder['shipments'][0]['status'] == 'ready_to_ship') {
if ($order->hasShipments()) {
$shipment = $this->_shipment->load($order->getId(), 'order_id');
} else {
$shipment = $this->_shipmentFactory->create($order);
$order->setIsInProcess(true);
}
$shipment->setShippingLabel($merchantOrder['shipments'][0]['id']);
$shipmentInfo = $this->_shipmentHelper->getShipmentInfo($merchantOrder['shipments'][0]['id']);
$this->_coreHelper->log("Shipment Info", 'mercadopago-notification.log', $shipmentInfo);
$serviceInfo = $this->_shipmentHelper->getServiceInfo($merchantOrder['shipments'][0]['service_id'], $merchantOrder['site_id']);
$this->_coreHelper->log("Service Info by service id", 'mercadopago-notification.log', $serviceInfo);
if ($shipmentInfo && isset($shipmentInfo->tracking_number)) {
$tracking['number'] = $shipmentInfo->tracking_number;
$tracking['description'] = str_replace('#{trackingNumber}', $shipmentInfo->tracking_number, $serviceInfo->tracking_url);
$tracking['title'] = self::CODE;
$existingTracking = $this->_trackFactory->create()->load($shipment->getOrderId(), 'order_id');
if ($existingTracking->getId()) {
$track = $shipment->getTrackById($existingTracking->getId());
$track->setNumber($tracking['number'])->setDescription($tracking['description'])->setTitle($tracking['title'])->save();
} else {
$track = $this->_trackFactory->create()->addData($tracking);
$track->setCarrierCode(\MercadoPago\MercadoEnvios\Model\Carrier\MercadoEnvios::CODE);
$shipment->addTrack($track);
$shipment->save();
}
$this->_coreHelper->log("Track added", 'mercadopago-notification.log', $track);
}
$this->_transaction->addObject($order)->save();
}
}