Skip to content

Commit

Permalink
feat: pseventbus v4 cart rules (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox-john authored Sep 13, 2024
1 parent 51383db commit a11a6ee
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 131 deletions.
4 changes: 4 additions & 0 deletions config/common/new-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ services:
PrestaShop\Module\PsEventbus\Repository\NewRepository\CartProductRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CartProductRepository
public: true

PrestaShop\Module\PsEventbus\Repository\NewRepository\CartRuleRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\CartRuleRepository
public: true
10 changes: 0 additions & 10 deletions config/common/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ services:
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'

PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderDetailRepository:
class: PrestaShop\Module\PsEventbus\Repository\NewRepository\OrderDetailRepository
public: true
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'

PrestaShop\Module\PsEventbus\Repository\CartRuleRepository:
class: PrestaShop\Module\PsEventbus\Repository\CartRuleRepository
public: true

PrestaShop\Module\PsEventbus\Repository\GoogleTaxonomyRepository:
class: PrestaShop\Module\PsEventbus\Repository\GoogleTaxonomyRepository
public: true
Expand Down
6 changes: 6 additions & 0 deletions config/front/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ services:
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CartProductRepository'

PrestaShop\Module\PsEventbus\Service\ShopContent\CartRulesService:
class: PrestaShop\Module\PsEventbus\Service\ShopContent\CartRulesService
public: true
arguments:
- '@PrestaShop\Module\PsEventbus\Repository\NewRepository\CartRuleRepository'
1 change: 1 addition & 0 deletions e2e/src/helpers/shop-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const shopContentMapping = {
'carrier_taxes': 'carrier-taxes',
'carts': 'carts',
'cart_products': 'cart-products',
'cart_rules': 'cart-rules',
'orders': 'orders',
'order_cart_rules': 'order-cart-rules',
'order_details': 'order-details',
Expand Down
121 changes: 0 additions & 121 deletions src/Repository/CartRuleRepository.php

This file was deleted.

131 changes: 131 additions & 0 deletions src/Repository/NewRepository/CartRuleRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace PrestaShop\Module\PsEventbus\Repository\NewRepository;

class CartRuleRepository extends AbstractRepository implements RepositoryInterface
{
const TABLE_NAME = 'cart_rule';

/**
* @return void
*/
public function generateMinimalQuery()
{
$this->query = new \DbQuery();

$this->query->from(self::TABLE_NAME, 'cr');
}

/**
* @param string $langIso
*
* @return mixed
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso)
{
$this->generateMinimalQuery();

$this->query
->select('cr.id_cart_rule')
->select('cr.id_customer')
->select('cr.code')
->select('cr.date_from AS "from"')
->select('cr.date_to AS "to"')
->select('cr.description')
->select('cr.quantity')
->select('cr.quantity_per_user')
->select('cr.priority')
->select('cr.partial_use')
->select('cr.minimum_amount')
->select('cr.minimum_amount_tax')
->select('cr.minimum_amount_currency')
->select('cr.minimum_amount_shipping')
->select('cr.country_restriction')
->select('cr.carrier_restriction')
->select('cr.group_restriction')
->select('cr.cart_rule_restriction')
->select('cr.product_restriction')
->select('cr.shop_restriction')
->select('cr.free_shipping')
->select('cr.reduction_percent')
->select('cr.reduction_amount')
->select('cr.reduction_tax')
->select('cr.reduction_currency')
->select('cr.reduction_product')
->select('cr.gift_product')
->select('cr.gift_product_attribute')
->select('cr.highlight')
->select('cr.active')
->select('cr.date_add AS created_at')
->select('cr.date_upd AS updated_at')
;

if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7', '>=')) {
$this->query->select('cr.reduction_exclude_special');
}
}

/**
* @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('cr.id_cart_rule 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(cr.id_cart_rule) - ' . (int) $offset . ') as count');

$result = $this->runQuery(false);

return $result[0]['count'];
}
}
Loading

0 comments on commit a11a6ee

Please sign in to comment.