diff --git a/Api/Data/InvoiceInterface.php b/Api/Data/InvoiceInterface.php index 2e039b2..c963157 100644 --- a/Api/Data/InvoiceInterface.php +++ b/Api/Data/InvoiceInterface.php @@ -16,6 +16,8 @@ interface InvoiceInterface const ENTITY_ID = 'entity_id'; const NUMBER = 'number'; const ORDER_INCREMENT_ID = 'order_increment_id'; + + const INTELIPOST_SHIPMENT_ID = 'intelipost_shipment_id'; const SERIES = 'series'; const KEY = 'key'; const DATE = 'date'; diff --git a/Api/Data/ShipmentInterface.php b/Api/Data/ShipmentInterface.php index f6dae7d..e35aa3d 100644 --- a/Api/Data/ShipmentInterface.php +++ b/Api/Data/ShipmentInterface.php @@ -31,6 +31,8 @@ interface ShipmentInterface const TRACKING_URL = 'tracking_url'; const INTELIPOST_MESSAGE = 'intelipost_message'; const PRODUCTS_IDS = 'products_ids'; + + const ORIGIN_ZIP_CODE = 'origin_zip_code'; const DELIVERY_ESTIMATE_DATE_EXACT_ISO = 'delivery_estimate_date_exact_iso'; const SELECTED_SCHEDULING_DATE = 'selected_scheduling_date'; const CREATED_AT = 'created_at'; @@ -278,6 +280,17 @@ public function getProductsIds(); */ public function setProductsIds($productsIds); + /** + * @return string + */ + public function getOriginZipCode(); + + /** + * @param $originZipCode + * @return void + */ + public function setOriginZipCode($originZipCode); + /** * @return string */ diff --git a/Block/Adminhtml/Order/View/Tab/Intelipost/Labels.php b/Block/Adminhtml/Order/View/Tab/Intelipost/Labels.php index 246e3bc..ccd485f 100644 --- a/Block/Adminhtml/Order/View/Tab/Intelipost/Labels.php +++ b/Block/Adminhtml/Order/View/Tab/Intelipost/Labels.php @@ -71,7 +71,7 @@ public function hasOrderCreated() public function getLabelsCollection() { $collection = $this->labelsCollectionFactory->create(); - $collection->addFieldToFilter('order_increment_id', $this->getOrder()->getIncrementId()); + $collection->addFieldToFilter('order_increment_id', ['like' => '%' . $this->getOrder()->getIncrementId() . '%']); return $collection; } } diff --git a/Client/ShipmentOrder.php b/Client/ShipmentOrder.php index 9664bb2..4e1377b 100644 --- a/Client/ShipmentOrder.php +++ b/Client/ShipmentOrder.php @@ -137,6 +137,7 @@ public function getShipment($shipment) $body = new \stdClass(); $body->order_number = $shipment->getData('intelipost_shipment_id') ?: $shipment->getData('order_increment_id'); + $body->origin_zip_code = $shipment->getData('origin_zip_code'); $body->quote_id = $shipment->getData('quote_id'); $body->sales_order_number = $shipment->getData('increment_id'); $body->delivery_method_id = $shipment->getData('delivery_method_id'); @@ -162,7 +163,9 @@ public function getShipment($shipment) */ public function getVolumes($shipment) { - $volume = $this->shipmentInvoice->getInformation($shipment->getData('order_increment_id')); + $incrementId = $shipment->getData('intelipost_shipment_id') + ?: $shipment->getData('order_increment_id'); + $volume = $this->shipmentInvoice->getInformation($incrementId); return $this->shipmentVolume->getInformation( $shipment->getData('volumes'), $volume @@ -179,6 +182,8 @@ public function sendShipmentRequest($requestBody, $shipment) $trackingCode = null; $trackingUrl = null; $incrementId = $shipment->getData('order_increment_id'); + $intelipostShipmentId = $shipment->getData('intelipost_shipment_id') + ?: $shipment->getData('order_increment_id');; $response = $this->helperApi->apiRequest('POST', 'shipment_order', $requestBody); $result = $this->helper->unserializeData($response); @@ -217,7 +222,7 @@ public function sendShipmentRequest($requestBody, $shipment) $trackingCode = implode(', ', $trackingCodes); } - $this->requestLabel->importPrintingLabels($incrementId, $volume['shipment_order_volume_number']); + $this->requestLabel->importPrintingLabels($intelipostShipmentId, $volume['shipment_order_volume_number']); } $status = $this->helper->getConfig('created_status', 'order_status', 'intelipost_push'); diff --git a/Client/ShipmentOrder/Invoice.php b/Client/ShipmentOrder/Invoice.php index 0158e0e..6723a59 100644 --- a/Client/ShipmentOrder/Invoice.php +++ b/Client/ShipmentOrder/Invoice.php @@ -9,27 +9,36 @@ namespace Intelipost\Shipping\Client\ShipmentOrder; use Intelipost\Shipping\Model\ResourceModel\Invoice\CollectionFactory; +use Intelipost\Shipping\Helper\Data; class Invoice { + + /** @var Data */ + protected $helper; + /** @var CollectionFactory */ protected $collectionFactory; /** * @param CollectionFactory $collectionFactory + * @param Data $helper */ - public function __construct(CollectionFactory $collectionFactory) - { + public function __construct( + CollectionFactory $collectionFactory, + Data $helper + ) { $this->collectionFactory = $collectionFactory; + $this->helper = $helper; } /** - * @param $orderNumber + * @param $intelipostNumber * @return \stdClass */ - public function getInformation($orderNumber) + public function getInformation($intelipostNumber) { - $invoiceCollection = $this->getInvoiceCollection($orderNumber); + $invoiceCollection = $this->getInvoiceCollection($intelipostNumber); $invoiceObj = new \stdClass(); foreach ($invoiceCollection as $invoice) { $invoiceDate = $invoice->getData('date'); @@ -47,13 +56,19 @@ public function getInformation($orderNumber) } /** - * @param $orderNumber + * @param $intelipostNumber * @return \Intelipost\Shipping\Model\ResourceModel\Invoice\Collection */ - public function getInvoiceCollection($orderNumber) + public function getInvoiceCollection($intelipostNumber) { + $byShipment = (boolean) $this->helper->getConfig('order_by_shipment', 'order_status', 'intelipost_push'); + $collection = $this->collectionFactory->create(); - $collection->addFieldToFilter('order_increment_id', $orderNumber); + if ($byShipment) { + $collection->addFieldToFilter('intelipost_shipment_id', $intelipostNumber); + } else { + $collection->addFieldToFilter('order_increment_id', $intelipostNumber); + } return $collection; } } diff --git a/Cron/ImportLabels.php b/Cron/ImportLabels.php index 72bc0d6..b8deae7 100644 --- a/Cron/ImportLabels.php +++ b/Cron/ImportLabels.php @@ -80,7 +80,9 @@ public function execute() foreach ($collection as $order) { try { - $incrementId = $order->getData('increment_id'); + $incrementId = $order->getData('intelipost_shipment_id') + ?: $order->getData('increment_id'); + $volumes = $this->requestLabel->getVolumes($incrementId); if (!empty($volumes)) { foreach ($volumes as $volume) { diff --git a/Model/Invoice.php b/Model/Invoice.php index b8c34bb..c581c22 100644 --- a/Model/Invoice.php +++ b/Model/Invoice.php @@ -79,6 +79,22 @@ public function getOrderIncrementId() return $this->getData(self::ORDER_INCREMENT_ID); } + /** + * @inheritDoc + */ + public function setIntelipostShipmentId($intelipostNumber) + { + $this->setData(self::INTELIPOST_SHIPMENT_ID, $intelipostNumber); + } + + /** + * @inheritDoc + */ + public function getIntelipostShipmentId() + { + return $this->getData(self::INTELIPOST_SHIPMENT_ID); + } + /** * @inheritDoc */ diff --git a/Model/ResourceModel/InvoiceRepository.php b/Model/ResourceModel/InvoiceRepository.php index e6d04ed..204d9b1 100644 --- a/Model/ResourceModel/InvoiceRepository.php +++ b/Model/ResourceModel/InvoiceRepository.php @@ -86,13 +86,18 @@ public function save( */ public function saveInvoices($invoices) { + foreach ($invoices as $nfe) { + $orderNumber = explode('-', $nfe->getOrderIncrementId()); + $orderNumber = $orderNumber[0]; + /** @var \Intelipost\Shipping\Model\Invoice $invoice */ $invoice = $this->invoiceFactory->create(); $invoice->setId($nfe->getId()); - $invoice->setOrderIncrementId($nfe->getOrderIncrementId()); + $invoice->setOrderIncrementId($orderNumber); + $invoice->setIntelipostShipmentId($nfe->getOrderIncrementId()); $invoice->setSeries($nfe->getSeries()); $invoice->setNumber($nfe->getNumber()); $invoice->setKey($nfe->getKey()); diff --git a/Model/Shipment.php b/Model/Shipment.php index 610afad..ed982bd 100644 --- a/Model/Shipment.php +++ b/Model/Shipment.php @@ -378,6 +378,22 @@ public function setProductsIds($productsIds) $this->setData(self::PRODUCTS_IDS, $productsIds); } + /** + * @inheritDoc + */ + public function getOriginZipCode() + { + return $this->getData(self::ORIGIN_ZIP_CODE); + } + + /** + * @inheritDoc + */ + public function setOriginZipCode($originZipCode) + { + $this->setData(self::ORIGIN_ZIP_CODE, $originZipCode); + } + /** * @inheritDoc */ diff --git a/composer.json b/composer.json index 529637f..4b29fe5 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "intelipost/magento2", "description": "Intelipost Shipping", "type": "magento2-module", - "version": "2.6.1", + "version": "2.6.2", "require": { "guzzlehttp/guzzle": ">=6.3.3" }, diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 1172280..e747f49 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -12,7 +12,7 @@
- In order to use our module, you need Intelipost Credentials and a valid Intelipost account + In order to use our module, you need Intelipost Credentials and a valid Intelipost account (Version 2.6.2) diff --git a/etc/db_schema.xml b/etc/db_schema.xml index 7b939f8..8963f9b 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -54,6 +54,7 @@ + @@ -72,6 +73,9 @@ + + + @@ -100,6 +104,7 @@ + @@ -110,6 +115,9 @@ + + +
diff --git a/etc/module.xml b/etc/module.xml index efa06a3..426e992 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -7,7 +7,7 @@ */ --> - +