-
Notifications
You must be signed in to change notification settings - Fork 7
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
9 changed files
with
209 additions
and
132 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
This file was deleted.
Oops, something went wrong.
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,100 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Repository\NewRepository; | ||
|
||
class CartRepository extends AbstractRepository implements RepositoryInterface | ||
{ | ||
const TABLE_NAME = 'cart'; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function generateMinimalQuery() | ||
{ | ||
$this->query = new \DbQuery(); | ||
|
||
$this->query->from(self::TABLE_NAME, 'c'); | ||
} | ||
|
||
/** | ||
* @param string $langIso | ||
* | ||
* @return mixed | ||
* | ||
* @throws \PrestaShopException | ||
*/ | ||
public function generateFullQuery($langIso) | ||
{ | ||
$this->generateMinimalQuery(); | ||
|
||
$this->query->where('c.id_shop = ' . (int) parent::getShopId()); | ||
|
||
$this->query | ||
->select('c.id_cart') | ||
->select('date_add as created_at') | ||
->select('date_upd as updated_at') | ||
; | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param int $limit | ||
* @param string $langIso | ||
* @param bool $debug | ||
* | ||
* @return array<mixed> | ||
* | ||
* @throws \PrestaShopException | ||
* @throws \PrestaShopDatabaseException | ||
*/ | ||
public function getContentsForFull($offset, $limit, $langIso, $debug) | ||
{ | ||
$this->generateFullQuery($langIso); | ||
|
||
$this->query->limit((int) $limit, (int) $offset); | ||
|
||
return $this->runQuery($debug); | ||
} | ||
|
||
/** | ||
* @param int $limit | ||
* @param array<mixed> $contentIds | ||
* @param string $langIso | ||
* @param bool $debug | ||
* | ||
* @return array<mixed> | ||
* | ||
* @throws \PrestaShopException | ||
* @throws \PrestaShopDatabaseException | ||
*/ | ||
public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) | ||
{ | ||
$this->generateFullQuery($langIso); | ||
|
||
$this->query | ||
->where('c.id_cart IN(' . implode(',', array_map('intval', $contentIds)) . ')') | ||
->limit($limit) | ||
; | ||
|
||
return $this->runQuery($debug); | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* | ||
* @return int | ||
* | ||
* @throws \PrestaShopException | ||
* @throws \PrestaShopDatabaseException | ||
*/ | ||
public function countFullSyncContentLeft($offset) | ||
{ | ||
$this->generateMinimalQuery(); | ||
|
||
$this->query->select('(COUNT(c.id_cart) - ' . (int) $offset . ') as count'); | ||
|
||
$result = $this->runQuery(false); | ||
|
||
return $result[0]['count']; | ||
} | ||
} |
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,95 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PsEventbus\Service\ShopContent; | ||
|
||
use PrestaShop\Module\PsEventbus\Config\Config; | ||
use PrestaShop\Module\PsEventbus\Repository\NewRepository\CartRepository; | ||
|
||
class CartsService implements ShopContentServiceInterface | ||
{ | ||
/** @var CartRepository */ | ||
private $cartRepository; | ||
|
||
public function __construct(CartRepository $cartRepository) | ||
{ | ||
$this->cartRepository = $cartRepository; | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* @param int $limit | ||
* @param string $langIso | ||
* @param bool $debug | ||
* | ||
* @return array<mixed> | ||
*/ | ||
public function getContentsForFull($offset, $limit, $langIso, $debug) | ||
{ | ||
$result = $this->cartRepository->getContentsForFull($offset, $limit, $langIso, $debug); | ||
|
||
if (empty($result)) { | ||
return []; | ||
} | ||
|
||
$this->castCarts($result); | ||
|
||
return array_map(function ($item) { | ||
return [ | ||
'id' => (string) $item['id_cart'], | ||
'collection' => Config::COLLECTION_CARTS, | ||
'properties' => $item, | ||
]; | ||
}, $result); | ||
} | ||
|
||
/** | ||
* @param int $limit | ||
* @param array<string, int> $contentIds | ||
* @param string $langIso | ||
* @param bool $debug | ||
* | ||
* @return array<mixed> | ||
*/ | ||
public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) | ||
{ | ||
$result = $this->cartRepository->getContentsForIncremental($limit, $contentIds, $langIso, $debug); | ||
|
||
if (empty($result)) { | ||
return []; | ||
} | ||
|
||
$this->castCarts($result); | ||
|
||
return array_map(function ($item) { | ||
return [ | ||
'id' => (string) $item['id_cart'], | ||
'collection' => Config::COLLECTION_CARTS, | ||
'properties' => $item, | ||
]; | ||
}, $result); | ||
} | ||
|
||
/** | ||
* @param int $offset | ||
* | ||
* @return int | ||
*/ | ||
public function countFullSyncContentLeft($offset) | ||
{ | ||
return $this->cartRepository->countFullSyncContentLeft($offset); | ||
} | ||
|
||
/** | ||
* @param array<mixed> $carts | ||
* | ||
* @return void | ||
*/ | ||
private function castCarts(&$carts) | ||
{ | ||
foreach ($carts as &$cart) { | ||
$cart['id_cart'] = (string) $cart['id_cart']; | ||
$cart['created_at'] = (string) $cart['created_at']; | ||
$cart['updated_at'] = (string) $cart['updated_at']; | ||
} | ||
} | ||
} |