+ * $query->filterByIsDefault(true); // WHERE is_default = true
+ * $query->filterByIsDefault('yes'); // WHERE is_default = true
+ *
+ *
+ * @param boolean|string $isDefault The value to use as filter.
+ * Non-boolean arguments are converted using the following rules:
+ * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
+ * * 0, '0', 'false', 'off', and 'no' are converted to boolean false
+ * Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
+ * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
+ *
+ * @return ChildTaxRuleQuery The current query, for fluid interface
+ */
+ public function filterByIsDefault($isDefault = null, $comparison = null)
+ {
+ if (is_string($isDefault)) {
+ $is_default = in_array(strtolower($isDefault), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
+ }
+
+ return $this->addUsingAlias(TaxRuleTableMap::IS_DEFAULT, $isDefault, $comparison);
+ }
+
/**
* Filter the query on the created_at column
*
diff --git a/core/lib/Thelia/Model/Map/TaxRuleTableMap.php b/core/lib/Thelia/Model/Map/TaxRuleTableMap.php
index 391e23b6d..ccc41e013 100644
--- a/core/lib/Thelia/Model/Map/TaxRuleTableMap.php
+++ b/core/lib/Thelia/Model/Map/TaxRuleTableMap.php
@@ -57,7 +57,7 @@ class TaxRuleTableMap extends TableMap
/**
* The total number of columns
*/
- const NUM_COLUMNS = 3;
+ const NUM_COLUMNS = 4;
/**
* The number of lazy-loaded columns
@@ -67,13 +67,18 @@ class TaxRuleTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
- const NUM_HYDRATE_COLUMNS = 3;
+ const NUM_HYDRATE_COLUMNS = 4;
/**
* the column name for the ID field
*/
const ID = 'tax_rule.ID';
+ /**
+ * the column name for the IS_DEFAULT field
+ */
+ const IS_DEFAULT = 'tax_rule.IS_DEFAULT';
+
/**
* the column name for the CREATED_AT field
*/
@@ -105,12 +110,12 @@ class TaxRuleTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
- self::TYPE_PHPNAME => array('Id', 'CreatedAt', 'UpdatedAt', ),
- self::TYPE_STUDLYPHPNAME => array('id', 'createdAt', 'updatedAt', ),
- self::TYPE_COLNAME => array(TaxRuleTableMap::ID, TaxRuleTableMap::CREATED_AT, TaxRuleTableMap::UPDATED_AT, ),
- self::TYPE_RAW_COLNAME => array('ID', 'CREATED_AT', 'UPDATED_AT', ),
- self::TYPE_FIELDNAME => array('id', 'created_at', 'updated_at', ),
- self::TYPE_NUM => array(0, 1, 2, )
+ self::TYPE_PHPNAME => array('Id', 'IsDefault', 'CreatedAt', 'UpdatedAt', ),
+ self::TYPE_STUDLYPHPNAME => array('id', 'isDefault', 'createdAt', 'updatedAt', ),
+ self::TYPE_COLNAME => array(TaxRuleTableMap::ID, TaxRuleTableMap::IS_DEFAULT, TaxRuleTableMap::CREATED_AT, TaxRuleTableMap::UPDATED_AT, ),
+ self::TYPE_RAW_COLNAME => array('ID', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ),
+ self::TYPE_FIELDNAME => array('id', 'is_default', 'created_at', 'updated_at', ),
+ self::TYPE_NUM => array(0, 1, 2, 3, )
);
/**
@@ -120,12 +125,12 @@ class TaxRuleTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
- self::TYPE_PHPNAME => array('Id' => 0, 'CreatedAt' => 1, 'UpdatedAt' => 2, ),
- self::TYPE_STUDLYPHPNAME => array('id' => 0, 'createdAt' => 1, 'updatedAt' => 2, ),
- self::TYPE_COLNAME => array(TaxRuleTableMap::ID => 0, TaxRuleTableMap::CREATED_AT => 1, TaxRuleTableMap::UPDATED_AT => 2, ),
- self::TYPE_RAW_COLNAME => array('ID' => 0, 'CREATED_AT' => 1, 'UPDATED_AT' => 2, ),
- self::TYPE_FIELDNAME => array('id' => 0, 'created_at' => 1, 'updated_at' => 2, ),
- self::TYPE_NUM => array(0, 1, 2, )
+ self::TYPE_PHPNAME => array('Id' => 0, 'IsDefault' => 1, 'CreatedAt' => 2, 'UpdatedAt' => 3, ),
+ self::TYPE_STUDLYPHPNAME => array('id' => 0, 'isDefault' => 1, 'createdAt' => 2, 'updatedAt' => 3, ),
+ self::TYPE_COLNAME => array(TaxRuleTableMap::ID => 0, TaxRuleTableMap::IS_DEFAULT => 1, TaxRuleTableMap::CREATED_AT => 2, TaxRuleTableMap::UPDATED_AT => 3, ),
+ self::TYPE_RAW_COLNAME => array('ID' => 0, 'IS_DEFAULT' => 1, 'CREATED_AT' => 2, 'UPDATED_AT' => 3, ),
+ self::TYPE_FIELDNAME => array('id' => 0, 'is_default' => 1, 'created_at' => 2, 'updated_at' => 3, ),
+ self::TYPE_NUM => array(0, 1, 2, 3, )
);
/**
@@ -145,6 +150,7 @@ class TaxRuleTableMap extends TableMap
$this->setUseIdGenerator(true);
// columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
+ $this->addColumn('IS_DEFAULT', 'IsDefault', 'BOOLEAN', true, 1, false);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -323,10 +329,12 @@ class TaxRuleTableMap extends TableMap
{
if (null === $alias) {
$criteria->addSelectColumn(TaxRuleTableMap::ID);
+ $criteria->addSelectColumn(TaxRuleTableMap::IS_DEFAULT);
$criteria->addSelectColumn(TaxRuleTableMap::CREATED_AT);
$criteria->addSelectColumn(TaxRuleTableMap::UPDATED_AT);
} else {
$criteria->addSelectColumn($alias . '.ID');
+ $criteria->addSelectColumn($alias . '.IS_DEFAULT');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}
diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php
index fbac7c71a..825668cd0 100755
--- a/core/lib/Thelia/Model/Product.php
+++ b/core/lib/Thelia/Model/Product.php
@@ -10,6 +10,8 @@ use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\ProductEvent;
use Propel\Runtime\ActiveQuery\Criteria;
+use Propel\Runtime\Propel;
+use Thelia\Model\Map\ProductTableMap;
class Product extends BaseProduct
{
@@ -41,11 +43,12 @@ class Product extends BaseProduct
public function getTaxedPrice(Country $country)
{
$taxCalculator = new Calculator();
- return round($taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice()), 2);
+
+ return $taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice());
}
/**
- * @return the current default category for this product
+ * @return the current default category ID for this product
*/
public function getDefaultCategoryId()
{
@@ -84,6 +87,72 @@ class Product extends BaseProduct
return $this;
}
+ /**
+ * Create a new product, along with the default category ID
+ *
+ * @param int $defaultCategoryId the default category ID of this product
+ */
+ public function create($defaultCategoryId) {
+
+ $con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
+
+ $con->beginTransaction();
+
+ $this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this));
+
+ try {
+ // Create the product
+ $this->save($con);
+
+ // Add the default category
+ $pc = new ProductCategory();
+
+ $pc
+ ->setProduct($this)
+ ->setCategoryId($defaultCategoryId)
+ ->setDefaultCategory(true)
+ ->save($con)
+ ;
+
+ // Set the position
+ $this->setPosition($this->getNextPosition())->save($con);
+
+ // Create an empty product sale element
+ $sale_elements = new ProductSaleElements();
+
+ $sale_elements
+ ->setProduct($this)
+ ->setRef($this->getRef())
+ ->setPromo(0)
+ ->setNewness(0)
+ ->setWeight(0)
+ ->save($con)
+ ;
+
+ // Create an empty product price in the default currency
+ $product_price = new ProductPrice();
+
+ $product_price
+ ->setProductSaleElements($sale_elements)
+ ->setPromoPrice(0)
+ ->setPrice(0)
+ ->setCurrency(CurrencyQuery::create()->findOneByByDefault(true))
+ ->save($con)
+ ;
+
+ // Store all the stuff !
+ $con->commit();
+
+ $this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this));
+ }
+ catch(\Exception $ex) {
+
+ $con->rollback();
+
+ throw $ex;
+ }
+ }
+
/**
* Calculate next position relative to our default category
*/
@@ -100,31 +169,7 @@ class Product extends BaseProduct
if ($produits != null) $query->filterById($produits, Criteria::IN);
}
- /**
- * {@inheritDoc}
- */
- public function preInsert(ConnectionInterface $con = null)
- {
- $this->setPosition($this->getNextPosition());
-
-
- $this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this));
-
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public function postInsert(ConnectionInterface $con = null)
- {
- $this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this));
- }
-
- /**
- * {@inheritDoc}
- */
public function preUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEPRODUCT, new ProductEvent($this));
@@ -157,5 +202,4 @@ class Product extends BaseProduct
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETEPRODUCT, new ProductEvent($this));
}
-
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php
index 2b31d265a..eb271d4c1 100755
--- a/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php
+++ b/core/lib/Thelia/Tests/Core/Template/Element/BaseLoopTestor.php
@@ -132,7 +132,7 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn);
}
- public function baseTestSearchById($id)
+ public function baseTestSearchById($id, $other_args = array())
{
$this->instance->initializeArgs(array_merge(
$this->getMandatoryArguments(),
@@ -140,7 +140,8 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
"type" => "foo",
"name" => "foo",
"id" => $id,
- )
+ ),
+ $other_args
));
$dummy = null;
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php
index 04e41b6f8..2b7019879 100644
--- a/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/DocumentTest.php
@@ -58,32 +58,27 @@ class DocumentTest extends BaseLoopTestor
{
$document = ProductDocumentQuery::create()->findOne();
- $this->baseTestSearchById($document->getId());
+ $this->baseTestSearchById($document->getId(), array('source' => 'product'));
}
public function testSearchByFolderId()
{
$document = FolderDocumentQuery::create()->findOne();
- $this->baseTestSearchById($document->getId());
+ $this->baseTestSearchById($document->getId(), array('source' => 'folder'));
}
public function testSearchByContentId()
{
$document = ContentDocumentQuery::create()->findOne();
- $this->baseTestSearchById($document->getId());
+ $this->baseTestSearchById($document->getId(), array('source' => 'content'));
}
public function testSearchByCategoryId()
{
$document = CategoryDocumentQuery::create()->findOne();
- $this->baseTestSearchById($document->getId());
- }
-
- public function testSearchLimit()
- {
- $this->baseTestSearchWithLimit(1);
+ $this->baseTestSearchById($document->getId(), array('source' => 'category'));
}
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php
index 3d2517c0a..ba4bfadc5 100644
--- a/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/ImageTest.php
@@ -58,32 +58,27 @@ class ImageTest extends BaseLoopTestor
{
$image = ProductImageQuery::create()->findOne();
- $this->baseTestSearchById($image->getId());
+ $this->baseTestSearchById($image->getId(), array('source' => 'product'));
}
public function testSearchByFolderId()
{
$image = FolderImageQuery::create()->findOne();
- $this->baseTestSearchById($image->getId());
+ $this->baseTestSearchById($image->getId(), array('source' => 'folder'));
}
public function testSearchByContentId()
{
$image = ContentImageQuery::create()->findOne();
- $this->baseTestSearchById($image->getId());
+ $this->baseTestSearchById($image->getId(), array('source' => 'content'));
}
public function testSearchByCategoryId()
{
$image = CategoryImageQuery::create()->findOne();
- $this->baseTestSearchById($image->getId());
- }
-
- public function testSearchLimit()
- {
- $this->baseTestSearchWithLimit(1);
+ $this->baseTestSearchById($image->getId(), array('source' => 'category'));
}
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php
index 1b307c5b5..07e179cbd 100755
--- a/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/ProductTest.php
@@ -27,6 +27,7 @@ use Thelia\Model\ProductQuery;
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
use Thelia\Core\Template\Loop\Product;
+use Propel\Runtime\ActiveQuery\Criteria;
/**
*
@@ -52,7 +53,7 @@ class ProductTest extends BaseLoopTestor
public function testSearchById()
{
- $product = ProductQuery::create()->findOne();
+ $product = ProductQuery::create()->orderById(Criteria::ASC)->findOne();
$this->baseTestSearchById($product->getId());
}
diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php
new file mode 100644
index 000000000..20523bfa5
--- /dev/null
+++ b/core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php
@@ -0,0 +1,60 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Tests\Core\Template\Loop;
+
+use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
+
+use Thelia\Core\Template\Loop\TaxRule;
+use Thelia\Model\TaxRuleQuery;
+
+/**
+ *
+ * @author Etienne Roudeix | - {admin_sortable_header - current_order=$category_order - order='id' - reverse_order='id_reverse' - path={url path='/admin/categories' id_category=$category_id} - request_parameter_name='category_order' - label="{intl l='ID'}" - } - | + {ifloop rel="category_list"} + +|||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| + {admin_sortable_header + current_order=$category_order + order='id' + reverse_order='id_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='ID'}" + } + | -+ | - | - {admin_sortable_header - current_order=$category_order - order='alpha' - reverse_order='alpha_reverse' - path={url path='/admin/categories' id_category=$category_id} - request_parameter_name='category_order' - label="{intl l='Category title'}" - } - | ++ {admin_sortable_header + current_order=$category_order + order='alpha' + reverse_order='alpha_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='Category title'}" + } + | - {module_include location='category_list_header'} + {module_include location='category_list_header'} -- {admin_sortable_header - current_order=$category_order - order='visible' - reverse_order='visible_reverse' - path={url path='/admin/categories' id_category=$category_id} - request_parameter_name='category_order' - label="{intl l='Online'}" - } - | ++ {admin_sortable_header + current_order=$category_order + order='visible' + reverse_order='visible_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='Online'}" + } + | -- {admin_sortable_header - current_order=$category_order - order='manual' - reverse_order='manual_reverse' - path={url path='/admin/categories' id_category=$category_id} - request_parameter_name='category_order' - label="{intl l='Position'}" - } - | ++ {admin_sortable_header + current_order=$category_order + order='manual' + reverse_order='manual_reverse' + path={url path='/admin/categories' id_category=$category_id} + request_parameter_name='category_order' + label="{intl l='Position'}" + } + | -{intl l='Actions'} | -{intl l='Actions'} | +|
| {$ID} | +|||||||||||
| {$ID} | -
- {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
- |
+
+ {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
+ |
- - - {$TITLE} - - | ++ + {$TITLE} + + | - {module_include location='category_list_row'} + {module_include location='category_list_row'} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
-
-
-
- {/loop}
+ |
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
+
+
+
+ {/loop}
- {elseloop rel="can_change"}
-
-
-
- {/elseloop}
- |
+ {elseloop rel="can_change"}
+ - {admin_position_block - permission="admin.categories.edit" - path={url path='admin/categories/update-position' category_id=$ID} - url_parameter="category_id" - in_place_edit_class="categoryPositionChange" - position=$POSITION - id=$ID - } - | ++ {admin_position_block + permission="admin.categories.edit" + path={url path='admin/categories/update-position' category_id=$ID} + url_parameter="category_id" + in_place_edit_class="categoryPositionChange" + position=$POSITION + id=$ID + } + | -
-
-
+
+ |
-
+
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
-
- {/loop}
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
+
+ {/loop}
- {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.categories.delete"}
-
- {/loop}
-
- | |
- {admin_sortable_header
- current_order=$product_order
- order='id'
- reverse_order='id_reverse'
- path={url path='/admin/categories' id_category=$category_id target='products'}
- label="{intl l='ID'}"
- }
+ {ifloop rel="product_list"}
+
+ |
+ {admin_sortable_header
+ current_order=$product_order
+ order='id'
+ reverse_order='id_reverse'
+ path={url path='/admin/categories' id_category=$category_id target='products'}
+ label="{intl l='ID'}"
+ }
- | |
+ |
-
- {admin_sortable_header
- current_order=$product_order
- order='ref'
- reverse_order='ref_reverse'
- path={url path='/admin/categories' id_category=$category_id target='products'}
- label="{intl l='Reference'}"
- }
- |
+
+ {admin_sortable_header
+ current_order=$product_order
+ order='ref'
+ reverse_order='ref_reverse'
+ path={url path='/admin/categories' id_category=$category_id target='products'}
+ label="{intl l='Reference'}"
+ }
+ |
-
- {admin_sortable_header
- current_order=$product_order
- order='alpha'
- reverse_order='alpha_reverse'
- path={url path='/admin/categories' id_category=$category_id target='products'}
- label="{intl l='Product title'}"
- }
+ |
+ {admin_sortable_header
+ current_order=$product_order
+ order='alpha'
+ reverse_order='alpha_reverse'
+ path={url path='/admin/categories' id_category=$category_id target='products'}
+ label="{intl l='Product title'}"
+ }
- {module_include location='product_list_header'}
+ {module_include location='product_list_header'}
- |
- {admin_sortable_header
- current_order=$product_order
- order='visible'
- reverse_order='visible_reverse'
- path={url path='/admin/categories' id_category=$category_id target='products'}
- label="{intl l='Online'}"
- }
- |
+
+ {admin_sortable_header
+ current_order=$product_order
+ order='visible'
+ reverse_order='visible_reverse'
+ path={url path='/admin/categories' id_category=$category_id target='products'}
+ label="{intl l='Online'}"
+ }
+ |
-
- {admin_sortable_header
- current_order=$product_order
- order='manual'
- reverse_order='manual_reverse'
- path={url path='/admin/categories' id_category=$category_id target='products'}
- label="{intl l='Position'}"
- }
- |
+
+ {admin_sortable_header
+ current_order=$product_order
+ order='manual'
+ reverse_order='manual_reverse'
+ path={url path='/admin/categories' id_category=$category_id target='products'}
+ label="{intl l='Position'}"
+ }
+ |
- |
- | + |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {$ID} | +|||||||||||||
| {$ID} | -
- {loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
-
- |
+ {loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
+
+ | {$REF} | +{$REF} | -{$TITLE} | +{$TITLE} | - {module_include location='product_list_row'} + {module_include location='product_list_row'} -
- {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"}
-
-
-
- {/loop}
+ |
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"}
+
+
+
+ {/loop}
- {elseloop rel="can_delete"}
-
-
-
- {/elseloop}
- |
+ {elseloop rel="can_change"}
+ - {admin_position_block - permission="admin.product.edit" - path={url path='admin/product' category_id=$ID} - url_parameter="product_id" - in_place_edit_class="productPositionChange" - position=$POSITION - id=$ID - } - | ++ {admin_position_block + permission="admin.product.edit" + path={url path='/admin/products/update-position' product_id=$ID} + url_parameter="product_id" + in_place_edit_class="productPositionChange" + position=$POSITION + id=$ID + } + | -- | ||