Skip to content

Commit

Permalink
Merge pull request #29 from contardi/master
Browse files Browse the repository at this point in the history
fix: order shipment id to shipments table
  • Loading branch information
nicolasmafraintelipost authored May 19, 2023
2 parents fcc9f6a + fbc59ba commit 13b11c6
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Api/Data/InvoiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
13 changes: 13 additions & 0 deletions Api/Data/ShipmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Order/View/Tab/Intelipost/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
9 changes: 7 additions & 2 deletions Client/ShipmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
31 changes: 23 additions & 8 deletions Client/ShipmentOrder/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
}
4 changes: 3 additions & 1 deletion Cron/ImportLabels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions Model/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
7 changes: 6 additions & 1 deletion Model/ResourceModel/InvoiceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions Model/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<section id="carriers">
<group id="intelipost_settings" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label comment">
<label>Intelipost</label>
<comment>In order to use our module, you need Intelipost Credentials and a valid Intelipost account</comment>
<comment>In order to use our module, you need Intelipost Credentials and a valid Intelipost account (Version 2.6.2)</comment>
<include path="Intelipost_Shipping::system/general.xml"/>
<include path="Intelipost_Shipping::system/quote.xml"/>
<include path="Intelipost_Shipping::system/push.xml"/>
Expand Down
8 changes: 8 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<table name="intelipost_invoices" resource="default" engine="innodb" comment="Intelipost Invoice">
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment="ID"/>
<column xsi:type="varchar" name="order_increment_id" length="255" nullable="false" comment="Order Number"/>
<column xsi:type="varchar" name="intelipost_shipment_id" length="255" nullable="false" comment="Intelipost Shipment Id"/>
<column xsi:type="varchar" name="number" length="255" nullable="false" comment="Invoice Number"/>
<column xsi:type="varchar" name="series" length="255" nullable="false" comment="Order Series"/>
<column xsi:type="varchar" name="key" length="255" nullable="false" comment="Invoice Key"/>
Expand All @@ -72,6 +73,9 @@
<index referenceId="INTELIPOST_INVOICE_ORDER_INCREMENT_ID" indexType="btree">
<column name="order_increment_id"/>
</index>
<index referenceId="INTELIPOST_INVOICE_INTELIPOST_SHIPMENT_ID" indexType="btree">
<column name="intelipost_shipment_id"/>
</index>
<index referenceId="INTELIPOST_INVOICE_KEY" indexType="btree">
<column name="key"/>
</index>
Expand Down Expand Up @@ -100,6 +104,7 @@
<column xsi:type="varchar" name="tracking_url" length="255" comment="Tracking Url" />
<column xsi:type="text" name="intelipost_message" comment="Intelipost Message" />
<column xsi:type="varchar" name="products_ids" length="255" comment="Products Ids" />
<column xsi:type="varchar" name="origin_zip_code" length="255" comment="Origin Zip Code" />
<column xsi:type="timestamp" name="delivery_estimate_date_exact_iso" comment="Delivery Estimate Date Exact" />
<column xsi:type="timestamp" name="selected_scheduling_date" comment="Selected Scheduling Date" />
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="false" comment="Created Datetime"/>
Expand All @@ -110,6 +115,9 @@
<index referenceId="INTELIPOST_SHIPMENT_ORDER_INCREMENT_ID" indexType="btree">
<column name="order_increment_id"/>
</index>
<index referenceId="INTELIPOST_SHIPMENT_INTELIPOST_SHIPMENT_ID" indexType="btree">
<column name="intelipost_shipment_id"/>
</index>
</table>

<table name="intelipost_webhooks" resource="default" engine="innodb" comment="Intelipost Webhooks">
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
-->
<config>
<module name="Intelipost_Shipping" setup_version="2.6.1">
<module name="Intelipost_Shipping" setup_version="2.6.2">
<sequence>
<module name="Magento_Quote"/>
</sequence>
Expand Down

0 comments on commit 13b11c6

Please sign in to comment.