-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented PartnersSourceAdapter, IntegrationPartner *Implemented me…
…thod getOrderByMagento *Implemented method *Added Marketplace configs *Set v1.1.1 *Added partnersResource type
- Loading branch information
Returnless
committed
Jul 22, 2021
1 parent
8730806
commit c3428b5
Showing
8 changed files
with
287 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Returnless\Connector\Model\Config\Source; | ||
|
||
use Magento\Framework\Option\ArrayInterface; | ||
|
||
/** | ||
* Class IntegrationPartner | ||
* @package Returnless\Connector\Model\Config | ||
*/ | ||
class IntegrationPartner implements ArrayInterface | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
return | ||
[ | ||
[ | ||
'value' => 'vendiro', | ||
'label' => __('Vendiro') | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
namespace Returnless\Connector\Model; | ||
|
||
use Magento\Sales\Model\OrderRepository; | ||
use Magento\Framework\Api\SearchCriteriaBuilder;; | ||
use Returnless\Connector\Model\Config; | ||
use Psr\Log\LoggerInterface as Logger; | ||
|
||
/** | ||
* Class PartnersSourceAdapter | ||
* @package Returnless\Connector\Model | ||
*/ | ||
class PartnersSourceAdapter | ||
{ | ||
/** | ||
* @var array|mixed | ||
*/ | ||
private $partnersResource; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var OrderRepository | ||
*/ | ||
private $orderRepository; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var LoggerInterface | ||
* | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* PartnersSourceAdapter constructor. | ||
* @param OrderRepository $orderRepository | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param \Returnless\Connector\Model\Config $config | ||
* @param array $partnersResource | ||
*/ | ||
public function __construct( | ||
OrderRepository $orderRepository, | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
Config $config, | ||
Logger $logger, | ||
$partnersResource = [] | ||
) { | ||
$this->config = $config; | ||
$this->logger = $logger; | ||
$this->orderRepository = $orderRepository; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
$this->partnersResource = $partnersResource; | ||
} | ||
|
||
/** | ||
* @deprecated | ||
* | ||
* @param $orderId | ||
* @return \Magento\Framework\DataObject|mixed | ||
*/ | ||
public function getOrderById($orderId) | ||
{ | ||
$order = $this->getOrderByMagento($orderId); | ||
if (!$order->getId() && $this->config->getMarketplaceSearchEnabled()) { | ||
try { | ||
$order = $this->getOrderByMarketplace($orderId); | ||
} catch (\Throwable $e) { | ||
$this->logger->critical('Returnless Error PartnersSourceAdapter', ['exception' => $e]); | ||
} | ||
} | ||
|
||
return $order; | ||
} | ||
|
||
/** | ||
* @param $orderId | ||
* @return \Magento\Framework\DataObject|mixed | ||
*/ | ||
public function getOrderByMarketplace($orderId) | ||
{ | ||
$partnerId = $this->config->getMarketplaceSearchPartnerId(); | ||
$collection = $this->getPartnersCollectionModel($partnerId); | ||
$partnerOrder = $collection->addFieldToFilter( | ||
$this->partnersResource[$partnerId]['keyForSearch'], | ||
['eq' => $orderId] | ||
) | ||
->addFieldToSelect('order_id') | ||
->getFirstItem(); | ||
$order = $this->getOrderByMagento($partnerOrder->getOrderId(), 'entity_id'); | ||
|
||
return $order; | ||
} | ||
|
||
/** | ||
* @param $incrementId | ||
* @param string $searchKey | ||
* @return \Magento\Framework\DataObject | ||
*/ | ||
private function getOrderByMagento($incrementId, $searchKey = 'increment_id') | ||
{ | ||
$searchCriteria = $this->searchCriteriaBuilder | ||
->addFilter( | ||
$searchKey, | ||
$incrementId, | ||
'eq' | ||
) | ||
->create(); | ||
|
||
return $this->orderRepository->getList($searchCriteria)->getFirstItem(); | ||
} | ||
|
||
/** | ||
* @param $partnerId | ||
* @return false|mixed | ||
*/ | ||
private function getPartnersCollectionModel($partnerId) | ||
{ | ||
$result = false; | ||
if (!empty($this->partnersResource[$partnerId])) { | ||
$result = $this->partnersResource[$partnerId]['model']; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getIntegrationPartners() | ||
{ | ||
$result = []; | ||
if(!empty($this->partnersResource)) { | ||
foreach ($this->partnersResource as $partnerIntegrationCode => $value) { | ||
$result[] = [ | ||
'value' => $partnerIntegrationCode, | ||
'label' => __($value['label']) | ||
]; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
"OSL-3.0", | ||
"AFL-3.0" | ||
], | ||
"version": "1.1.0" | ||
"version": "1.1.1" | ||
} |
Oops, something went wrong.