currency management in PSE loop

This commit is contained in:
Etienne Roudeix
2013-09-11 10:51:44 +02:00
parent 70f6ee6a52
commit 3d31090344
3 changed files with 22 additions and 16 deletions

View File

@@ -34,6 +34,7 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Base\ProductSaleElementsQuery;
use Thelia\Model\CountryQuery;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\Map\ProductSaleElementsTableMap;
use Thelia\Type\TypeCollection;
use Thelia\Type;
@@ -41,7 +42,7 @@ use Thelia\Type;
*
* Product Sale Elements loop
*
* @todo : manage currency and attribute_availability
* @todo : manage attribute_availability
*
* Class ProductSaleElements
* @package Thelia\Core\Template\Loop
@@ -94,16 +95,16 @@ class ProductSaleElements extends BaseLoop
foreach ($orders as $order) {
switch ($order) {
case "min_price":
$search->addAscendingOrderByColumn('real_lowest_price', Criteria::ASC);
$search->addAscendingOrderByColumn('price_FINAL_PRICE', Criteria::ASC);
break;
case "max_price":
$search->addDescendingOrderByColumn('real_lowest_price');
$search->addDescendingOrderByColumn('price_FINAL_PRICE');
break;
case "promo":
$search->addDescendingOrderByColumn('main_product_is_promo');
$search->orderByPromo(Criteria::DESC);
break;
case "new":
$search->addDescendingOrderByColumn('main_product_is_new');
$search->orderByNewness(Criteria::DESC);
break;
case "random":
$search->clearOrderByColumns();
@@ -125,15 +126,22 @@ class ProductSaleElements extends BaseLoop
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
$defaultCurrencySuffix = '_default_currency';
$search->joinProductPrice('price', Criteria::INNER_JOIN)
$search->joinProductPrice('price', Criteria::LEFT_JOIN)
->addJoinCondition('price', '`price`.`currency_id` = ?', $currency->getId(), null, \PDO::PARAM_INT);
$search->joinProductPrice('price' . $defaultCurrencySuffix, Criteria::INNER_JOIN)
$search->joinProductPrice('price' . $defaultCurrencySuffix, Criteria::LEFT_JOIN)
->addJoinCondition('price_default_currency', '`price' . $defaultCurrencySuffix . '`.`currency_id` = ?', $defaultCurrency->getId(), null, \PDO::PARAM_INT);
$search->withColumn('`price`.CURRENCY_ID', 'price_CURRENCY_ID')
->withColumn('`price`.PRICE', 'price_PRICE')
->withColumn('`price`.PROMO_PRICE', 'price_PROMO_PRICE');
/**
* rate value is checked as a float in overloaded getRate method.
*/
$priceSelectorAsSQL = 'ROUND(CASE WHEN ISNULL(`price`.PRICE) THEN `price_default_currency`.PRICE * ' . $currency->getRate() . ' ELSE `price`.PRICE END, 2)';
$promoPriceSelectorAsSQL = 'ROUND(CASE WHEN ISNULL(`price`.PRICE) THEN `price_default_currency`.PROMO_PRICE * ' . $currency->getRate() . ' ELSE `price`.PROMO_PRICE END, 2)';
$search->withColumn($priceSelectorAsSQL, 'price_PRICE')
->withColumn($promoPriceSelectorAsSQL, 'price_PROMO_PRICE')
->withColumn('CASE WHEN ' . ProductSaleElementsTableMap::PROMO . ' = 1 THEN ' . $promoPriceSelectorAsSQL . ' ELSE ' . $priceSelectorAsSQL . ' END', 'price_FINAL_PRICE');
$search->groupById();
$PSEValues = $this->search($search, $pagination);
@@ -156,8 +164,6 @@ class ProductSaleElements extends BaseLoop
->set("IS_PROMO", $PSEValue->getPromo() === 1 ? 1 : 0)
->set("IS_NEW", $PSEValue->getNewness() === 1 ? 1 : 0)
->set("WEIGHT", $PSEValue->getWeight())
->set("CURRENCY", $PSEValue->getVirtualColumn('price_CURRENCY_ID'))
->set("PRICE", $price)
->set("PRICE_TAX", $taxedPrice - $price)
->set("TAXED_PRICE", $taxedPrice)

View File

@@ -83,7 +83,7 @@ class Thelia extends Kernel
$con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
$con->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true);
if ($this->isDebug()) {
$serviceContainer->setLogger('defaultLogger', \Thelia\Log\Tlog::getInstance());
$con->useDebug(true);
}
}

View File

@@ -1,4 +1,4 @@
{include file="includes/header.html"}
{*include file="includes/header.html"*}
Here you are : {navigate to="current"}<br />
From : {navigate to="return_to"}<br />
@@ -62,7 +62,7 @@ Index : {navigate to="index"}<br />
<h4>Product sale elements</h4>
{assign var=current_product value=$ID}
{loop name="pse" type="product_sale_elements" product="$ID"}
{loop name="pse" type="product_sale_elements" product="$ID" order="promo,min_price"}
<div style="border: solid 2px darkorange; padding: 5px; margin: 5px;">
{loop name="combi" type="attribute_combination" product_sale_elements="$ID"}
{$ATTRIBUTE_TITLE} = {$ATTRIBUTE_AVAILABILITY_TITLE}<br />
@@ -91,4 +91,4 @@ Index : {navigate to="index"}<br />
<h2>Produit introuvable !</h2>
{/elseloop}
{include file="includes/footer.html"}
{*include file="includes/footer.html"*}