Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add condition match for cart item include quantity #1853

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,83 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/

namespace Thelia\Condition\Implementation;

use Thelia\Condition\Operators;

/**
* Class MatchForXArticlesIncludeQuantity
* @package Thelia\Condition\Implementation
* @author Baixas Alban <abaixas@openstudio.fr>
*/
class MatchForXArticlesIncludeQuantity extends MatchForXArticles
{
/**
* @inheritdoc
*/
public function getServiceId()
{
return 'thelia.condition.match_for_x_articles_include_quantity';
}

/**
* @inheritdoc
*/
public function getName()
{
return $this->translator->trans('Cart item include quantity count');
}

/**
* @inheritdoc
*/
public function isMatching()
{
return $this->conditionValidator->variableOpComparison(
$this->facade->getNbArticlesInCartIncludeQuantity(),
$this->operators[self::CART_QUANTITY],
$this->values[self::CART_QUANTITY]
);
}

/**
* @inheritdoc
*/
public function drawBackOfficeInputs()
{
$labelQuantity = $this->facade->getTranslator()->trans('Cart item include quantity count is');

return $this->drawBackOfficeBaseInputsText($labelQuantity, self::CART_QUANTITY);
}

/**
* @inheritdoc
*/
public function getSummary()
{
$i18nOperator = Operators::getI18n(
$this->translator,
$this->operators[self::CART_QUANTITY]
);

$toolTip = $this->translator->trans(
'If cart item (include quantity) count is <strong>%operator%</strong> %quantity%',
array(
'%operator%' => $i18nOperator,
'%quantity%' => $this->values[self::CART_QUANTITY]
)
);

return $toolTip;
}

}
3 changes: 3 additions & 0 deletions core/lib/Thelia/Config/I18n/en_US.php
Expand Up @@ -85,9 +85,11 @@
'Cart contains categories condition' => 'Cart contains categories condition',
'Cart contains specific products' => 'Cart contains specific products',
'Cart item count' => 'Cart item count',
'Cart item include quantity count' => 'Cart item include quantity count',
'Cart item count is' => 'Cart item count is',
'Cart total amount' => 'Cart total amount',
'Cart total amount is' => 'Cart total amount is',
'Cart item include quantity count is' => 'Cart item include quantity count is',
'Catalog' => 'Catalog',
'Catalog configuration' => 'Catalog configuration',
'Categories' => 'Categories',
Expand Down Expand Up @@ -233,6 +235,7 @@
'ISO Alpha-3 code' => 'ISO Alpha-3 code',
'If a translation is missing or incomplete :' => 'If a translation is missing or incomplete :',
'If cart item count is <strong>%operator%</strong> %quantity%' => 'If cart item count is <strong>%operator%</strong> %quantity%',
'If cart item (include quantity) count is <strong>%operator%</strong> %quantity%' => 'If cart item (include quantity) count is <strong>%operator%</strong> %quantity%',
'If cart total amount is <strong>%operator%</strong> %amount% %currency%' => 'If cart total amount is <strong>%operator%</strong> %amount% %currency%',
'If checked, this hook will be used by a hook block. If not, by hook function.' => 'If checked, this hook will be used by a hook block. If not, by hook function.',
'Image' => 'Image',
Expand Down
3 changes: 3 additions & 0 deletions core/lib/Thelia/Config/I18n/fr_FR.php
Expand Up @@ -85,7 +85,9 @@
'Cart contains categories condition' => 'Valable si le panier contient/ne contient pas des produits appartenant à certaines catégories',
'Cart contains specific products' => 'Valable si le panier contient certains produits',
'Cart item count' => 'Nombre d\'articles dans le panier',
'Cart item include quantity count' => 'Nombre d\'articles quantité incluse dans le panier',
'Cart item count is' => 'Le nombre d\'articles dans le panier est',
'Cart item include quantity count is' => 'Le nombre d\'articles quantité incluse dans le panier est',
'Cart total amount' => 'Montant total du panier',
'Cart total amount is' => 'Le total du panier est',
'Catalog' => 'Catalogue',
Expand Down Expand Up @@ -233,6 +235,7 @@
'ISO Alpha-3 code' => 'Code ISO Alpha-3',
'If a translation is missing or incomplete :' => 'Si une traduction est manquante ou incomplète :',
'If cart item count is <strong>%operator%</strong> %quantity%' => 'Le nombre d\'articles dans le panier est <strong>%operator%</strong> %quantity% ',
'If cart item (include quantity) count is <strong>%operator%</strong> %quantity%' => 'Le nombre d\'articles (quantité incluse) dans le panier est <strong>%operator%</strong> %quantity% ',
'If cart total amount is <strong>%operator%</strong> %amount% %currency%' => 'Si le total du panier est <strong>%operator%</strong> %amount% %currency% ',
'If checked, this hook will be used by a hook block. If not, by hook function.' => 'Indique que ce point d\'accroche utilise un bloc Smarty hookBlock. sinon une fonction Smarty hook.',
'Image' => 'Image',
Expand Down
5 changes: 5 additions & 0 deletions core/lib/Thelia/Config/Resources/coupon.xml
Expand Up @@ -95,6 +95,11 @@
<tag name="thelia.coupon.addCondition"/>
</service>

<service id="thelia.condition.match_for_x_articles_include_quantity" class="Thelia\Condition\Implementation\MatchForXArticlesIncludeQuantity">
<argument type="service" id="thelia.facade" />
<tag name="thelia.coupon.addCondition"/>
</service>

<service id="thelia.condition.match_delivery_countries" class="Thelia\Condition\Implementation\MatchDeliveryCountries">
<argument type="service" id="thelia.facade" />
<tag name="thelia.coupon.addCondition"/>
Expand Down
12 changes: 12 additions & 0 deletions core/lib/Thelia/Coupon/BaseFacade.php
Expand Up @@ -177,6 +177,18 @@ public function getNbArticlesInCart()
return count($this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getCartItems());
}

public function getNbArticlesInCartIncludeQuantity()
{
$cartItems = $this->getCart()->getCartItems();
$quantity = 0;

foreach ($cartItems as $cartItem) {
$quantity += $cartItem->getQuantity();
}

return $quantity;
}

/**
* Return all Coupon given during the Checkout
*
Expand Down
7 changes: 7 additions & 0 deletions core/lib/Thelia/Coupon/FacadeInterface.php
Expand Up @@ -108,6 +108,13 @@ public function getCheckoutPostagePrice();
*/
public function getNbArticlesInCart();

/**
* Return the number of Products include quantity in the Cart
*
* @return int
*/
public function getNbArticlesInCartIncludeQuantity();

/**
* Return all Coupon given during the Checkout
*
Expand Down