Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Api/Order/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function save(ChannableOrderData $entity): ChannableOrderData;
*
* @return int|bool
*/
public function getByChannableId(int $channableId);
public function getByChannableId(int $channableId, ?int $storeId = null);

/**
* @param array $orderData
Expand Down
6 changes: 3 additions & 3 deletions Model/Order/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function delete(DataModel $entity): bool
*/
public function createByDataArray(array $orderData, int $storeId): DataInterface
{
$channableOrderId = $this->getByChannableId((int)$orderData['channable_id']);
$channableOrderId = $this->getByChannableId((int)$orderData['channable_id'], $storeId);
if ($channableOrderId) {
$channableOrder = $this->get((int)$channableOrderId);
$channableOrder->setAttempts($channableOrder->getAttempts() + 1);
Expand All @@ -190,9 +190,9 @@ public function createByDataArray(array $orderData, int $storeId): DataInterface
/**
* {@inheritDoc}
*/
public function getByChannableId(int $channableId)
public function getByChannableId(int $channableId, ?int $storeId = null)
{
return $this->channableOrderResource->getByChannableId($channableId);
return $this->channableOrderResource->getByChannableId($channableId, $storeId);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion Model/Order/ResourceModel/ResourceModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ public function __construct(
* @param int $channableId
* @return bool
*/
public function getByChannableId($channableId)
public function getByChannableId($channableId, ?int $storeId = null)
{
$connection = $this->getConnection();
$select = $connection->select()
->from($this->getTable('channable_orders'), self::ID_FIELD_NAME)
->where('channable_id = :channable_id');
$bind = [':channable_id' => $channableId];

if ($storeId !== null) {
$select->where('store_id = :store_id');
$bind[':store_id'] = $storeId;
}

return $connection->fetchOne($select, $bind);
}

Expand Down
11 changes: 7 additions & 4 deletions Service/Order/Process/GetCustomIncrementId.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function execute(array $orderData, StoreInterface $store): ?string
$channelId = $orderData['channel_id'];
$prefix = $this->configProvider->getOrderIdPrefix((int)$store->getId());
if ($this->configProvider->stripChannelId((int)$store->getId())) {
$newIncrementId = $prefix . preg_replace('/[^a-zA-Z0-9]+/', '', $channelId);
$newIncrementId = $prefix . preg_replace('/[^a-zA-Z0-9-]+/', '', $channelId);
} else {
$newIncrementId = $prefix . preg_replace('/\s+/', '', $channelId);
}
Expand All @@ -73,9 +73,12 @@ public function execute(array $orderData, StoreInterface $store): ?string
->getLastItem();

if ($lastOrder->getIncrementId()) {
$lastIncrement = explode('-', $lastOrder->getIncrementId());
$newIncrementId = substr($lastOrder->getIncrementId(), 0, -(strlen(end($lastIncrement)) + 1));
$newIncrementId .= '-' . (end($lastIncrement) + 1);
$suffix = substr($lastOrder->getIncrementId(), strlen($newIncrementId) + 1);
if (is_numeric($suffix)) {
$newIncrementId .= '-' . ((int)$suffix + 1);
} else {
$newIncrementId .= '-1';
}
} else {
$newIncrementId .= '-1';
}
Expand Down
Loading