Skip to content

Commit

Permalink
Merge pull request #33 from contardi/master
Browse files Browse the repository at this point in the history
fix: error notifying customer when receive a webhook
  • Loading branch information
fgmarchione authored Apr 11, 2024
2 parents e8a96b6 + 5a6783f commit 2295a94
Show file tree
Hide file tree
Showing 22 changed files with 144 additions and 143 deletions.
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Bug Report
about: Describe a problem or defect you found in the module
title: "[SUMMARY OF THE BUG]"
labels: bug
assignees: ''

---

**Description**
A clear and concise description of what the bug is.

**Steps to Reproduce**
1. ...
2. ...
3. ...

**Expected Behavior**
Describe what you expected to happen.

**Actual Behavior**
Describe what actually happened.

**Environment**
* Magento Version:
* PHP Version:
* Operating System:
* Browser (if applicable):
* Module Version:
* Other Relevant Extensions:

**Additional Context**
Add any other context or screenshots about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature Request
about: Suggest a new idea for the module
title: "[SUMMARY OF THE FEATURE]"
labels: enhancement
assignees: ''

---

**Description**
A clear and concise description of the proposed feature.

**Use Case**
Explain why this feature would be valuable and how it would be used.

**Potential Solution (Optional)**
If you have any ideas on how to implement this feature, describe them here.

**Additional Context**
Add any other context or screenshots about the feature request here.
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**Title:**

**Description:**
* Provide a clear and concise description of the changes being made.
* Explain the reasons behind these changes.

**Checklist:**
- [ ] Changes are consistent with the project's coding style.
- [ ] Documentation (if applicable) has been updated.
- [ ] Link to related issue (if applicable):

**Testing Instructions:**
* Instructions for reviewers on how to test the changes
17 changes: 0 additions & 17 deletions Api/Data/InvoiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@ interface InvoiceInterface
const PRODUCTS_VALUE = 'products_value';
const CFOP = 'cfop';

/**
* Get item id
*
* @return int|null
* @api
*/
public function getEntityId();

/**
* Set item id
*
* @param int $id
* @return void
* @api
*/
public function setEntityId($id);

/**
* Get invoice number
*
Expand Down
17 changes: 0 additions & 17 deletions Api/Data/LabelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ interface LabelInterface

const UPDATED_AT = 'updated_at';

/**
* Get item id
*
* @return int|null
* @api
*/
public function getEntityId();

/**
* Set item id
*
* @param int $id
* @return void
* @api
*/
public function setEntityId($id);

/**
* Get invoice number
*
Expand Down
8 changes: 4 additions & 4 deletions Block/Adminhtml/Order/View/Tab/Intelipost.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ public function getWebhooksBlock()
{
return $this->getLayout()->createBlock(
\Intelipost\Shipping\Block\Adminhtml\Order\View\Tab\Intelipost\Webhooks::class
)->setOrder($this->getOrder())
->setOrderId($this->getOrderId())
)->setData('order', $this->getOrder())
->setData('order_id', $this->getOrderId())
->toHtml();
}

Expand All @@ -177,8 +177,8 @@ public function getLabelsBlock()
{
return $this->getLayout()->createBlock(
\Intelipost\Shipping\Block\Adminhtml\Order\View\Tab\Intelipost\Labels::class
)->setOrder($this->getOrder())
->setOrderId($this->getOrderId())
)->setData('order', $this->getOrder())
->setData('order_id', $this->getOrderId())
->toHtml();
}

Expand Down
10 changes: 6 additions & 4 deletions Block/Adminhtml/Order/View/Tab/Intelipost/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use Intelipost\Shipping\Model\ResourceModel\Label\CollectionFactory as LabelCollectionFactory;
use Intelipost\Shipping\Model\ResourceModel\ShipmentRepository;
use Intelipost\Shipping\Model\ShipmentFactory;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;

Expand Down Expand Up @@ -57,11 +56,11 @@ public function __construct(
}

/**
* @return \Intelipost\Shipping\Model\ResourceModel\Label\Collection
* @return bool
*/
public function hasOrderCreated()
{
$shipment = $this->shipmentRepository->getByOrderIncrementId($this->getOrder()->getIncrementId());
$shipment = $this->shipmentRepository->getByOrderIncrementId($this->getData('order')->getIncrementId());
return $shipment->getId() ? true : false;
}

Expand All @@ -71,7 +70,10 @@ public function hasOrderCreated()
public function getLabelsCollection()
{
$collection = $this->labelsCollectionFactory->create();
$collection->addFieldToFilter('order_increment_id', ['like' => '%' . $this->getOrder()->getIncrementId() . '%']);
$collection->addFieldToFilter(
'order_increment_id',
['like' => '%' . $this->getData('order')->getIncrementId() . '%']
);
return $collection;
}
}
2 changes: 1 addition & 1 deletion Block/Adminhtml/Order/View/Tab/Intelipost/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
public function getWebhooksCollection()
{
$collection = $this->webhookCollectionFactory->create();
$collection->addFieldToFilter('order_increment_id', $this->getOrder()->getIncrementId());
$collection->addFieldToFilter('order_increment_id', $this->getData('order')->getIncrementId());
return $collection;
}
}
8 changes: 7 additions & 1 deletion Client/ShipmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function sendShipmentRequest($requestBody, $shipment)
if ($responseStatus == Intelipost::RESPONSE_STATUS_OK) {
$trackingCode = '';
$trackingUrl = $result['content']['tracking_url'];
$volume = [];
if (isset($result['content']['shipment_order_volume_array'])) {
$trackingCodes = [];
foreach ($result['content']['shipment_order_volume_array'] as $volume) {
Expand All @@ -222,7 +223,12 @@ public function sendShipmentRequest($requestBody, $shipment)
$trackingCode = implode(', ', $trackingCodes);
}

$this->requestLabel->importPrintingLabels($intelipostShipmentId, $volume['shipment_order_volume_number']);
if (isset($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
2 changes: 1 addition & 1 deletion Controller/Product/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function execute()
}

$resultPage = $this->resultPageFactory->create();
$this->getResponse()->setBody(
return $this->getResponse()->setBody(
$resultPage->getLayout()
->createBlock(\Magento\Framework\View\Element\Template::class)
->setCacheLifetime(false)
Expand Down
26 changes: 7 additions & 19 deletions Controller/Schedule/Index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Intelipost\Shipping
* @copyright Copyright (c) 2021 Intelipost
Expand All @@ -23,31 +24,18 @@ class Index extends \Magento\Framework\App\Action\Action
/** @var \Intelipost\Shipping\Helper\Data */
protected $helper;

/** @var \Intelipost\Shipping\Model\QuoteFactory */
protected $shippingFactory;

/** @var \Magento\Checkout\Model\Session */
protected $checkoutSession;

/** @var \Magento\Framework\View\Result\PageFactory */
protected $resultPageFactory;

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Intelipost\Shipping\Helper\Data $helper
* @param \Intelipost\Shipping\Model\QuoteFactory $quoteFactory
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
* @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Intelipost\Shipping\Helper\Data $helper,
\Intelipost\Shipping\Model\QuoteFactory $quoteFactory,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Intelipost\Shipping\Helper\Data $helper,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
) {
$this->helper = $helper;
Expand Down Expand Up @@ -116,7 +104,7 @@ public function execute()
$metadata
);

$this->getResponse()->setBody(
return $this->getResponse()->setBody(
__('Delivery Scheduled for: %1 period: %2', $selDate, __(ucfirst($period)))
);
}
Expand Down
5 changes: 4 additions & 1 deletion Controller/Schedule/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ public function execute()
$item->setSelectedSchedulingPeriod($period);
}

$this->getResponse()->setBody(
return $this->getResponse()->setBody(
__('Delivery Scheduled for: %1 period: %2', $selDate, __(ucfirst($period)))
);
}
}
}

//Response empty body
return $this->getResponse()->setBody('');
}
}
15 changes: 15 additions & 0 deletions Controller/Webhook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ protected function updateOrderStatus($orderIncrementId, $requestBody)
(in_array($state, $preDispatchEvents) && $trackPreShip)
|| (in_array($state, $postDispatchEvents))
) {
$status = '';
switch (strtoupper($state)) {
case 'NEW':
$status = $this->helper->getConfig('status_created');
Expand All @@ -197,10 +198,24 @@ protected function updateOrderStatus($orderIncrementId, $requestBody)

case 'IN_TRANSIT':
$status = $this->helper->getConfig('status_in_transit');
if ($status) {
$order = $this->helper->loadOrder($orderIncrementId);
if ($order->canShip()) {
$trackingUrl = $requestBody['tracking_url'] ?? null;
$this->createShipment($orderIncrementId, $trackingUrl);
}
}
break;

case 'TO_BE_DELIVERED':
$status = $this->helper->getConfig('status_to_be_delivered');
if ($status) {
$order = $this->helper->loadOrder($orderIncrementId);
if ($order->canShip()) {
$trackingUrl = $requestBody['tracking_url'] ?? null;
$this->createShipment($orderIncrementId, $trackingUrl);
}
}
break;

case 'DELIVERED':
Expand Down
Loading

0 comments on commit 2295a94

Please sign in to comment.