-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
264 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\DataProvider\DB; | ||
|
||
/** | ||
* Snapshot Settings data provider | ||
*/ | ||
class SnapshotSettings | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
private $status = true; | ||
|
||
/** | ||
* Is enabled | ||
* | ||
* @return bool | ||
*/ | ||
public function isEnabled(): bool | ||
{ | ||
return $this->status; | ||
} | ||
|
||
/** | ||
* Set Enabled | ||
* | ||
* @param bool $status | ||
* | ||
* @return void | ||
*/ | ||
public function setEnabled(bool $status): void | ||
{ | ||
$this->status = $status; | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\Order; | ||
|
||
use Bloomreach\EngagementConnector\Model\ResourceModel\Order as OrderResource; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
|
||
/** | ||
* This class is responsible for loading orders by ID | ||
* - It stores only one order in the local cache, unlike the OrderRepository | ||
* - It only returns data from `sales_order` table | ||
*/ | ||
class OrderRepository | ||
{ | ||
/** | ||
* @var OrderResource | ||
*/ | ||
private $orderResource; | ||
|
||
/** | ||
* @var OrderInterface|null | ||
*/ | ||
private $cachedOrder; | ||
|
||
/** | ||
* @param OrderResource $orderResource | ||
*/ | ||
public function __construct(OrderResource $orderResource) | ||
{ | ||
$this->orderResource = $orderResource; | ||
} | ||
|
||
/** | ||
* Get Order by ID | ||
* | ||
* @param int $orderId | ||
* | ||
* @return OrderInterface | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function getById(int $orderId): OrderInterface | ||
{ | ||
if (($this->cachedOrder instanceof OrderInterface) && (int) $this->cachedOrder->getId() === $orderId) { | ||
return $this->cachedOrder; | ||
} | ||
|
||
$order = $this->orderResource->getById($orderId); | ||
|
||
if ($order->getId()) { | ||
$this->cachedOrder = $order; | ||
|
||
return $this->cachedOrder; | ||
} | ||
|
||
throw new NoSuchEntityException( | ||
__('The entity that was requested doesn\'t exist. Verify the entity and try again.') | ||
); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\ResourceModel; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Model\OrderFactory as OrderModelFactory; | ||
|
||
/** | ||
* This resource model is responsible for getting simplified order object | ||
*/ | ||
class Order | ||
{ | ||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resourceConnection; | ||
|
||
/** | ||
* @var OrderModelFactory | ||
*/ | ||
private $orderModelFactory; | ||
|
||
/** | ||
* @param ResourceConnection $resourceConnection | ||
* @param OrderModelFactory $orderModelFactory | ||
*/ | ||
public function __construct( | ||
ResourceConnection $resourceConnection, | ||
OrderModelFactory $orderModelFactory | ||
) { | ||
$this->resourceConnection = $resourceConnection; | ||
$this->orderModelFactory = $orderModelFactory; | ||
} | ||
|
||
/** | ||
* Get order by id | ||
* | ||
* @param int $orderId | ||
* | ||
* @return OrderInterface | ||
*/ | ||
public function getById(int $orderId): OrderInterface | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
$select = $connection->select()->reset()->from($connection->getTableName('sales_order')); | ||
$select->where('entity_id = ?', $orderId); | ||
$result = $connection->fetchRow($select); | ||
|
||
return $this->orderModelFactory->create(['data' => is_array($result) ? $result : []]); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
Plugin/Framework/Model/ResourceModel/Db/VersionControl/DisableSnapshot.php
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,59 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Plugin\Framework\Model\ResourceModel\Db\VersionControl; | ||
|
||
use Bloomreach\EngagementConnector\Api\Data\ExportQueueInterface; | ||
use Bloomreach\EngagementConnector\Api\Data\InitialExportStatusInterface; | ||
use Bloomreach\EngagementConnector\Model\DataProvider\DB\SnapshotSettings; | ||
use Magento\Framework\DataObject; | ||
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot as Subject; | ||
|
||
/** | ||
* This plugin is responsible for disabling db snapshot | ||
*/ | ||
class DisableSnapshot | ||
{ | ||
/** | ||
* @var SnapshotSettings | ||
*/ | ||
private $snapshotSettings; | ||
|
||
/** | ||
* @param SnapshotSettings $snapshotSettings | ||
*/ | ||
public function __construct(SnapshotSettings $snapshotSettings) | ||
{ | ||
$this->snapshotSettings = $snapshotSettings; | ||
} | ||
|
||
/** | ||
* Creates snapshot only if it is enabled | ||
* | ||
* Snapshot is disabled for all entities except: | ||
* - ExportQueue | ||
* - InitialExportStatus | ||
* | ||
* Snapshot is only disabled during preparing Export queue | ||
* | ||
* @param Subject $subject | ||
* @param callable $proceed | ||
* @param DataObject $entity | ||
* | ||
* @return void | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function aroundRegisterSnapshot(Subject $subject, callable $proceed, DataObject $entity) | ||
{ | ||
if ($this->snapshotSettings->isEnabled() | ||
|| ($entity instanceof ExportQueueInterface) | ||
|| ($entity instanceof InitialExportStatusInterface) | ||
) { | ||
$proceed($entity); | ||
} | ||
} | ||
} |
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