- * $obj = $c->findPk(12, $con);
+ * $obj = $c->findPk(array(12, 34), $con);
*
*
- * @param mixed $key Primary key to use for the query
+ * @param array[$product_sale_elements_id, $currency_id] $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildProductPrice|array|mixed the result, formatted by the current formatter
@@ -127,7 +123,7 @@ abstract class ProductPriceQuery extends ModelCriteria
if ($key === null) {
return null;
}
- if ((null !== ($obj = ProductPriceTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
+ if ((null !== ($obj = ProductPriceTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
@@ -155,10 +151,11 @@ abstract class ProductPriceQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
- $sql = 'SELECT ID, PRODUCT_SALE_ELEMENTS_ID, CURRENCY_ID, PRICE, PROMO_PRICE, CREATED_AT, UPDATED_AT FROM product_price WHERE ID = :p0';
+ $sql = 'SELECT PRODUCT_SALE_ELEMENTS_ID, CURRENCY_ID, PRICE, PROMO_PRICE, CREATED_AT, UPDATED_AT FROM product_price WHERE PRODUCT_SALE_ELEMENTS_ID = :p0 AND CURRENCY_ID = :p1';
try {
$stmt = $con->prepare($sql);
- $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
+ $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
+ $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
@@ -168,7 +165,7 @@ abstract class ProductPriceQuery extends ModelCriteria
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildProductPrice();
$obj->hydrate($row);
- ProductPriceTableMap::addInstanceToPool($obj, (string) $key);
+ ProductPriceTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1])));
}
$stmt->closeCursor();
@@ -197,7 +194,7 @@ abstract class ProductPriceQuery extends ModelCriteria
/**
* Find objects by primary key
*
- * $objs = $c->findPks(array(12, 56, 832), $con);
+ * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
*
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
@@ -227,8 +224,10 @@ abstract class ProductPriceQuery extends ModelCriteria
*/
public function filterByPrimaryKey($key)
{
+ $this->addUsingAlias(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID, $key[0], Criteria::EQUAL);
+ $this->addUsingAlias(ProductPriceTableMap::CURRENCY_ID, $key[1], Criteria::EQUAL);
- return $this->addUsingAlias(ProductPriceTableMap::ID, $key, Criteria::EQUAL);
+ return $this;
}
/**
@@ -240,49 +239,17 @@ abstract class ProductPriceQuery extends ModelCriteria
*/
public function filterByPrimaryKeys($keys)
{
-
- return $this->addUsingAlias(ProductPriceTableMap::ID, $keys, Criteria::IN);
- }
-
- /**
- * Filter the query on the id column
- *
- * Example usage:
- *
- * $query->filterById(1234); // WHERE id = 1234
- * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
- * $query->filterById(array('min' => 12)); // WHERE id > 12
- *
- *
- * @param mixed $id The value to use as filter.
- * Use scalar values for equality.
- * Use array values for in_array() equivalent.
- * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
- * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
- *
- * @return ChildProductPriceQuery The current query, for fluid interface
- */
- public function filterById($id = null, $comparison = null)
- {
- if (is_array($id)) {
- $useMinMax = false;
- if (isset($id['min'])) {
- $this->addUsingAlias(ProductPriceTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
- $useMinMax = true;
- }
- if (isset($id['max'])) {
- $this->addUsingAlias(ProductPriceTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
- $useMinMax = true;
- }
- if ($useMinMax) {
- return $this;
- }
- if (null === $comparison) {
- $comparison = Criteria::IN;
- }
+ if (empty($keys)) {
+ return $this->add(null, '1<>1', Criteria::CUSTOM);
+ }
+ foreach ($keys as $key) {
+ $cton0 = $this->getNewCriterion(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID, $key[0], Criteria::EQUAL);
+ $cton1 = $this->getNewCriterion(ProductPriceTableMap::CURRENCY_ID, $key[1], Criteria::EQUAL);
+ $cton0->addAnd($cton1);
+ $this->addOr($cton0);
}
- return $this->addUsingAlias(ProductPriceTableMap::ID, $id, $comparison);
+ return $this;
}
/**
@@ -699,7 +666,9 @@ abstract class ProductPriceQuery extends ModelCriteria
public function prune($productPrice = null)
{
if ($productPrice) {
- $this->addUsingAlias(ProductPriceTableMap::ID, $productPrice->getId(), Criteria::NOT_EQUAL);
+ $this->addCond('pruneCond0', $this->getAliasedColName(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID), $productPrice->getProductSaleElementsId(), Criteria::NOT_EQUAL);
+ $this->addCond('pruneCond1', $this->getAliasedColName(ProductPriceTableMap::CURRENCY_ID), $productPrice->getCurrencyId(), Criteria::NOT_EQUAL);
+ $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
}
return $this;
diff --git a/core/lib/Thelia/Model/Base/ProductSaleElements.php b/core/lib/Thelia/Model/Base/ProductSaleElements.php
index f79d9a246..4c14580ff 100644
--- a/core/lib/Thelia/Model/Base/ProductSaleElements.php
+++ b/core/lib/Thelia/Model/Base/ProductSaleElements.php
@@ -2248,7 +2248,10 @@ abstract class ProductSaleElements implements ActiveRecordInterface
$productPricesToDelete = $this->getProductPrices(new Criteria(), $con)->diff($productPrices);
- $this->productPricesScheduledForDeletion = $productPricesToDelete;
+ //since at least one column in the foreign key is at the same time a PK
+ //we can not just set a PK to NULL in the lines below. We have to store
+ //a backup of all values, so we are able to manipulate these items based on the onDelete value later.
+ $this->productPricesScheduledForDeletion = clone $productPricesToDelete;
foreach ($productPricesToDelete as $productPriceRemoved) {
$productPriceRemoved->setProductSaleElements(null);
diff --git a/core/lib/Thelia/Model/Base/Tax.php b/core/lib/Thelia/Model/Base/Tax.php
index ed4bb40f7..da674b5cf 100644
--- a/core/lib/Thelia/Model/Base/Tax.php
+++ b/core/lib/Thelia/Model/Base/Tax.php
@@ -66,10 +66,16 @@ abstract class Tax implements ActiveRecordInterface
protected $id;
/**
- * The value for the rate field.
- * @var double
+ * The value for the type field.
+ * @var string
*/
- protected $rate;
+ protected $type;
+
+ /**
+ * The value for the serialized_requirements field.
+ * @var string
+ */
+ protected $serialized_requirements;
/**
* The value for the created_at field.
@@ -395,14 +401,25 @@ abstract class Tax implements ActiveRecordInterface
}
/**
- * Get the [rate] column value.
+ * Get the [type] column value.
*
- * @return double
+ * @return string
*/
- public function getRate()
+ public function getType()
{
- return $this->rate;
+ return $this->type;
+ }
+
+ /**
+ * Get the [serialized_requirements] column value.
+ *
+ * @return string
+ */
+ public function getSerializedRequirements()
+ {
+
+ return $this->serialized_requirements;
}
/**
@@ -467,25 +484,46 @@ abstract class Tax implements ActiveRecordInterface
} // setId()
/**
- * Set the value of [rate] column.
+ * Set the value of [type] column.
*
- * @param double $v new value
+ * @param string $v new value
* @return \Thelia\Model\Tax The current object (for fluent API support)
*/
- public function setRate($v)
+ public function setType($v)
{
if ($v !== null) {
- $v = (double) $v;
+ $v = (string) $v;
}
- if ($this->rate !== $v) {
- $this->rate = $v;
- $this->modifiedColumns[] = TaxTableMap::RATE;
+ if ($this->type !== $v) {
+ $this->type = $v;
+ $this->modifiedColumns[] = TaxTableMap::TYPE;
}
return $this;
- } // setRate()
+ } // setType()
+
+ /**
+ * Set the value of [serialized_requirements] column.
+ *
+ * @param string $v new value
+ * @return \Thelia\Model\Tax The current object (for fluent API support)
+ */
+ public function setSerializedRequirements($v)
+ {
+ if ($v !== null) {
+ $v = (string) $v;
+ }
+
+ if ($this->serialized_requirements !== $v) {
+ $this->serialized_requirements = $v;
+ $this->modifiedColumns[] = TaxTableMap::SERIALIZED_REQUIREMENTS;
+ }
+
+
+ return $this;
+ } // setSerializedRequirements()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
@@ -569,16 +607,19 @@ abstract class Tax implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : TaxTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
$this->id = (null !== $col) ? (int) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : TaxTableMap::translateFieldName('Rate', TableMap::TYPE_PHPNAME, $indexType)];
- $this->rate = (null !== $col) ? (double) $col : null;
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : TaxTableMap::translateFieldName('Type', TableMap::TYPE_PHPNAME, $indexType)];
+ $this->type = (null !== $col) ? (string) $col : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : TaxTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : TaxTableMap::translateFieldName('SerializedRequirements', TableMap::TYPE_PHPNAME, $indexType)];
+ $this->serialized_requirements = (null !== $col) ? (string) $col : null;
+
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : TaxTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
- $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : TaxTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
+ $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : TaxTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -591,7 +632,7 @@ abstract class Tax implements ActiveRecordInterface
$this->ensureConsistency();
}
- return $startcol + 4; // 4 = TaxTableMap::NUM_HYDRATE_COLUMNS.
+ return $startcol + 5; // 5 = TaxTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\Tax object", 0, $e);
@@ -852,8 +893,11 @@ abstract class Tax implements ActiveRecordInterface
if ($this->isColumnModified(TaxTableMap::ID)) {
$modifiedColumns[':p' . $index++] = 'ID';
}
- if ($this->isColumnModified(TaxTableMap::RATE)) {
- $modifiedColumns[':p' . $index++] = 'RATE';
+ if ($this->isColumnModified(TaxTableMap::TYPE)) {
+ $modifiedColumns[':p' . $index++] = 'TYPE';
+ }
+ if ($this->isColumnModified(TaxTableMap::SERIALIZED_REQUIREMENTS)) {
+ $modifiedColumns[':p' . $index++] = 'SERIALIZED_REQUIREMENTS';
}
if ($this->isColumnModified(TaxTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
@@ -875,8 +919,11 @@ abstract class Tax implements ActiveRecordInterface
case 'ID':
$stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
break;
- case 'RATE':
- $stmt->bindValue($identifier, $this->rate, PDO::PARAM_STR);
+ case 'TYPE':
+ $stmt->bindValue($identifier, $this->type, PDO::PARAM_STR);
+ break;
+ case 'SERIALIZED_REQUIREMENTS':
+ $stmt->bindValue($identifier, $this->serialized_requirements, PDO::PARAM_STR);
break;
case 'CREATED_AT':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
@@ -950,12 +997,15 @@ abstract class Tax implements ActiveRecordInterface
return $this->getId();
break;
case 1:
- return $this->getRate();
+ return $this->getType();
break;
case 2:
- return $this->getCreatedAt();
+ return $this->getSerializedRequirements();
break;
case 3:
+ return $this->getCreatedAt();
+ break;
+ case 4:
return $this->getUpdatedAt();
break;
default:
@@ -988,9 +1038,10 @@ abstract class Tax implements ActiveRecordInterface
$keys = TaxTableMap::getFieldNames($keyType);
$result = array(
$keys[0] => $this->getId(),
- $keys[1] => $this->getRate(),
- $keys[2] => $this->getCreatedAt(),
- $keys[3] => $this->getUpdatedAt(),
+ $keys[1] => $this->getType(),
+ $keys[2] => $this->getSerializedRequirements(),
+ $keys[3] => $this->getCreatedAt(),
+ $keys[4] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach($virtualColumns as $key => $virtualColumn)
@@ -1043,12 +1094,15 @@ abstract class Tax implements ActiveRecordInterface
$this->setId($value);
break;
case 1:
- $this->setRate($value);
+ $this->setType($value);
break;
case 2:
- $this->setCreatedAt($value);
+ $this->setSerializedRequirements($value);
break;
case 3:
+ $this->setCreatedAt($value);
+ break;
+ case 4:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1076,9 +1130,10 @@ abstract class Tax implements ActiveRecordInterface
$keys = TaxTableMap::getFieldNames($keyType);
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
- if (array_key_exists($keys[1], $arr)) $this->setRate($arr[$keys[1]]);
- if (array_key_exists($keys[2], $arr)) $this->setCreatedAt($arr[$keys[2]]);
- if (array_key_exists($keys[3], $arr)) $this->setUpdatedAt($arr[$keys[3]]);
+ if (array_key_exists($keys[1], $arr)) $this->setType($arr[$keys[1]]);
+ if (array_key_exists($keys[2], $arr)) $this->setSerializedRequirements($arr[$keys[2]]);
+ if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]);
+ if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]);
}
/**
@@ -1091,7 +1146,8 @@ abstract class Tax implements ActiveRecordInterface
$criteria = new Criteria(TaxTableMap::DATABASE_NAME);
if ($this->isColumnModified(TaxTableMap::ID)) $criteria->add(TaxTableMap::ID, $this->id);
- if ($this->isColumnModified(TaxTableMap::RATE)) $criteria->add(TaxTableMap::RATE, $this->rate);
+ if ($this->isColumnModified(TaxTableMap::TYPE)) $criteria->add(TaxTableMap::TYPE, $this->type);
+ if ($this->isColumnModified(TaxTableMap::SERIALIZED_REQUIREMENTS)) $criteria->add(TaxTableMap::SERIALIZED_REQUIREMENTS, $this->serialized_requirements);
if ($this->isColumnModified(TaxTableMap::CREATED_AT)) $criteria->add(TaxTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(TaxTableMap::UPDATED_AT)) $criteria->add(TaxTableMap::UPDATED_AT, $this->updated_at);
@@ -1157,7 +1213,8 @@ abstract class Tax implements ActiveRecordInterface
*/
public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
{
- $copyObj->setRate($this->getRate());
+ $copyObj->setType($this->getType());
+ $copyObj->setSerializedRequirements($this->getSerializedRequirements());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
@@ -1729,7 +1786,8 @@ abstract class Tax implements ActiveRecordInterface
public function clear()
{
$this->id = null;
- $this->rate = null;
+ $this->type = null;
+ $this->serialized_requirements = null;
$this->created_at = null;
$this->updated_at = null;
$this->alreadyInSave = false;
diff --git a/core/lib/Thelia/Model/Base/TaxQuery.php b/core/lib/Thelia/Model/Base/TaxQuery.php
index 07316bf69..93da10f53 100644
--- a/core/lib/Thelia/Model/Base/TaxQuery.php
+++ b/core/lib/Thelia/Model/Base/TaxQuery.php
@@ -23,12 +23,14 @@ use Thelia\Model\Map\TaxTableMap;
*
*
* @method ChildTaxQuery orderById($order = Criteria::ASC) Order by the id column
- * @method ChildTaxQuery orderByRate($order = Criteria::ASC) Order by the rate column
+ * @method ChildTaxQuery orderByType($order = Criteria::ASC) Order by the type column
+ * @method ChildTaxQuery orderBySerializedRequirements($order = Criteria::ASC) Order by the serialized_requirements column
* @method ChildTaxQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildTaxQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
* @method ChildTaxQuery groupById() Group by the id column
- * @method ChildTaxQuery groupByRate() Group by the rate column
+ * @method ChildTaxQuery groupByType() Group by the type column
+ * @method ChildTaxQuery groupBySerializedRequirements() Group by the serialized_requirements column
* @method ChildTaxQuery groupByCreatedAt() Group by the created_at column
* @method ChildTaxQuery groupByUpdatedAt() Group by the updated_at column
*
@@ -48,12 +50,14 @@ use Thelia\Model\Map\TaxTableMap;
* @method ChildTax findOneOrCreate(ConnectionInterface $con = null) Return the first ChildTax matching the query, or a new ChildTax object populated from the query conditions when no match is found
*
* @method ChildTax findOneById(int $id) Return the first ChildTax filtered by the id column
- * @method ChildTax findOneByRate(double $rate) Return the first ChildTax filtered by the rate column
+ * @method ChildTax findOneByType(string $type) Return the first ChildTax filtered by the type column
+ * @method ChildTax findOneBySerializedRequirements(string $serialized_requirements) Return the first ChildTax filtered by the serialized_requirements column
* @method ChildTax findOneByCreatedAt(string $created_at) Return the first ChildTax filtered by the created_at column
* @method ChildTax findOneByUpdatedAt(string $updated_at) Return the first ChildTax filtered by the updated_at column
*
* @method array findById(int $id) Return ChildTax objects filtered by the id column
- * @method array findByRate(double $rate) Return ChildTax objects filtered by the rate column
+ * @method array findByType(string $type) Return ChildTax objects filtered by the type column
+ * @method array findBySerializedRequirements(string $serialized_requirements) Return ChildTax objects filtered by the serialized_requirements column
* @method array findByCreatedAt(string $created_at) Return ChildTax objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildTax objects filtered by the updated_at column
*
@@ -144,7 +148,7 @@ abstract class TaxQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
- $sql = 'SELECT ID, RATE, CREATED_AT, UPDATED_AT FROM tax WHERE ID = :p0';
+ $sql = 'SELECT ID, TYPE, SERIALIZED_REQUIREMENTS, CREATED_AT, UPDATED_AT FROM tax WHERE ID = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -275,44 +279,61 @@ abstract class TaxQuery extends ModelCriteria
}
/**
- * Filter the query on the rate column
+ * Filter the query on the type column
*
* Example usage:
*
- * $query->filterByRate(1234); // WHERE rate = 1234
- * $query->filterByRate(array(12, 34)); // WHERE rate IN (12, 34)
- * $query->filterByRate(array('min' => 12)); // WHERE rate > 12
+ * $query->filterByType('fooValue'); // WHERE type = 'fooValue'
+ * $query->filterByType('%fooValue%'); // WHERE type LIKE '%fooValue%'
*
*
- * @param mixed $rate The value to use as filter.
- * Use scalar values for equality.
- * Use array values for in_array() equivalent.
- * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
+ * @param string $type The value to use as filter.
+ * Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildTaxQuery The current query, for fluid interface
*/
- public function filterByRate($rate = null, $comparison = null)
+ public function filterByType($type = null, $comparison = null)
{
- if (is_array($rate)) {
- $useMinMax = false;
- if (isset($rate['min'])) {
- $this->addUsingAlias(TaxTableMap::RATE, $rate['min'], Criteria::GREATER_EQUAL);
- $useMinMax = true;
- }
- if (isset($rate['max'])) {
- $this->addUsingAlias(TaxTableMap::RATE, $rate['max'], Criteria::LESS_EQUAL);
- $useMinMax = true;
- }
- if ($useMinMax) {
- return $this;
- }
- if (null === $comparison) {
+ if (null === $comparison) {
+ if (is_array($type)) {
$comparison = Criteria::IN;
+ } elseif (preg_match('/[\%\*]/', $type)) {
+ $type = str_replace('*', '%', $type);
+ $comparison = Criteria::LIKE;
}
}
- return $this->addUsingAlias(TaxTableMap::RATE, $rate, $comparison);
+ return $this->addUsingAlias(TaxTableMap::TYPE, $type, $comparison);
+ }
+
+ /**
+ * Filter the query on the serialized_requirements column
+ *
+ * Example usage:
+ *
+ * $query->filterBySerializedRequirements('fooValue'); // WHERE serialized_requirements = 'fooValue'
+ * $query->filterBySerializedRequirements('%fooValue%'); // WHERE serialized_requirements LIKE '%fooValue%'
+ *
+ *
+ * @param string $serializedRequirements The value to use as filter.
+ * Accepts wildcards (* and % trigger a LIKE)
+ * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
+ *
+ * @return ChildTaxQuery The current query, for fluid interface
+ */
+ public function filterBySerializedRequirements($serializedRequirements = null, $comparison = null)
+ {
+ if (null === $comparison) {
+ if (is_array($serializedRequirements)) {
+ $comparison = Criteria::IN;
+ } elseif (preg_match('/[\%\*]/', $serializedRequirements)) {
+ $serializedRequirements = str_replace('*', '%', $serializedRequirements);
+ $comparison = Criteria::LIKE;
+ }
+ }
+
+ return $this->addUsingAlias(TaxTableMap::SERIALIZED_REQUIREMENTS, $serializedRequirements, $comparison);
}
/**
diff --git a/core/lib/Thelia/Model/ConfigQuery.php b/core/lib/Thelia/Model/ConfigQuery.php
index 87b506e93..ced3783fe 100755
--- a/core/lib/Thelia/Model/ConfigQuery.php
+++ b/core/lib/Thelia/Model/ConfigQuery.php
@@ -42,4 +42,9 @@ class ConfigQuery extends BaseConfigQuery {
{
return self::read('active-template', 'default');
}
+
+ public static function useTaxFreeAmounts()
+ {
+ return self::read('use_tax_free_amounts', 'default') == 1;
+ }
} // ConfigQuery
diff --git a/core/lib/Thelia/Model/Currency.php b/core/lib/Thelia/Model/Currency.php
index 843211d5a..6ec452456 100755
--- a/core/lib/Thelia/Model/Currency.php
+++ b/core/lib/Thelia/Model/Currency.php
@@ -2,6 +2,7 @@
namespace Thelia\Model;
+use Propel\Runtime\Exception\PropelException;
use Thelia\Model\Base\Currency as BaseCurrency;
use Thelia\Core\Event\TheliaEvents;
use Propel\Runtime\Connection\ConnectionInterface;
@@ -80,4 +81,19 @@ class Currency extends BaseCurrency {
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETECURRENCY, new CurrencyEvent($this));
}
+
+ /**
+ * Get the [rate] column value.
+ *
+ * @return double
+ * @throws PropelException
+ */
+ public function getRate()
+ {
+ if(false === filter_var($this->rate, FILTER_VALIDATE_FLOAT)) {
+ throw new PropelException('Currency::rate is not float value');
+ }
+
+ return $this->rate;
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Model/Map/ProductPriceTableMap.php b/core/lib/Thelia/Model/Map/ProductPriceTableMap.php
index 1a6274e2d..86a22b680 100644
--- a/core/lib/Thelia/Model/Map/ProductPriceTableMap.php
+++ b/core/lib/Thelia/Model/Map/ProductPriceTableMap.php
@@ -57,7 +57,7 @@ class ProductPriceTableMap extends TableMap
/**
* The total number of columns
*/
- const NUM_COLUMNS = 7;
+ const NUM_COLUMNS = 6;
/**
* The number of lazy-loaded columns
@@ -67,12 +67,7 @@ class ProductPriceTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
- const NUM_HYDRATE_COLUMNS = 7;
-
- /**
- * the column name for the ID field
- */
- const ID = 'product_price.ID';
+ const NUM_HYDRATE_COLUMNS = 6;
/**
* the column name for the PRODUCT_SALE_ELEMENTS_ID field
@@ -116,12 +111,12 @@ class ProductPriceTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
- self::TYPE_PHPNAME => array('Id', 'ProductSaleElementsId', 'CurrencyId', 'Price', 'PromoPrice', 'CreatedAt', 'UpdatedAt', ),
- self::TYPE_STUDLYPHPNAME => array('id', 'productSaleElementsId', 'currencyId', 'price', 'promoPrice', 'createdAt', 'updatedAt', ),
- self::TYPE_COLNAME => array(ProductPriceTableMap::ID, ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductPriceTableMap::CURRENCY_ID, ProductPriceTableMap::PRICE, ProductPriceTableMap::PROMO_PRICE, ProductPriceTableMap::CREATED_AT, ProductPriceTableMap::UPDATED_AT, ),
- self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_SALE_ELEMENTS_ID', 'CURRENCY_ID', 'PRICE', 'PROMO_PRICE', 'CREATED_AT', 'UPDATED_AT', ),
- self::TYPE_FIELDNAME => array('id', 'product_sale_elements_id', 'currency_id', 'price', 'promo_price', 'created_at', 'updated_at', ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
+ self::TYPE_PHPNAME => array('ProductSaleElementsId', 'CurrencyId', 'Price', 'PromoPrice', 'CreatedAt', 'UpdatedAt', ),
+ self::TYPE_STUDLYPHPNAME => array('productSaleElementsId', 'currencyId', 'price', 'promoPrice', 'createdAt', 'updatedAt', ),
+ self::TYPE_COLNAME => array(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductPriceTableMap::CURRENCY_ID, ProductPriceTableMap::PRICE, ProductPriceTableMap::PROMO_PRICE, ProductPriceTableMap::CREATED_AT, ProductPriceTableMap::UPDATED_AT, ),
+ self::TYPE_RAW_COLNAME => array('PRODUCT_SALE_ELEMENTS_ID', 'CURRENCY_ID', 'PRICE', 'PROMO_PRICE', 'CREATED_AT', 'UPDATED_AT', ),
+ self::TYPE_FIELDNAME => array('product_sale_elements_id', 'currency_id', 'price', 'promo_price', 'created_at', 'updated_at', ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
);
/**
@@ -131,12 +126,12 @@ class ProductPriceTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
- self::TYPE_PHPNAME => array('Id' => 0, 'ProductSaleElementsId' => 1, 'CurrencyId' => 2, 'Price' => 3, 'PromoPrice' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ),
- self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productSaleElementsId' => 1, 'currencyId' => 2, 'price' => 3, 'promoPrice' => 4, 'createdAt' => 5, 'updatedAt' => 6, ),
- self::TYPE_COLNAME => array(ProductPriceTableMap::ID => 0, ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID => 1, ProductPriceTableMap::CURRENCY_ID => 2, ProductPriceTableMap::PRICE => 3, ProductPriceTableMap::PROMO_PRICE => 4, ProductPriceTableMap::CREATED_AT => 5, ProductPriceTableMap::UPDATED_AT => 6, ),
- self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_SALE_ELEMENTS_ID' => 1, 'CURRENCY_ID' => 2, 'PRICE' => 3, 'PROMO_PRICE' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ),
- self::TYPE_FIELDNAME => array('id' => 0, 'product_sale_elements_id' => 1, 'currency_id' => 2, 'price' => 3, 'promo_price' => 4, 'created_at' => 5, 'updated_at' => 6, ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
+ self::TYPE_PHPNAME => array('ProductSaleElementsId' => 0, 'CurrencyId' => 1, 'Price' => 2, 'PromoPrice' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ),
+ self::TYPE_STUDLYPHPNAME => array('productSaleElementsId' => 0, 'currencyId' => 1, 'price' => 2, 'promoPrice' => 3, 'createdAt' => 4, 'updatedAt' => 5, ),
+ self::TYPE_COLNAME => array(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID => 0, ProductPriceTableMap::CURRENCY_ID => 1, ProductPriceTableMap::PRICE => 2, ProductPriceTableMap::PROMO_PRICE => 3, ProductPriceTableMap::CREATED_AT => 4, ProductPriceTableMap::UPDATED_AT => 5, ),
+ self::TYPE_RAW_COLNAME => array('PRODUCT_SALE_ELEMENTS_ID' => 0, 'CURRENCY_ID' => 1, 'PRICE' => 2, 'PROMO_PRICE' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ),
+ self::TYPE_FIELDNAME => array('product_sale_elements_id' => 0, 'currency_id' => 1, 'price' => 2, 'promo_price' => 3, 'created_at' => 4, 'updated_at' => 5, ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
);
/**
@@ -153,11 +148,10 @@ class ProductPriceTableMap extends TableMap
$this->setPhpName('ProductPrice');
$this->setClassName('\\Thelia\\Model\\ProductPrice');
$this->setPackage('Thelia.Model');
- $this->setUseIdGenerator(true);
+ $this->setUseIdGenerator(false);
// columns
- $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
- $this->addForeignKey('PRODUCT_SALE_ELEMENTS_ID', 'ProductSaleElementsId', 'INTEGER', 'product_sale_elements', 'ID', true, null, null);
- $this->addForeignKey('CURRENCY_ID', 'CurrencyId', 'INTEGER', 'currency', 'ID', true, null, null);
+ $this->addForeignPrimaryKey('PRODUCT_SALE_ELEMENTS_ID', 'ProductSaleElementsId', 'INTEGER' , 'product_sale_elements', 'ID', true, null, null);
+ $this->addForeignPrimaryKey('CURRENCY_ID', 'CurrencyId', 'INTEGER' , 'currency', 'ID', true, null, null);
$this->addColumn('PRICE', 'Price', 'FLOAT', true, null, null);
$this->addColumn('PROMO_PRICE', 'PromoPrice', 'FLOAT', false, null, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
@@ -186,6 +180,59 @@ class ProductPriceTableMap extends TableMap
);
} // getBehaviors()
+ /**
+ * Adds an object to the instance pool.
+ *
+ * Propel keeps cached copies of objects in an instance pool when they are retrieved
+ * from the database. In some cases you may need to explicitly add objects
+ * to the cache in order to ensure that the same objects are always returned by find*()
+ * and findPk*() calls.
+ *
+ * @param \Thelia\Model\ProductPrice $obj A \Thelia\Model\ProductPrice object.
+ * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
+ */
+ public static function addInstanceToPool($obj, $key = null)
+ {
+ if (Propel::isInstancePoolingEnabled()) {
+ if (null === $key) {
+ $key = serialize(array((string) $obj->getProductSaleElementsId(), (string) $obj->getCurrencyId()));
+ } // if key === null
+ self::$instances[$key] = $obj;
+ }
+ }
+
+ /**
+ * Removes an object from the instance pool.
+ *
+ * Propel keeps cached copies of objects in an instance pool when they are retrieved
+ * from the database. In some cases -- especially when you override doDelete
+ * methods in your stub classes -- you may need to explicitly remove objects
+ * from the cache in order to prevent returning objects that no longer exist.
+ *
+ * @param mixed $value A \Thelia\Model\ProductPrice object or a primary key value.
+ */
+ public static function removeInstanceFromPool($value)
+ {
+ if (Propel::isInstancePoolingEnabled() && null !== $value) {
+ if (is_object($value) && $value instanceof \Thelia\Model\ProductPrice) {
+ $key = serialize(array((string) $value->getProductSaleElementsId(), (string) $value->getCurrencyId()));
+
+ } elseif (is_array($value) && count($value) === 2) {
+ // assume we've been passed a primary key";
+ $key = serialize(array((string) $value[0], (string) $value[1]));
+ } elseif ($value instanceof Criteria) {
+ self::$instances = [];
+
+ return;
+ } else {
+ $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ProductPrice object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true)));
+ throw $e;
+ }
+
+ unset(self::$instances[$key]);
+ }
+ }
+
/**
* Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
*
@@ -200,11 +247,11 @@ class ProductPriceTableMap extends TableMap
public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
// If the PK cannot be derived from the row, return NULL.
- if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) {
+ if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('ProductSaleElementsId', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('CurrencyId', TableMap::TYPE_PHPNAME, $indexType)] === null) {
return null;
}
- return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
+ return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('ProductSaleElementsId', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('CurrencyId', TableMap::TYPE_PHPNAME, $indexType)]));
}
/**
@@ -222,11 +269,7 @@ class ProductPriceTableMap extends TableMap
public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
- return (int) $row[
- $indexType == TableMap::TYPE_NUM
- ? 0 + $offset
- : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)
- ];
+ return $pks;
}
/**
@@ -324,7 +367,6 @@ class ProductPriceTableMap extends TableMap
public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
- $criteria->addSelectColumn(ProductPriceTableMap::ID);
$criteria->addSelectColumn(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID);
$criteria->addSelectColumn(ProductPriceTableMap::CURRENCY_ID);
$criteria->addSelectColumn(ProductPriceTableMap::PRICE);
@@ -332,7 +374,6 @@ class ProductPriceTableMap extends TableMap
$criteria->addSelectColumn(ProductPriceTableMap::CREATED_AT);
$criteria->addSelectColumn(ProductPriceTableMap::UPDATED_AT);
} else {
- $criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.PRODUCT_SALE_ELEMENTS_ID');
$criteria->addSelectColumn($alias . '.CURRENCY_ID');
$criteria->addSelectColumn($alias . '.PRICE');
@@ -390,7 +431,17 @@ class ProductPriceTableMap extends TableMap
$criteria = $values->buildPkeyCriteria();
} else { // it's a primary key, or an array of pks
$criteria = new Criteria(ProductPriceTableMap::DATABASE_NAME);
- $criteria->add(ProductPriceTableMap::ID, (array) $values, Criteria::IN);
+ // primary key is composite; we therefore, expect
+ // the primary key passed to be an array of pkey values
+ if (count($values) == count($values, COUNT_RECURSIVE)) {
+ // array is not multi-dimensional
+ $values = array($values);
+ }
+ foreach ($values as $value) {
+ $criterion = $criteria->getNewCriterion(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID, $value[0]);
+ $criterion->addAnd($criteria->getNewCriterion(ProductPriceTableMap::CURRENCY_ID, $value[1]));
+ $criteria->addOr($criterion);
+ }
}
$query = ProductPriceQuery::create()->mergeWith($criteria);
@@ -436,10 +487,6 @@ class ProductPriceTableMap extends TableMap
$criteria = $criteria->buildCriteria(); // build Criteria from ProductPrice object
}
- if ($criteria->containsKey(ProductPriceTableMap::ID) && $criteria->keyContainsValue(ProductPriceTableMap::ID) ) {
- throw new PropelException('Cannot insert a value for auto-increment primary key ('.ProductPriceTableMap::ID.')');
- }
-
// Set the correct dbName
$query = ProductPriceQuery::create()->mergeWith($criteria);
diff --git a/core/lib/Thelia/Model/Map/TaxTableMap.php b/core/lib/Thelia/Model/Map/TaxTableMap.php
index 11e5047ce..6ca89ae85 100644
--- a/core/lib/Thelia/Model/Map/TaxTableMap.php
+++ b/core/lib/Thelia/Model/Map/TaxTableMap.php
@@ -57,7 +57,7 @@ class TaxTableMap extends TableMap
/**
* The total number of columns
*/
- const NUM_COLUMNS = 4;
+ const NUM_COLUMNS = 5;
/**
* The number of lazy-loaded columns
@@ -67,7 +67,7 @@ class TaxTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
- const NUM_HYDRATE_COLUMNS = 4;
+ const NUM_HYDRATE_COLUMNS = 5;
/**
* the column name for the ID field
@@ -75,9 +75,14 @@ class TaxTableMap extends TableMap
const ID = 'tax.ID';
/**
- * the column name for the RATE field
+ * the column name for the TYPE field
*/
- const RATE = 'tax.RATE';
+ const TYPE = 'tax.TYPE';
+
+ /**
+ * the column name for the SERIALIZED_REQUIREMENTS field
+ */
+ const SERIALIZED_REQUIREMENTS = 'tax.SERIALIZED_REQUIREMENTS';
/**
* the column name for the CREATED_AT field
@@ -110,12 +115,12 @@ class TaxTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
- self::TYPE_PHPNAME => array('Id', 'Rate', 'CreatedAt', 'UpdatedAt', ),
- self::TYPE_STUDLYPHPNAME => array('id', 'rate', 'createdAt', 'updatedAt', ),
- self::TYPE_COLNAME => array(TaxTableMap::ID, TaxTableMap::RATE, TaxTableMap::CREATED_AT, TaxTableMap::UPDATED_AT, ),
- self::TYPE_RAW_COLNAME => array('ID', 'RATE', 'CREATED_AT', 'UPDATED_AT', ),
- self::TYPE_FIELDNAME => array('id', 'rate', 'created_at', 'updated_at', ),
- self::TYPE_NUM => array(0, 1, 2, 3, )
+ self::TYPE_PHPNAME => array('Id', 'Type', 'SerializedRequirements', 'CreatedAt', 'UpdatedAt', ),
+ self::TYPE_STUDLYPHPNAME => array('id', 'type', 'serializedRequirements', 'createdAt', 'updatedAt', ),
+ self::TYPE_COLNAME => array(TaxTableMap::ID, TaxTableMap::TYPE, TaxTableMap::SERIALIZED_REQUIREMENTS, TaxTableMap::CREATED_AT, TaxTableMap::UPDATED_AT, ),
+ self::TYPE_RAW_COLNAME => array('ID', 'TYPE', 'SERIALIZED_REQUIREMENTS', 'CREATED_AT', 'UPDATED_AT', ),
+ self::TYPE_FIELDNAME => array('id', 'type', 'serialized_requirements', 'created_at', 'updated_at', ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, )
);
/**
@@ -125,12 +130,12 @@ class TaxTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
- self::TYPE_PHPNAME => array('Id' => 0, 'Rate' => 1, 'CreatedAt' => 2, 'UpdatedAt' => 3, ),
- self::TYPE_STUDLYPHPNAME => array('id' => 0, 'rate' => 1, 'createdAt' => 2, 'updatedAt' => 3, ),
- self::TYPE_COLNAME => array(TaxTableMap::ID => 0, TaxTableMap::RATE => 1, TaxTableMap::CREATED_AT => 2, TaxTableMap::UPDATED_AT => 3, ),
- self::TYPE_RAW_COLNAME => array('ID' => 0, 'RATE' => 1, 'CREATED_AT' => 2, 'UPDATED_AT' => 3, ),
- self::TYPE_FIELDNAME => array('id' => 0, 'rate' => 1, 'created_at' => 2, 'updated_at' => 3, ),
- self::TYPE_NUM => array(0, 1, 2, 3, )
+ self::TYPE_PHPNAME => array('Id' => 0, 'Type' => 1, 'SerializedRequirements' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ),
+ self::TYPE_STUDLYPHPNAME => array('id' => 0, 'type' => 1, 'serializedRequirements' => 2, 'createdAt' => 3, 'updatedAt' => 4, ),
+ self::TYPE_COLNAME => array(TaxTableMap::ID => 0, TaxTableMap::TYPE => 1, TaxTableMap::SERIALIZED_REQUIREMENTS => 2, TaxTableMap::CREATED_AT => 3, TaxTableMap::UPDATED_AT => 4, ),
+ self::TYPE_RAW_COLNAME => array('ID' => 0, 'TYPE' => 1, 'SERIALIZED_REQUIREMENTS' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ),
+ self::TYPE_FIELDNAME => array('id' => 0, 'type' => 1, 'serialized_requirements' => 2, 'created_at' => 3, 'updated_at' => 4, ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, )
);
/**
@@ -150,7 +155,8 @@ class TaxTableMap extends TableMap
$this->setUseIdGenerator(true);
// columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
- $this->addColumn('RATE', 'Rate', 'FLOAT', true, null, null);
+ $this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null);
+ $this->addColumn('SERIALIZED_REQUIREMENTS', 'SerializedRequirements', 'LONGVARCHAR', true, null, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -327,12 +333,14 @@ class TaxTableMap extends TableMap
{
if (null === $alias) {
$criteria->addSelectColumn(TaxTableMap::ID);
- $criteria->addSelectColumn(TaxTableMap::RATE);
+ $criteria->addSelectColumn(TaxTableMap::TYPE);
+ $criteria->addSelectColumn(TaxTableMap::SERIALIZED_REQUIREMENTS);
$criteria->addSelectColumn(TaxTableMap::CREATED_AT);
$criteria->addSelectColumn(TaxTableMap::UPDATED_AT);
} else {
$criteria->addSelectColumn($alias . '.ID');
- $criteria->addSelectColumn($alias . '.RATE');
+ $criteria->addSelectColumn($alias . '.TYPE');
+ $criteria->addSelectColumn($alias . '.SERIALIZED_REQUIREMENTS');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}
diff --git a/core/lib/Thelia/Model/Tax.php b/core/lib/Thelia/Model/Tax.php
index 21efbae6a..738f16508 100755
--- a/core/lib/Thelia/Model/Tax.php
+++ b/core/lib/Thelia/Model/Tax.php
@@ -4,6 +4,7 @@ namespace Thelia\Model;
use Thelia\Exception\TaxEngineException;
use Thelia\Model\Base\Tax as BaseTax;
+use Thelia\TaxEngine\TaxType\BaseTaxType;
class Tax extends BaseTax
{
@@ -33,14 +34,37 @@ class Tax extends BaseTax
return $taxRuleCountryPosition;
}
- public function getTaxRuleRateSum()
+ public function getTypeInstance()
{
- try {
- $taxRuleRateSum = $this->getVirtualColumn(TaxRuleQuery::ALIAS_FOR_TAX_RATE_SUM);
- } catch(PropelException $e) {
- throw new PropelException("Virtual column `" . TaxRuleQuery::ALIAS_FOR_TAX_RATE_SUM . "` does not exist in Tax::getTaxRuleRateSum");
+ $class = '\\Thelia\\TaxEngine\\TaxType\\' . $this->getType();
+
+ /* test type */
+ if(!class_exists($class)) {
+ throw new TaxEngineException('Recorded type does not exists', TaxEngineException::BAD_RECORDED_TYPE);
}
- return $taxRuleRateSum;
+ $instance = new $class;
+
+ if(!$instance instanceof BaseTaxType) {
+ throw new TaxEngineException('Recorded type does not extends BaseTaxType', TaxEngineException::BAD_RECORDED_TYPE);
+ }
+
+ return $instance;
+ }
+
+ public function setRequirements($requirements)
+ {
+ parent::setSerializedRequirements(base64_encode(json_encode($requirements)));
+ }
+
+ public function getRequirements()
+ {
+ $requirements = json_decode(base64_decode(parent::getSerializedRequirements()), true);
+
+ if(json_last_error() != JSON_ERROR_NONE || !is_array($requirements)) {
+ throw new TaxEngineException('BAD RECORDED REQUIREMENTS', TaxEngineException::BAD_RECORDED_REQUIREMENTS);
+ }
+
+ return $requirements;
}
}
diff --git a/core/lib/Thelia/Model/TaxRuleQuery.php b/core/lib/Thelia/Model/TaxRuleQuery.php
index f9c6cf1e5..d5ce47546 100755
--- a/core/lib/Thelia/Model/TaxRuleQuery.php
+++ b/core/lib/Thelia/Model/TaxRuleQuery.php
@@ -20,21 +20,18 @@ use Thelia\Model\Map\TaxTableMap;
class TaxRuleQuery extends BaseTaxRuleQuery
{
const ALIAS_FOR_TAX_RULE_COUNTRY_POSITION = 'taxRuleCountryPosition';
- const ALIAS_FOR_TAX_RATE_SUM = 'taxRateSum';
- public function getTaxCalculatorGroupedCollection(Product $product, Country $country)
+ public function getTaxCalculatorCollection(Product $product, Country $country)
{
$search = TaxQuery::create()
->filterByTaxRuleCountry(
TaxRuleCountryQuery::create()
->filterByCountry($country, Criteria::EQUAL)
->filterByTaxRuleId($product->getTaxRuleId())
- ->groupByPosition()
->orderByPosition()
->find()
)
->withColumn(TaxRuleCountryTableMap::POSITION, self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION)
- ->withColumn('ROUND(SUM(' . TaxTableMap::RATE . '), 2)', self::ALIAS_FOR_TAX_RATE_SUM)
;
return $search->find();
diff --git a/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php b/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php
index 5e5dae010..c7426ef71 100755
--- a/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php
+++ b/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php
@@ -110,7 +110,7 @@ class ModelCriteriaTools
{
// If a lang has been requested, find the related Lang object, and get the locale
if ($requestedLangId !== null) {
- $localeSearch = LangQuery::create()->findOneById($requestedLangId);
+ $localeSearch = LangQuery::create()->findPk($requestedLangId);
if ($localeSearch === null) {
throw new \InvalidArgumentException(sprintf('Incorrect lang argument given : lang ID %d not found', $requestedLangId));
diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php
index 145da3c02..9d76e08f3 100755
--- a/core/lib/Thelia/Module/BaseModule.php
+++ b/core/lib/Thelia/Module/BaseModule.php
@@ -46,9 +46,10 @@ abstract class BaseModule extends ContainerAware
public function getContainer()
{
- if($this->hasContainer() === false) {
+ if ($this->hasContainer() === false) {
throw new \RuntimeException("Sorry, container his not available in this context");
}
+
return $this->container;
}
diff --git a/core/lib/Thelia/Module/BaseModuleInterface.php b/core/lib/Thelia/Module/BaseModuleInterface.php
index 2db450830..5cfd98409 100644
--- a/core/lib/Thelia/Module/BaseModuleInterface.php
+++ b/core/lib/Thelia/Module/BaseModuleInterface.php
@@ -23,15 +23,14 @@
namespace Thelia\Module;
-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
-interface BaseModuleInterface {
-
+interface BaseModuleInterface
+{
public function setRequest(Request $request);
public function getRequest();
public function setDispatcher(EventDispatcherInterface $dispatcher);
public function getDispatcher();
-}
\ No newline at end of file
+}
diff --git a/core/lib/Thelia/Module/DeliveryModuleInterface.php b/core/lib/Thelia/Module/DeliveryModuleInterface.php
index b8ffcfc01..ba218ac4d 100644
--- a/core/lib/Thelia/Module/DeliveryModuleInterface.php
+++ b/core/lib/Thelia/Module/DeliveryModuleInterface.php
@@ -23,9 +23,8 @@
namespace Thelia\Module;
-
-interface DeliveryModuleInterface extends BaseModuleInterface {
-
+interface DeliveryModuleInterface extends BaseModuleInterface
+{
/**
*
* calculate and return delivery price
@@ -33,4 +32,4 @@ interface DeliveryModuleInterface extends BaseModuleInterface {
* @return mixed
*/
public function calculate($country = null);
-}
\ No newline at end of file
+}
diff --git a/core/lib/Thelia/TaxEngine/Calculator.php b/core/lib/Thelia/TaxEngine/Calculator.php
index 66c4fcbbf..2708e88c6 100755
--- a/core/lib/Thelia/TaxEngine/Calculator.php
+++ b/core/lib/Thelia/TaxEngine/Calculator.php
@@ -34,9 +34,12 @@ use Thelia\Model\TaxRuleQuery;
*/
class Calculator
{
+ /**
+ * @var TaxRuleQuery
+ */
protected $taxRuleQuery = null;
- protected $taxRulesGroupedCollection = null;
+ protected $taxRulesCollection = null;
protected $product = null;
protected $country = null;
@@ -50,7 +53,7 @@ class Calculator
{
$this->product = null;
$this->country = null;
- $this->taxRulesGroupedCollection = null;
+ $this->taxRulesCollection = null;
if($product->getId() === null) {
throw new TaxEngineException('Product id is empty in Calculator::load', TaxEngineException::UNDEFINED_PRODUCT);
@@ -62,34 +65,38 @@ class Calculator
$this->product = $product;
$this->country = $country;
- $this->taxRulesGroupedCollection = $this->taxRuleQuery->getTaxCalculatorGroupedCollection($product, $country);
+ $this->taxRulesCollection = $this->taxRuleQuery->getTaxCalculatorCollection($product, $country);
return $this;
}
- public function getTaxAmount($amount)
+ public function getTaxAmount($untaxedPrice)
{
- if(null === $this->taxRulesGroupedCollection) {
+ if(null === $this->taxRulesCollection) {
throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxAmount', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION);
}
- if(false === filter_var($amount, FILTER_VALIDATE_FLOAT)) {
+ if(false === filter_var($untaxedPrice, FILTER_VALIDATE_FLOAT)) {
throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT);
}
$totalTaxAmount = 0;
- foreach($this->taxRulesGroupedCollection as $taxRule) {
- $rateSum = $taxRule->getTaxRuleRateSum();
- $taxAmount = $amount * $rateSum * 0.01;
+ foreach($this->taxRulesCollection as $taxRule) {
+ $taxType = $taxRule->getTypeInstance();
+
+ $taxType->loadRequirements($taxRule->getRequirements());
+
+ $taxAmount = $taxType->calculate($untaxedPrice);
+
$totalTaxAmount += $taxAmount;
- $amount += $taxAmount;
+ $untaxedPrice += $taxAmount;
}
return $totalTaxAmount;
}
- public function getTaxedPrice($amount)
+ public function getTaxedPrice($untaxedPrice)
{
- return $amount + $this->getTaxAmount($amount);
+ return $untaxedPrice + $this->getTaxAmount($untaxedPrice);
}
}
diff --git a/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php
new file mode 100755
index 000000000..7f487bf64
--- /dev/null
+++ b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php
@@ -0,0 +1,78 @@
+. */
+/* */
+/*************************************************************************************/
+namespace Thelia\TaxEngine\TaxType;
+
+use Thelia\Exception\TaxEngineException;
+use Thelia\Type\TypeInterface;
+
+/**
+ *
+ * @author Etienne Roudeix |
{loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
- |
@@ -258,7 +258,7 @@
{loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
-
-
+
@@ -162,7 +162,7 @@
{loop name="cat-parent" type="category-tree" visible="*" category="0" exclude="{$current_category_id}"}
-
+
{/loop}
diff --git a/templates/admin/default/configuration.html b/templates/admin/default/configuration.html
index 75e9d523c..70b7cffb8 100644
--- a/templates/admin/default/configuration.html
+++ b/templates/admin/default/configuration.html
@@ -25,21 +25,21 @@
{loop type="auth" name="pcc1" roles="ADMIN" permissions="admin.configuration.product_templates"}
| ||||||||||
| {intl l='Product templates'} | -+ | ||||||||||
| {intl l='Product attributes'} | -+ | ||||||||||
| {intl l='Product features'} | -+ | ||||||||||
| {intl l='Title'} | -#TITLE | -
| {intl l='Expiration date'} | -#EXPIRATION_DATE | -
| {intl l='Usage left'} | -- {if #USAGE_LEFT} + |
| {intl l='Title'} | +{$TITLE} | +
| {intl l='Expiration date'} | +{$EXPIRATION_DATE} | +
| {intl l='Usage left'} | ++ {if $USAGE_LEFT} - #USAGE_LEFT + {$USAGE_LEFT} - {else} + {else} 0 - {/if} - | -
| #SHORT_DESCRIPTION | -|
| #DESCRIPTION | -|
| - {if #IS_CUMULATIVE} + {/if} + | +|
| {$SHORT_DESCRIPTION} | +|
| {$DESCRIPTION} | +|
| + {if $IS_CUMULATIVE} {intl l="May be cumulative"} @@ -66,53 +66,53 @@ {intl l="Can't be cumulative"} {/if} - | -|
| - {if #IS_REMOVING_POSTAGE} - + | +|
| + {if $IS_REMOVING_POSTAGE} + {intl l="Will remove postage"} - {else} - + {else} + {intl l="Won't remove postage"} - {/if} - | -|
| {intl l='Amount'} | -#AMOUNT | -
| {intl l='Application field'} | -
-
|
-
| {intl l='Actions'} | -- {intl l='Edit'} - {intl l='Enabled'} - | -
| {intl l='Amount'} | +{$AMOUNT} | +
| {intl l='Application field'} | +
+
|
+
| {intl l='Actions'} | ++ {intl l='Edit'} + {intl l='Enabled'} + | +
| + {intl l="customer ref"} + | - {ifloop rel="customer_list"} - -|||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| - {intl l="customer ref"} - | ++ {intl l="company"} + | -- {intl l="company"} - | + {module_include location='category_list_header'} - {module_include location='category_list_header'} ++ {intl l="firstname & lastname"} + | -- {intl l="firstname & lastname"} - | ++ {intl l="last order"} + | -- {intl l="last order"} - | +{intl l='order amount'} | -{intl l='order amount'} | +{intl l='Actions'} | +{intl l='Actions'} | -|
| {$REF} | -|||||||||||
| {#REF} | ++ {$COMPANY} + | -- {#COMPANY} - | ++ {$FIRSTNAME} {$LASTNAME} + | -- {#FIRSTNAME} {#LASTNAME} - | + {module_include location='customer_list_row'} - {module_include location='customer_list_row'} ++ {format_date date=$LASTORDER_DATE} + | -- {format_date date=$LASTORDER_DATE} - | ++ {format_number number=$LASTORDER_AMOUNT} + | +
+
-
-
- {format_number number=$LASTORDER_AMOUNT}
- |
-
- |
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.customer.edit"}
-
- {/loop}
- {loop type="auth" name="can_send_mail" roles="ADMIN" permissions="admin.customer.sendMail"}
-
- {/loop}
- {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.customer.delete"}
-
- {/loop}
-
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.customer.edit"}
+
+ {/loop}
+ {loop type="auth" name="can_send_mail" roles="ADMIN" permissions="admin.customer.sendMail"}
+
+ {/loop}
+ {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.customer.delete"}
+
+ {/loop}
+
+ |
-
-