Conflicts:
	core/lib/Thelia/Model/Product.php
This commit is contained in:
franck
2013-09-17 23:51:31 +02:00
27 changed files with 995 additions and 543 deletions

View File

@@ -40,6 +40,7 @@ use Thelia\Core\Event\ProductAddContentEvent;
use Thelia\Core\Event\ProductDeleteContentEvent;
use Thelia\Model\ProductAssociatedContent;
use Thelia\Model\ProductAssociatedContentQuery;
use Thelia\Model\ProductCategory;
class Product extends BaseAction implements EventSubscriberInterface
{
@@ -55,13 +56,13 @@ class Product extends BaseAction implements EventSubscriberInterface
$product
->setDispatcher($this->getDispatcher())
->setLocale($event->getLocale())
->setRef($event->getRef())
->setTitle($event->getTitle())
->setParent($event->getParent())
->setLocale($event->getLocale())
->setVisible($event->getVisible())
->save()
;
->create($event->getDefaultCategory())
;
$event->setProduct($product);
}

View File

@@ -133,7 +133,7 @@ class CategoryController extends AbstractCrudController
'description' => $object->getDescription(),
'postscriptum' => $object->getPostscriptum(),
'visible' => $object->getVisible(),
'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()),
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
'parent' => $object->getParent()
);

View File

@@ -83,9 +83,10 @@ class ProductController extends AbstractCrudController
$createEvent = new ProductCreateEvent();
$createEvent
->setRef($formData['ref'])
->setTitle($formData['title'])
->setLocale($formData["locale"])
->setParent($formData['parent'])
->setLocale($formData['locale'])
->setDefaultCategory($formData['default_category'])
->setVisible($formData['visible'])
;
@@ -134,15 +135,15 @@ class ProductController extends AbstractCrudController
{
// Prepare the data that will hydrate the form
$data = array(
'id' => $object->getId(),
'locale' => $object->getLocale(),
'title' => $object->getTitle(),
'chapo' => $object->getChapo(),
'description' => $object->getDescription(),
'postscriptum' => $object->getPostscriptum(),
'visible' => $object->getVisible(),
'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()),
'parent' => $object->getParent()
'id' => $object->getId(),
'locale' => $object->getLocale(),
'title' => $object->getTitle(),
'chapo' => $object->getChapo(),
'description' => $object->getDescription(),
'postscriptum' => $object->getPostscriptum(),
'visible' => $object->getVisible(),
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
'default_category' => $object->getDefaultCategoryId()
);
// Setup the object form
@@ -174,12 +175,26 @@ class ProductController extends AbstractCrudController
protected function getEditionArguments()
{
return array(
'product_id' => $this->getRequest()->get('product_id', 0),
'folder_id' => $this->getRequest()->get('folder_id', 0),
'category_id' => $this->getCategoryId(),
'product_id' => $this->getRequest()->get('product_id', 0),
'folder_id' => $this->getRequest()->get('folder_id', 0),
'current_tab' => $this->getRequest()->get('current_tab', 'general')
);
}
protected function getCategoryId() {
// Trouver le category_id, soit depuis la reques, souit depuis le produit courant
$category_id = $this->getRequest()->get('category_id', null);
if ($category_id == null) {
$product = $this->getExistingObject();
if ($product !== null) $category_id = $product->getDefaultCategoryId();
}
return $category_id != null ? $category_id : 0;
}
protected function renderListTemplate($currentOrder)
{
$this->getListOrderFromSession('product', 'product_order', 'manual');
@@ -187,18 +202,15 @@ class ProductController extends AbstractCrudController
return $this->render('categories',
array(
'product_order' => $currentOrder,
'product_id' => $this->getRequest()->get('product_id', 0)
'category_id' => $this->getCategoryId()
));
}
protected function redirectToListTemplate()
{
// Redirect to the product default category list
$product = $this->getExistingObject();
$this->redirectToRoute(
'admin.products.default',
array('category_id' => $product != null ? $product->getDefaultCategory() : 0)
array('category_id' => $this->getCategoryId())
);
}
@@ -238,7 +250,7 @@ class ProductController extends AbstractCrudController
// Redirect to parent product list
$this->redirectToRoute(
'admin.products.default',
array('category_id' => $deleteEvent->getProduct()->getDefaultCategory())
array('category_id' => $deleteEvent->getProduct()->getDefaultCategoryId())
);
}
@@ -249,24 +261,18 @@ class ProductController extends AbstractCrudController
// Redirect to parent product list
$this->redirectToRoute(
'admin.categories.default',
array('category_id' => $product->getDefaultCategory())
array('category_id' => $updateEvent->getProduct()->getDefaultCategoryId())
);
}
}
protected function performAdditionalUpdatePositionAction($event)
protected function performAdditionalUpdatePositionAction($positionEvent)
{
$product = ProductQuery::create()->findPk($event->getObjectId());
if ($product != null) {
// Redirect to parent product list
$this->redirectToRoute(
'admin.categories.default',
array('category_id' => $product->getDefaultCategory())
);
}
return null;
// Redirect to parent product list
$this->redirectToRoute(
'admin.categories.default',
array('category_id' => $positionEvent->getProduct()->getDefaultCategoryId())
);
}
public function getAvailableRelatedContentAction($productId, $folderId)

View File

@@ -25,11 +25,23 @@ namespace Thelia\Core\Event;
class ProductCreateEvent extends ProductEvent
{
protected $ref;
protected $title;
protected $parent;
protected $locale;
protected $default_category;
protected $visible;
public function getRef()
{
return $this->ref;
}
public function setRef($ref)
{
$this->ref = $ref;
return $this;
}
public function getTitle()
{
return $this->title;
@@ -38,19 +50,6 @@ class ProductCreateEvent extends ProductEvent
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function getParent()
{
return $this->parent;
}
public function setParent($parent)
{
$this->parent = $parent;
return $this;
}
@@ -62,7 +61,17 @@ class ProductCreateEvent extends ProductEvent
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
public function getDefaultCategory()
{
return $this->default_category;
}
public function setDefaultCategory($default_category)
{
$this->default_category = $default_category;
return $this;
}
@@ -74,7 +83,6 @@ class ProductCreateEvent extends ProductEvent
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
}

View File

@@ -598,31 +598,59 @@ class Product extends BaseI18nLoop
$loopResult = new LoopResult($products);
foreach ($products as $product) {
$loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable);
$price = $product->getRealLowestPrice();
$taxedPrice = $product->getTaxedPrice(
CountryQuery::create()->findOneById(64) // @TODO : make it magic
);
// Find previous and next product, in the default category.
$default_category_id = $product->getDefaultCategoryId();
$loopResultRow->set("ID", $product->getId())
->set("REF",$product->getRef())
->set("IS_TRANSLATED",$product->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)
->set("TITLE",$product->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $product->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $product->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("URL", $product->getUrl($locale))
->set("BEST_PRICE", $price)
->set("BEST_PRICE_TAX", $taxedPrice - $price)
->set("BEST_TAXED_PRICE", $taxedPrice)
->set("IS_PROMO", $product->getVirtualColumn('main_product_is_promo'))
->set("IS_NEW", $product->getVirtualColumn('main_product_is_new'))
->set("POSITION", $product->getPosition())
$previous = ProductQuery::create()
->joinProductCategory()
->where('ProductCategory.category_id = ?', $default_category_id)
->filterByPosition($product->getPosition(), Criteria::LESS_THAN)
->orderByPosition(Criteria::DESC)
->findOne()
;
$next = ProductQuery::create()
->joinProductCategory()
->where('ProductCategory.category_id = ?', $default_category_id)
->filterByPosition($product->getPosition(), Criteria::GREATER_THAN)
->orderByPosition(Criteria::ASC)
->findOne()
;
$loopResultRow
->set("ID" , $product->getId())
->set("REF" , $product->getRef())
->set("IS_TRANSLATED" , $product->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale)
->set("TITLE" , $product->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $product->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $product->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("URL" , $product->getUrl($locale))
->set("BEST_PRICE" , $price)
->set("BEST_PRICE_TAX" , $taxedPrice - $price)
->set("BEST_TAXED_PRICE" , $taxedPrice)
->set("IS_PROMO" , $product->getVirtualColumn('main_product_is_promo'))
->set("IS_NEW" , $product->getVirtualColumn('main_product_is_new'))
->set("POSITION" , $product->getPosition())
->set("VISIBLE" , $product->getVisible() ? "1" : "0")
->set("HAS_PREVIOUS" , $previous != null ? 1 : 0)
->set("HAS_NEXT" , $next != null ? 1 : 0)
->set("PREVIOUS" , $previous != null ? $previous->getId() : -1)
->set("NEXT" , $next != null ? $next->getId() : -1)
->set("DEFAULT_CATEGORY" , $default_category_id)
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -23,16 +23,26 @@
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ProductQuery;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\ExecutionContextInterface;
class ProductCreationForm extends BaseForm
{
protected function buildForm()
protected function buildForm($change_mode = false)
{
$ref_constraints = array(new NotBlank());
if (! $change_mode) {
$ref_constraints[] = new Callback(array(
"methods" => array(array($this, "checkDuplicateRef"))
));
}
$this->formBuilder
->add("ref", "text", array(
"constraints" => array(
new NotBlank()
),
"constraints" => $ref_constraints,
"label" => "Product reference *",
"label_attr" => array(
"for" => "ref"
@@ -64,6 +74,19 @@ class ProductCreationForm extends BaseForm
;
}
public function checkDuplicateRef($value, ExecutionContextInterface $context)
{
$count = ProductQuery::create()->filterByRef($value)->count();
if ($count > 0) {
$context->addViolation(
Translator::getInstance()->trans(
"A product with reference %ref already exists. Please choose another reference.",
array('%ref' => $value)
));
}
}
public function getName()
{
return "thelia_product_creation";

View File

@@ -857,7 +857,7 @@ abstract class ProductQuery extends ModelCriteria
*
* @return ChildProductQuery The current query, for fluid interface
*/
public function joinTemplate($relationAlias = null, $joinType = Criteria::INNER_JOIN)
public function joinTemplate($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Template');
@@ -892,7 +892,7 @@ abstract class ProductQuery extends ModelCriteria
*
* @return \Thelia\Model\TemplateQuery A secondary query class using the current class as primary query
*/
public function useTemplateQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
public function useTemplateQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinTemplate($relationAlias, $joinType)

View File

@@ -77,6 +77,13 @@ abstract class Tax implements ActiveRecordInterface
*/
protected $serialized_requirements;
/**
* The value for the is_default field.
* Note: this column has a database default value of: false
* @var boolean
*/
protected $is_default;
/**
* The value for the created_at field.
* @var string
@@ -135,11 +142,24 @@ abstract class Tax implements ActiveRecordInterface
*/
protected $taxI18nsScheduledForDeletion = null;
/**
* Applies default values to this object.
* This method should be called from the object's constructor (or
* equivalent initialization method).
* @see __construct()
*/
public function applyDefaultValues()
{
$this->is_default = false;
}
/**
* Initializes internal state of Thelia\Model\Base\Tax object.
* @see applyDefaults()
*/
public function __construct()
{
$this->applyDefaultValues();
}
/**
@@ -422,6 +442,17 @@ abstract class Tax implements ActiveRecordInterface
return $this->serialized_requirements;
}
/**
* Get the [is_default] column value.
*
* @return boolean
*/
public function getIsDefault()
{
return $this->is_default;
}
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -525,6 +556,35 @@ abstract class Tax implements ActiveRecordInterface
return $this;
} // setSerializedRequirements()
/**
* Sets the value of the [is_default] column.
* 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 boolean|integer|string $v The new value
* @return \Thelia\Model\Tax The current object (for fluent API support)
*/
public function setIsDefault($v)
{
if ($v !== null) {
if (is_string($v)) {
$v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
} else {
$v = (boolean) $v;
}
}
if ($this->is_default !== $v) {
$this->is_default = $v;
$this->modifiedColumns[] = TaxTableMap::IS_DEFAULT;
}
return $this;
} // setIsDefault()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -577,6 +637,10 @@ abstract class Tax implements ActiveRecordInterface
*/
public function hasOnlyDefaultValues()
{
if ($this->is_default !== false) {
return false;
}
// otherwise, everything was equal, so return TRUE
return true;
} // hasOnlyDefaultValues()
@@ -613,13 +677,16 @@ abstract class Tax implements ActiveRecordInterface
$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)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : TaxTableMap::translateFieldName('IsDefault', TableMap::TYPE_PHPNAME, $indexType)];
$this->is_default = (null !== $col) ? (boolean) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $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 ? 4 + $startcol : TaxTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : TaxTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -632,7 +699,7 @@ abstract class Tax implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 5; // 5 = TaxTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 6; // 6 = TaxTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\Tax object", 0, $e);
@@ -899,6 +966,9 @@ abstract class Tax implements ActiveRecordInterface
if ($this->isColumnModified(TaxTableMap::SERIALIZED_REQUIREMENTS)) {
$modifiedColumns[':p' . $index++] = 'SERIALIZED_REQUIREMENTS';
}
if ($this->isColumnModified(TaxTableMap::IS_DEFAULT)) {
$modifiedColumns[':p' . $index++] = 'IS_DEFAULT';
}
if ($this->isColumnModified(TaxTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
}
@@ -925,6 +995,9 @@ abstract class Tax implements ActiveRecordInterface
case 'SERIALIZED_REQUIREMENTS':
$stmt->bindValue($identifier, $this->serialized_requirements, PDO::PARAM_STR);
break;
case 'IS_DEFAULT':
$stmt->bindValue($identifier, (int) $this->is_default, PDO::PARAM_INT);
break;
case 'CREATED_AT':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1003,9 +1076,12 @@ abstract class Tax implements ActiveRecordInterface
return $this->getSerializedRequirements();
break;
case 3:
return $this->getCreatedAt();
return $this->getIsDefault();
break;
case 4:
return $this->getCreatedAt();
break;
case 5:
return $this->getUpdatedAt();
break;
default:
@@ -1040,8 +1116,9 @@ abstract class Tax implements ActiveRecordInterface
$keys[0] => $this->getId(),
$keys[1] => $this->getType(),
$keys[2] => $this->getSerializedRequirements(),
$keys[3] => $this->getCreatedAt(),
$keys[4] => $this->getUpdatedAt(),
$keys[3] => $this->getIsDefault(),
$keys[4] => $this->getCreatedAt(),
$keys[5] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach($virtualColumns as $key => $virtualColumn)
@@ -1100,9 +1177,12 @@ abstract class Tax implements ActiveRecordInterface
$this->setSerializedRequirements($value);
break;
case 3:
$this->setCreatedAt($value);
$this->setIsDefault($value);
break;
case 4:
$this->setCreatedAt($value);
break;
case 5:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1132,8 +1212,9 @@ abstract class Tax implements ActiveRecordInterface
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
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]]);
if (array_key_exists($keys[3], $arr)) $this->setIsDefault($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]);
}
/**
@@ -1148,6 +1229,7 @@ abstract class Tax implements ActiveRecordInterface
if ($this->isColumnModified(TaxTableMap::ID)) $criteria->add(TaxTableMap::ID, $this->id);
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::IS_DEFAULT)) $criteria->add(TaxTableMap::IS_DEFAULT, $this->is_default);
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);
@@ -1215,6 +1297,7 @@ abstract class Tax implements ActiveRecordInterface
{
$copyObj->setType($this->getType());
$copyObj->setSerializedRequirements($this->getSerializedRequirements());
$copyObj->setIsDefault($this->getIsDefault());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
@@ -1788,10 +1871,12 @@ abstract class Tax implements ActiveRecordInterface
$this->id = null;
$this->type = null;
$this->serialized_requirements = null;
$this->is_default = null;
$this->created_at = null;
$this->updated_at = null;
$this->alreadyInSave = false;
$this->clearAllReferences();
$this->applyDefaultValues();
$this->resetModified();
$this->setNew(true);
$this->setDeleted(false);

View File

@@ -25,12 +25,14 @@ use Thelia\Model\Map\TaxTableMap;
* @method ChildTaxQuery orderById($order = Criteria::ASC) Order by the id 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 orderByIsDefault($order = Criteria::ASC) Order by the is_default 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 groupByType() Group by the type column
* @method ChildTaxQuery groupBySerializedRequirements() Group by the serialized_requirements column
* @method ChildTaxQuery groupByIsDefault() Group by the is_default column
* @method ChildTaxQuery groupByCreatedAt() Group by the created_at column
* @method ChildTaxQuery groupByUpdatedAt() Group by the updated_at column
*
@@ -52,12 +54,14 @@ use Thelia\Model\Map\TaxTableMap;
* @method ChildTax findOneById(int $id) Return the first ChildTax filtered by the id 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 findOneByIsDefault(boolean $is_default) Return the first ChildTax filtered by the is_default 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 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 findByIsDefault(boolean $is_default) Return ChildTax objects filtered by the is_default 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
*
@@ -148,7 +152,7 @@ abstract class TaxQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, TYPE, SERIALIZED_REQUIREMENTS, CREATED_AT, UPDATED_AT FROM tax WHERE ID = :p0';
$sql = 'SELECT ID, TYPE, SERIALIZED_REQUIREMENTS, IS_DEFAULT, CREATED_AT, UPDATED_AT FROM tax WHERE ID = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -336,6 +340,33 @@ abstract class TaxQuery extends ModelCriteria
return $this->addUsingAlias(TaxTableMap::SERIALIZED_REQUIREMENTS, $serializedRequirements, $comparison);
}
/**
* Filter the query on the is_default column
*
* Example usage:
* <code>
* $query->filterByIsDefault(true); // WHERE is_default = true
* $query->filterByIsDefault('yes'); // WHERE is_default = true
* </code>
*
* @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 ChildTaxQuery 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(TaxTableMap::IS_DEFAULT, $isDefault, $comparison);
}
/**
* Filter the query on the created_at column
*

View File

@@ -864,9 +864,10 @@ abstract class Template implements ActiveRecordInterface
if ($this->productsScheduledForDeletion !== null) {
if (!$this->productsScheduledForDeletion->isEmpty()) {
\Thelia\Model\ProductQuery::create()
->filterByPrimaryKeys($this->productsScheduledForDeletion->getPrimaryKeys(false))
->delete($con);
foreach ($this->productsScheduledForDeletion as $product) {
// need to save related object because we set the relation to null
$product->save($con);
}
$this->productsScheduledForDeletion = null;
}
}
@@ -1553,7 +1554,7 @@ abstract class Template implements ActiveRecordInterface
$this->productsScheduledForDeletion = clone $this->collProducts;
$this->productsScheduledForDeletion->clear();
}
$this->productsScheduledForDeletion[]= clone $product;
$this->productsScheduledForDeletion[]= $product;
$product->setTemplate(null);
}

View File

@@ -395,7 +395,7 @@ abstract class TemplateQuery extends ModelCriteria
*
* @return ChildTemplateQuery The current query, for fluid interface
*/
public function joinProduct($relationAlias = null, $joinType = Criteria::INNER_JOIN)
public function joinProduct($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Product');
@@ -430,7 +430,7 @@ abstract class TemplateQuery extends ModelCriteria
*
* @return \Thelia\Model\ProductQuery A secondary query class using the current class as primary query
*/
public function useProductQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
public function useProductQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinProduct($relationAlias, $joinType)

View File

@@ -28,7 +28,7 @@ class Category extends BaseCategory
/**
* {@inheritDoc}
*/
protected function getRewritenUrlViewName() {
protected function getRewrittenUrlViewName() {
return 'category';
}
@@ -69,8 +69,6 @@ class Category extends BaseCategory
{
$this->setPosition($this->getNextPosition());
$this->generateRewritenUrl($this->getLocale());
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECATEGORY, new CategoryEvent($this));
return true;
@@ -81,6 +79,7 @@ class Category extends BaseCategory
*/
public function postInsert(ConnectionInterface $con = null)
{
//$this->generateRewrittenUrl($this->getLocale());
$this->dispatchEvent(TheliaEvents::AFTER_CREATECATEGORY, new CategoryEvent($this));
}

View File

@@ -17,7 +17,7 @@ class Content extends BaseContent
/**
* {@inheritDoc}
*/
protected function getRewritenUrlViewName() {
protected function getRewrittenUrlViewName() {
return 'content';
}
@@ -37,8 +37,11 @@ class Content extends BaseContent
{
$this->setPosition($this->getNextPosition());
$this->generateRewritenUrl($this->getLocale());
return true;
}
public function postInsert(ConnectionInterface $con = null)
{
//$this->generateRewrittenUrl($this->getLocale());
}
}

View File

@@ -17,7 +17,7 @@ class Folder extends BaseFolder
/**
* {@inheritDoc}
*/
protected function getRewritenUrlViewName() {
protected function getRewrittenUrlViewName() {
return 'folder';
}
@@ -67,8 +67,12 @@ class Folder extends BaseFolder
{
$this->setPosition($this->getNextPosition());
$this->generateRewritenUrl($this->getLocale());
return true;
}
public function postInsert(ConnectionInterface $con = null)
{
//$this->generateRewrittenUrl($this->getLocale());
}
}

View File

@@ -189,7 +189,7 @@ class ProductTableMap extends TableMap
$this->addColumn('REF', 'Ref', 'VARCHAR', true, 255, null);
$this->addColumn('VISIBLE', 'Visible', 'TINYINT', true, null, 0);
$this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null);
$this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', true, null, null);
$this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', false, null, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('VERSION', 'Version', 'INTEGER', false, null, 0);

View File

@@ -180,7 +180,7 @@ class ProductVersionTableMap extends TableMap
$this->addColumn('REF', 'Ref', 'VARCHAR', true, 255, null);
$this->addColumn('VISIBLE', 'Visible', 'TINYINT', true, null, 0);
$this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null);
$this->addColumn('TEMPLATE_ID', 'TemplateId', 'INTEGER', true, null, null);
$this->addColumn('TEMPLATE_ID', 'TemplateId', 'INTEGER', false, null, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
$this->addPrimaryKey('VERSION', 'Version', 'INTEGER', true, null, 0);

View File

@@ -57,7 +57,7 @@ class TaxTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 5;
const NUM_COLUMNS = 6;
/**
* 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 = 5;
const NUM_HYDRATE_COLUMNS = 6;
/**
* the column name for the ID field
@@ -84,6 +84,11 @@ class TaxTableMap extends TableMap
*/
const SERIALIZED_REQUIREMENTS = 'tax.SERIALIZED_REQUIREMENTS';
/**
* the column name for the IS_DEFAULT field
*/
const IS_DEFAULT = 'tax.IS_DEFAULT';
/**
* the column name for the CREATED_AT field
*/
@@ -115,12 +120,12 @@ class TaxTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
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, )
self::TYPE_PHPNAME => array('Id', 'Type', 'SerializedRequirements', 'IsDefault', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('id', 'type', 'serializedRequirements', 'isDefault', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(TaxTableMap::ID, TaxTableMap::TYPE, TaxTableMap::SERIALIZED_REQUIREMENTS, TaxTableMap::IS_DEFAULT, TaxTableMap::CREATED_AT, TaxTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('ID', 'TYPE', 'SERIALIZED_REQUIREMENTS', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('id', 'type', 'serialized_requirements', 'is_default', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
);
/**
@@ -130,12 +135,12 @@ class TaxTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
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, )
self::TYPE_PHPNAME => array('Id' => 0, 'Type' => 1, 'SerializedRequirements' => 2, 'IsDefault' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'type' => 1, 'serializedRequirements' => 2, 'isDefault' => 3, 'createdAt' => 4, 'updatedAt' => 5, ),
self::TYPE_COLNAME => array(TaxTableMap::ID => 0, TaxTableMap::TYPE => 1, TaxTableMap::SERIALIZED_REQUIREMENTS => 2, TaxTableMap::IS_DEFAULT => 3, TaxTableMap::CREATED_AT => 4, TaxTableMap::UPDATED_AT => 5, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'TYPE' => 1, 'SERIALIZED_REQUIREMENTS' => 2, 'IS_DEFAULT' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ),
self::TYPE_FIELDNAME => array('id' => 0, 'type' => 1, 'serialized_requirements' => 2, 'is_default' => 3, 'created_at' => 4, 'updated_at' => 5, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
);
/**
@@ -157,6 +162,7 @@ class TaxTableMap extends TableMap
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('TYPE', 'Type', 'VARCHAR', true, 255, null);
$this->addColumn('SERIALIZED_REQUIREMENTS', 'SerializedRequirements', 'LONGVARCHAR', true, null, null);
$this->addColumn('IS_DEFAULT', 'IsDefault', 'BOOLEAN', false, 1, false);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -335,12 +341,14 @@ class TaxTableMap extends TableMap
$criteria->addSelectColumn(TaxTableMap::ID);
$criteria->addSelectColumn(TaxTableMap::TYPE);
$criteria->addSelectColumn(TaxTableMap::SERIALIZED_REQUIREMENTS);
$criteria->addSelectColumn(TaxTableMap::IS_DEFAULT);
$criteria->addSelectColumn(TaxTableMap::CREATED_AT);
$criteria->addSelectColumn(TaxTableMap::UPDATED_AT);
} else {
$criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.TYPE');
$criteria->addSelectColumn($alias . '.SERIALIZED_REQUIREMENTS');
$criteria->addSelectColumn($alias . '.IS_DEFAULT');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}

View File

@@ -21,12 +21,10 @@ class Product extends BaseProduct
use \Thelia\Model\Tools\UrlRewritingTrait;
protected $defaultCategory = null;
/**
* {@inheritDoc}
*/
protected function getRewritenUrlViewName() {
protected function getRewrittenUrlViewName() {
return 'product';
}
@@ -45,7 +43,8 @@ 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());
}
/**
@@ -99,10 +98,12 @@ class Product extends BaseProduct
$con->beginTransaction();
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this));
try {
// Create the product
$this->save($con);
echo "1";
// Add the default category
$pc = new ProductCategory();
@@ -113,13 +114,44 @@ class Product extends BaseProduct
->save($con)
;
// Set the position
$this->setPosition($this->getNextPosition())->save($con);
echo "2";
// Create an empty product sale element
$sale_elements = new ProductSaleElements();
$sale_elements
->setProduct($this)
->setRef('')
->setPromo(0)
->setNewness(0)
->setWeight(0)
->save($con)
;
echo "3";
// 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()->findByByDefault(true))
->save($con)
;
echo "4";
// Store all the stuff !
$con->commit();
echo "commited !!!: ".$this->getId();
$this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this));
}
catch(PropelException $ex) {
$con->rollback();
echo("error !");
exit;
throw $ex;
}
}
@@ -140,30 +172,6 @@ class Product extends BaseProduct
if ($produits != null) $query->filterById($produits, Criteria::IN);
}
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
{
$this->generateRewritenUrl($this->getLocale());
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this));
return true;
}
/**
* {@inheritDoc}
*/
public function postInsert(ConnectionInterface $con = null)
{
$this->setPosition($this->getNextPosition());
$this->save();
$this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this));
}
/**
* {@inheritDoc}
*/
@@ -199,5 +207,4 @@ class Product extends BaseProduct
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETEPRODUCT, new ProductEvent($this));
}
}

View File

@@ -1,9 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Rewriting as BaseRewriting;
class Rewriting extends BaseRewriting {
}

View File

@@ -1,20 +0,0 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\RewritingQuery as BaseRewritingQuery;
/**
* Skeleton subclass for performing query and update operations on the 'rewriting' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class RewritingQuery extends BaseRewritingQuery {
} // RewritingQuery

View File

@@ -2,8 +2,25 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Base\RewritingUrl as BaseRewritingUrl;
use Thelia\Model\RewritingUrlQuery;
class RewritingUrl extends BaseRewritingUrl {
public function postInsert(ConnectionInterface $con = null)
{
if(null !== $this->getRedirected()) {
//check if rewriting url alredy exists and put redirect to the new one
RewritingUrlQuery::create()
->filterByView($this->getView())
->filterByViewId($this->getViewId())
->filterByViewLocale($this->getViewLocale())
->filterByRedirected($this->getId(), Criteria::NOT_IN)
->update(array(
"Redirected" => $this->getId()
));
}
}
}

View File

@@ -23,6 +23,9 @@
namespace Thelia\Model\Tools;
use Thelia\Exception\UrlRewritingException;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Model\RewritingUrl;
use Thelia\Tools\URL;
/**
* A trait for managing Rewriten URLs from model classes
@@ -32,7 +35,7 @@ trait UrlRewritingTrait {
/**
* @returns string the view name of the rewriten object (e.g., 'category', 'product')
*/
protected abstract function getRewritenUrlViewName();
protected abstract function getRewrittenUrlViewName();
/**
* Get the object URL for the given locale, rewriten if rewriting is enabled.
@@ -41,7 +44,7 @@ trait UrlRewritingTrait {
*/
public function getUrl($locale)
{
return URL::getInstance()->retrieve($this->getRewritenUrlViewName(), $this->getId(), $locale)->toString();
return URL::getInstance()->retrieve($this->getRewrittenUrlViewName(), $this->getId(), $locale)->toString();
}
/**
@@ -49,27 +52,79 @@ trait UrlRewritingTrait {
*
* @param string $locale a valid locale (e.g. en_US)
*/
public function generateRewritenUrl($locale)
public function generateRewrittenUrl($locale)
{
URL::getInstance()->generateRewritenUrl($this->getRewritenUrlViewName(), $this->getId(), $locale, $this->getTitle());
if ($this->isNew()) {
throw new \RuntimeException(sprintf('Object %s must be saved before generating url', $this->getRewrittenUrlViewName()));
}
// Borrowed from http://stackoverflow.com/questions/2668854/sanitizing-strings-to-make-them-url-and-filename-safe
$this->setLocale($locale);
$title = $this->getTitle() ?: $this->getRef();
// Replace all weird characters with dashes
$string = preg_replace('/[^\w\-~_\.]+/u', '-', $title);
// Only allow one dash separator at a time (and make string lowercase)
$cleanString = mb_strtolower(preg_replace('/--+/u', '-', $string), 'UTF-8');
$urlFilePart = $cleanString . ".html";
// TODO :
// check if URL url already exists, and add a numeric suffix, or the like
try{
$i=0;
while(URL::getInstance()->resolve($urlFilePart)) {
$i++;
$urlFilePart = sprintf("%s-%d.html",$cleanString, $i);
}
} catch (UrlRewritingException $e) {
$rewritingUrl = new RewritingUrl();
$rewritingUrl->setUrl($urlFilePart)
->setView($this->getRewrittenUrlViewName())
->setViewId($this->getId())
->setViewLocale($locale)
->save()
;
}
return $urlFilePart;
}
/**
* return the rewriten URL for the given locale
*
* @param string $locale a valid locale (e.g. en_US)
* @return null
*/
public function getRewritenUrl($locale)
public function getRewrittenUrl($locale)
{
return "fake url - TODO";
$rewritingUrl = RewritingUrlQuery::create()
->filterByViewLocale($locale)
->filterByView($this->getRewrittenUrlViewName())
->filterByViewId($this->getId())
->filterByRedirected(0)
->findOne()
;
if($rewritingUrl) {
$url = $rewritingUrl->getUrl();
} else {
$url = null;
}
return $url;
}
/**
* Set the rewriten URL for the given locale
*
* @param string $locale a valid locale (e.g. en_US)
* @param $url the wanted url
* @return $this
*/
public function setRewritenUrl($locale, $url)
public function setRewrittenUrl($locale, $url)
{
// TODO - code me !

View File

@@ -0,0 +1,88 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\Product;
use Thelia\Model\ProductQuery;
/**
* Class ProductRewriteTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ProductRewriteTest extends \PHPUnit_Framework_TestCase
{
protected static $productId;
public static function setUpBeforeClass()
{
$product = new Product();
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
->setPosition(1)
->setVisible(1)
->setLocale('en_US')
->setTitle('My english super Title')
->setLocale('fr_FR')
->setTitle('Mon super titre en français')
->save();
self::$productId = $product->getId();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testFrenchRewrittenUrl()
{
$product = ProductQuery::create()->findPk(self::$productId);
$rewrittenUrl = $product->generateRewrittenUrl('fr_FR');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl);
//mon-super-titre-en-français-2.html
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testEnglishRewrittenUrl()
{
$product = ProductQuery::create()->findPk(self::$productId);
$rewrittenUrl = $product->generateRewrittenUrl('en_US');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Object product must be saved before generating url
*/
public function testOnNotSavedProduct()
{
$product = new Product();
$product->generateRewrittenUrl('fr_FR');
}
}

View File

@@ -1128,9 +1128,9 @@ INSERT INTO `country_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `po
(268, 'es_ES', 'USA - Alabama', '', '', ''),
(268, 'fr_FR', 'USA - Alabama', '', '', '');
INSERT INTO `tax` (`id`, `type`, `serialized_requirements`, `created_at`, `updated_at`)
INSERT INTO `tax` (`id`, `type`, `serialized_requirements`, `is_default`, `created_at`, `updated_at`)
VALUES
(1, 'PricePercentTaxType', 'eyJwZXJjZW50IjoxOS42fQ==', NOW(), NOW());
(1, 'PricePercentTaxType', 'eyJwZXJjZW50IjoxOS42fQ==', 1, NOW(), NOW());
INSERT INTO `tax_i18n` (`id`, `locale`, `title`)
VALUES

View File

@@ -36,7 +36,7 @@ CREATE TABLE `product`
`ref` VARCHAR(255) NOT NULL,
`visible` TINYINT DEFAULT 0 NOT NULL,
`position` INTEGER NOT NULL,
`template_id` INTEGER NOT NULL,
`template_id` INTEGER,
`created_at` DATETIME,
`updated_at` DATETIME,
`version` INTEGER DEFAULT 0,
@@ -121,6 +121,7 @@ CREATE TABLE `tax`
`id` INTEGER NOT NULL AUTO_INCREMENT,
`type` VARCHAR(255) NOT NULL,
`serialized_requirements` TEXT NOT NULL,
`is_default` TINYINT(1) DEFAULT 0,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`)
@@ -2167,7 +2168,7 @@ CREATE TABLE `product_version`
`ref` VARCHAR(255) NOT NULL,
`visible` TINYINT DEFAULT 0 NOT NULL,
`position` INTEGER NOT NULL,
`template_id` INTEGER NOT NULL,
`template_id` INTEGER,
`created_at` DATETIME,
`updated_at` DATETIME,
`version` INTEGER DEFAULT 0 NOT NULL,

View File

@@ -28,7 +28,7 @@
<column name="title" size="255" type="VARCHAR" />
<column name="description" type="CLOB" />
<column name="chapo" type="LONGVARCHAR" />
<column name="postscriptum" type="LONGVARCHAR" />
<column name="postscriptum" type="LONGVARCHAR" />
<column name="template_id" type="INTEGER" />
<foreign-key foreignTable="tax_rule" name="fk_product_tax_rule_id" onDelete="SET NULL" onUpdate="RESTRICT">
<reference foreign="id" local="tax_rule_id" />
@@ -102,6 +102,7 @@
<column name="type" required="true" size="255" type="VARCHAR" />
<column name="serialized_requirements" required="true" type="LONGVARCHAR" />
<column name="title" size="255" type="VARCHAR" />
<column name="description" type="LONGVARCHAR" />
<column defaultValue="0" name="is_default" type="BOOLEAN" />
<behavior name="timestampable" />
<behavior name="i18n">

View File

@@ -5,452 +5,533 @@
{block name="check-permissions"}admin.categories.view{/block}
{block name="main-content"}
<div class="categories">
<div class="categories">
<div id="wrapper" class="container">
<div id="wrapper" class="container">
{include file="includes/catalog-breadcrumb.html"}
{include file="includes/catalog-breadcrumb.html"}
{module_include location='categories_top'}
{module_include location='categories_top'}
<div class="row">
<div class="col-md-12">
<div class="general-block-decorator">
<div class="row">
<div class="col-md-12">
<div class="general-block-decorator">
<table class="table table-striped table-condensed" id="category_list">
<caption>
{* display parent category name, and get current cat ID *}
{loop name="category_title" type="category" visible="*" id=$category_id}
{intl l="Categories in %cat" cat=$TITLE}
{$cat_id = $ID}
{/loop}
{elseloop rel="category_title"}
{intl l="Top level categories"}
{/elseloop}
<table class="table table-striped table-condensed" id="category_list">
<caption>
{* display parent category name, and get current cat ID *}
{loop name="category_title" type="category" visible="*" id=$category_id}
{intl l="Categories in %cat" cat=$TITLE}
{$cat_id = $ID}
{/loop}
{elseloop rel="category_title"}
{intl l="Top level categories"}
{/elseloop}
{module_include location='category_list_caption'}
{module_include location='category_list_caption'}
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"}
<a class="btn btn-default btn-primary action-btn" title="{intl l='Add a new category'}" href="#category_creation_dialog" data-toggle="modal">
<span class="glyphicon glyphicon-plus-sign"></span>
</a>
{/loop}
</caption>
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"}
<a class="btn btn-default btn-primary action-btn" title="{intl l='Add a new category'}" href="#category_creation_dialog" data-toggle="modal">
<span class="glyphicon glyphicon-plus-sign"></span>
</a>
{/loop}
</caption>
{ifloop rel="category_list"}
<thead>
<tr>
<th class="object-title">
{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'}"
}
</th>
{ifloop rel="category_list"}
<thead>
<tr>
<th class="object-title">
{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'}"
}
</th>
<th class="object-image">&nbsp;</th>
<th class="object-image">&nbsp;</th>
<th class="object-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'}"
}
</th>
<th class="object-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'}"
}
</th>
{module_include location='category_list_header'}
{module_include location='category_list_header'}
<th>
{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'}"
}
</th>
<th>
{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'}"
}
</th>
<th>
{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'}"
}
</th>
<th>
{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'}"
}
</th>
<th class="actions">{intl l='Actions'}</th>
</tr>
</thead>
<th class="actions">{intl l='Actions'}</th>
</tr>
</thead>
<tbody>
{loop name="category_list" type="category" visible="*" parent=$category_id order=$category_order backend_context="1" lang=$lang_id}
<tr>
<td>{$ID}</td>
<tbody>
{loop name="category_list" type="category" visible="*" parent=$category_id order=$category_order backend_context="1" lang=$lang_id}
<tr>
<td>{$ID}</td>
<td>
{loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
<a href="{url path='admin/catalog' category_id=$ID}" title="{intl l='Browse this category'}"><img class="img-thumbnail" src="{$IMAGE_URL}" alt="{$TITLE}" /></a>
{/loop}
</td>
<td>
{loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
<a href="{url path='admin/catalog' category_id=$ID}" title="{intl l='Browse this category'}"><img class="img-thumbnail" src="{$IMAGE_URL}" alt="{$TITLE}" /></a>
{/loop}
</td>
<td class="object-title">
<a href="{url path='admin/catalog' category_id=$ID}" title="{intl l='Browse this category'}">
{$TITLE}
</a>
</td>
<td class="object-title">
<a href="{url path='admin/catalog' category_id=$ID}" title="{intl l='Browse this category'}">
{$TITLE}
</a>
</td>
{module_include location='category_list_row'}
{module_include location='category_list_row'}
<td>
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
<div class="make-switch switch-small categoryVisibleToggle" data-id="{$ID}" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="categoryVisibleToggle" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/loop}
<td>
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
<div class="make-switch switch-small categoryVisibleToggle" data-id="{$ID}" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="categoryVisibleToggle" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/loop}
{elseloop rel="can_change"}
<div class="make-switch switch-small" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="disabled" disabled="disabled" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/elseloop}
</td>
{elseloop rel="can_change"}
<div class="make-switch switch-small" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="disabled" disabled="disabled" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/elseloop}
</td>
<td>
{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
}
</td>
<td>
{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
}
</td>
<td class="actions">
<div class="btn-group">
<a class="btn btn-default btn-xs" title="{intl l='Browse this category'}" href="{url path='admin/categories' category_id=$ID}"><i class="glyphicon glyphicon-folder-open"></i></a>
<td class="actions">
<div class="btn-group">
<a class="btn btn-default btn-xs" title="{intl l='Browse this category'}" href="{url path='admin/categories' category_id=$ID}"><i class="glyphicon glyphicon-folder-open"></i></a>
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
<a class="btn btn-default btn-xs" title="{intl l='Edit this category'}" href="{url path='/admin/categories/update' category_id=$ID}"><i class="glyphicon glyphicon-edit"></i></a>
{/loop}
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
<a class="btn btn-default btn-xs" title="{intl l='Edit this category'}" href="{url path='/admin/categories/update' category_id=$ID}"><i class="glyphicon glyphicon-edit"></i></a>
{/loop}
{loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.categories.delete"}
<a class="btn btn-default btn-xs category-delete" title="{intl l='Delete this category and all its contents'}" href="#category_delete_dialog" data-id="{$ID}" data-toggle="modal"><i class="glyphicon glyphicon-trash"></i></a>
{/loop}
</div>
</td>
</tr>
{/loop}
</tbody>
{/ifloop}
{loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.categories.delete"}
<a class="btn btn-default btn-xs category-delete" title="{intl l='Delete this category and all its contents'}" href="#category_delete_dialog" data-id="{$ID}" data-toggle="modal"><i class="glyphicon glyphicon-trash"></i></a>
{/loop}
</div>
</td>
</tr>
{/loop}
</tbody>
{/ifloop}
{elseloop rel="category_list"}
<thead>
<tr>
<td class="message">
<div class="alert alert-info">
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"}
{intl l="This category has no sub-categories. To create a new one, click the + button above."}
{/loop}
{elseloop rel="category_list"}
<thead>
<tr>
<td class="message">
<div class="alert alert-info">
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"}
{intl l="This category has no sub-categories. To create a new one, click the + button above."}
{/loop}
{elseloop rel="can_create"}
{intl l="This category has no sub-categories."}
{/elseloop}
</div>
</td>
</tr>
</thead>
{/elseloop}
</table>
</div>
{elseloop rel="can_create"}
{intl l="This category has no sub-categories."}
{/elseloop}
</div>
</td>
</tr>
</thead>
{/elseloop}
</table>
</div>
</div>
</div>
{* -- PRODUCT MANAGEMENT ---------------------------------------------------- *}
<div class="row">
<div class="col-md-12">
<div class="general-block-decorator">
<div class="row">
<div class="col-md-12">
<div class="general-block-decorator">
<table class="table table-striped table-condensed">
<caption>
{* display parent category name *}
{loop name="category_title" type="category" visible="*" id=$category_id}
{intl l="Products in %cat" cat=$TITLE}
{/loop}
<table class="table table-striped table-condensed">
<caption>
{* display parent category name *}
{loop name="category_title" type="category" visible="*" id=$category_id}
{intl l="Products in %cat" cat=$TITLE}
{/loop}
{elseloop rel="category_title"}
{intl l="Top level Products"}
{/elseloop}
{elseloop rel="category_title"}
{intl l="Top level Products"}
{/elseloop}
{module_include location='product_list_caption'}
{module_include location='product_list_caption'}
<a class="btn btn-default btn-primary action-btn" title="{intl l='Add a new product'}" href="#productAddModal" data-toggle="modal">
<span class="glyphicon glyphicon-plus-sign"></span>
</a>
</caption>
<a class="btn btn-default btn-primary action-btn" title="{intl l='Add a new product'}" href="#product_creation_dialog" data-toggle="modal">
<span class="glyphicon glyphicon-plus-sign"></span>
</a>
</caption>
{ifloop rel="product_list"}
<thead>
<tr>
<th class="object-title">
{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"}
<thead>
<tr>
<th class="object-title">
{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'}"
}
<th>&nbsp;</th>
<th>&nbsp;</th>
<th class="object-title">
{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'}"
}
</th>
<th class="object-title">
{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'}"
}
</th>
<th class="object-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'}"
}
<th class="object-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'}
<th>
{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'}"
}
</th>
<th>
{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'}"
}
</th>
<th>
{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'}"
}
</th>
<th>
{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'}"
}
</th>
<th>&nbsp;</th>
</tr>
</thead>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{loop name="product_list" type="product" visible="*" category_default=$category_id order=$product_order}
<tr>
<td>{$ID}</td>
<tbody>
{loop name="product_list" type="product" visible="*" category_default=$category_id order=$product_order}
<tr>
<td>{$ID}</td>
<td>
{loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
<a href="{url path='admin/product/edit' id=$ID}" title="{intl l='Edit this product'}">
<img src="{$IMAGE_URL}" alt="{$TITLE}" />
</a>
{/loop}
<td>
{loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"}
<a href="{url path='admin/product/edit' id=$ID}" title="{intl l='Edit this product'}">
<img src="{$IMAGE_URL}" alt="{$TITLE}" />
</a>
{/loop}
<td class="object-title"><a href="{url path="/admin/product/update/$ID"}" title="{intl l='Edit this product'}">{$REF}</a></td>
<td class="object-title"><a href="{url path="/admin/product/update/$ID"}" title="{intl l='Edit this product'}">{$REF}</a></td>
<td class="object-title"><a href="{url path="/admin/product/update/$ID"}" title="{intl l='Edit this product'}">{$TITLE}</a></td>
<td class="object-title"><a href="{url path="/admin/product/update/$ID"}" title="{intl l='Edit this product'}">{$TITLE}</a></td>
{module_include location='product_list_row'}
{module_include location='product_list_row'}
<td>
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"}
<div class="make-switch switch-small" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" data-id="{$ID}" class="productVisibleToggle" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/loop}
<td>
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"}
<div class="make-switch switch-small productVisibleToggle" data-id="{$ID}" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="productVisibleToggle" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/loop}
{elseloop rel="can_delete"}
<div class="make-switch switch-small" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" data-id="{$ID}" class="displayToggle" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/elseloop}
</td>
{elseloop rel="can_change"}
<div class="make-switch switch-small" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="disabled" disabled="disabled" {if $VISIBLE == 1}checked="checked"{/if}>
</div>
{/elseloop}
</td>
<td>
{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
}
</td>
<td>
{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
}
</td>
<td>
<div class="btn-group">
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.edit"}
<a class="btn btn-default btn-xs" title="{intl l='Edit this product'}" href="{url path="admin/product/update/$ID"}"><i class="glyphicon glyphicon-edit"></i></a>
{/loop}
<td>
<div class="btn-group">
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.edit"}
<a class="btn btn-default btn-xs" title="{intl l='Edit this product'}" href="{url path="admin/product/update/$ID"}"><i class="glyphicon glyphicon-edit"></i></a>
{/loop}
{loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.product.delete"}
<a class="btn btn-default btn-xs product-delete" title="{intl l='Delete this product'}" href="#product_delete_dialog" data-id="{$ID}" data-toggle="modal"><i class="glyphicon glyphicon-trash"></i></a>
{/loop}
</div>
</td>
</tr>
{/loop}
</tbody>
{/ifloop}
{loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.product.delete"}
<a class="btn btn-default btn-xs product-delete" title="{intl l='Delete this product'}" href="#product_delete_dialog" data-id="{$ID}" data-toggle="modal"><i class="glyphicon glyphicon-trash"></i></a>
{/loop}
</div>
</td>
</tr>
{/loop}
</tbody>
{/ifloop}
{elseloop rel="product_list"}
<thead>
<tr>
<td class="message"><div class="alert alert-info">{intl l="This category doesn't contains any products. To add a new product, <strong>click the + button</strong> above."}</div></td>
</tr>
</thead>
{/elseloop}
</table>
{elseloop rel="product_list"}
<thead>
<tr>
<td class="message"><div class="alert alert-info">{intl l="This category doesn't contains any products. To add a new product, <strong>click the + button</strong> above."}</div></td>
</tr>
</thead>
{/elseloop}
</table>
</div>
</div>
</div>
</div>
{module_include location='categories_bottom'}
</div>
{module_include location='catalog_bottom'}
</div>
{module_include location='categories_bottom'}
</div>
{module_include location='catalog_bottom'}
</div>
{* Adding a new category *}
{form name="thelia.admin.category.creation"}
{* -- Adding a new category ------------------------------------------------- *}
{* Capture the dialog body, to pass it to the generic dialog *}
{capture "category_creation_dialog"}
{form name="thelia.admin.category.creation"}
{form_hidden_fields form=$form}
{* Capture the dialog body, to pass it to the generic dialog *}
{capture "category_creation_dialog"}
{form_field form=$form field='success_url'}
{* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *}
<input type="hidden" name="{$name}" value="{url path='/admin/categories/update' category_id='_ID_'}" />
{/form_field}
{form_hidden_fields form=$form}
{form_field form=$form field='parent'}
<input type="hidden" name="{$name}" value="{$category_id}" />
{/form_field}
{form_field form=$form field='success_url'}
{* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *}
<input type="hidden" name="{$name}" value="{url path='/admin/categories/update' category_id='_ID_'}" />
{/form_field}
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
{loop type="lang" name="default-lang" default_only="1"}
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{intl l='Currency name'}" placeholder="{intl l='Name'}">
<span class="input-group-addon"><img src="{image file="assets/img/flags/{$CODE}.gif"}" alt="$TITLE" /></span>
</div>
{form_field form=$form field='parent'}
<input type="hidden" name="{$name}" value="{$category_id}" />
{/form_field}
<div class="help-block">{intl l='Enter here the category name in the default language (%title)' title="$TITLE"}</div>
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$LOCALE}" />
{/form_field}
{/loop}
</div>
{/form_field}
{form_field form=$form field='visible'}
<div class="form-group {if $error}has-error{/if}">
<div class="checkbox">
<label>
<input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" checked="checked">
{$label}
</label>
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
{loop type="lang" name="default-lang" default_only="1"}
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{intl l='Category title'}" placeholder="{intl l='Name'}">
<span class="input-group-addon"><img src="{image file="assets/img/flags/{$CODE}.gif"}" alt="$TITLE" /></span>
</div>
<div class="help-block">{intl l='Enter here the category name in the default language (%title)' title="$TITLE"}</div>
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$LOCALE}" />
{/form_field}
{/loop}
</div>
{/form_field}
{form_field form=$form field='visible'}
<div class="form-group {if $error}has-error{/if}">
<div class="checkbox">
<label>
<input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" checked="checked">
{$label}
</label>
</div>
{/form_field}
</div>
{/form_field}
{module_include location='category_create_form'}
{/capture}
{include
file = "includes/generic-create-dialog.html"
dialog_id = "category_creation_dialog"
dialog_title = {intl l="Create a new category"}
dialog_body = {$smarty.capture.category_creation_dialog nofilter}
dialog_ok_label = {intl l="Create this category"}
form_action = {url path='/admin/categories/create'}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}
{/form}
{* Delete category confirmation dialog *}
{capture "category_delete_dialog"}
<input type="hidden" name="category_id" id="category_delete_id" value="" />
{module_include location='category_delete_form'}
{module_include location='category_create_form'}
{/capture}
{include
file = "includes/generic-confirm-dialog.html"
file = "includes/generic-create-dialog.html"
dialog_id = "category_delete_dialog"
dialog_title = {intl l="Delete category"}
dialog_message = {intl l="Do you really want to delete this category and all its content ?"}
dialog_id = "category_creation_dialog"
dialog_title = {intl l="Create a new category"}
dialog_body = {$smarty.capture.category_creation_dialog nofilter}
form_action = {url path='/admin/categories/delete'}
form_content = {$smarty.capture.category_delete_dialog nofilter}
dialog_ok_label = {intl l="Create this category"}
form_action = {url path='/admin/categories/create'}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}
{/form}
{* Delete product confirmation dialog *}
{* -- Adding a new product -------------------------------------------------- *}
{capture "product_delete_dialog"}
<input type="hidden" name="product_id" id="product_delete_id" value="" />
{form name="thelia.admin.product.creation"}
{module_include location='product_delete_form'}
{* Capture the dialog body, to pass it to the generic dialog *}
{capture "product_creation_dialog"}
{form_hidden_fields form=$form}
{* Be sure to get the category_id, even if the form could not be validated *}
<input type="hidden" name="category_id" value="{$category_id}" />
{form_field form=$form field='success_url'}
{* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *}
<input type="hidden" name="{$name}" value="{url path='/admin/products/update' product_id='_ID_'}" />
{/form_field}
{form_field form=$form field='default_category'}
<input type="hidden" name="{$name}" value="{$category_id}" />
{/form_field}
{form_field form=$form field='ref'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="from-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Reference'}">
</div>
<div class="help-block">{intl l='Enter here the product reference'}</div>
</div>
{/form_field}
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
{loop type="lang" name="default-lang" default_only="1"}
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Title'}">
<span class="input-group-addon"><img src="{image file="assets/img/flags/{$CODE}.gif"}" alt="$TITLE" /></span>
</div>
<div class="help-block">{intl l='Enter here the product name in the default language (%title)' title="$TITLE"}</div>
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$LOCALE}" />
{/form_field}
{/loop}
</div>
{/form_field}
{form_field form=$form field='visible'}
<div class="form-group {if $error}has-error{/if}">
<div class="checkbox">
<label>
<input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" checked="checked">
{$label}
</label>
</div>
</div>
{/form_field}
{module_include location='product_create_form'}
{/capture}
{include
file = "includes/generic-confirm-dialog.html"
file = "includes/generic-create-dialog.html"
dialog_id = "product_delete_dialog"
dialog_title = {intl l="Delete product"}
dialog_message = {intl l="Do you really want to delete this product ?"}
dialog_id = "product_creation_dialog"
dialog_title = {intl l="Create a new product"}
dialog_body = {$smarty.capture.product_creation_dialog nofilter}
form_action = {url path='/admin/products/delete'}
form_content = {$smarty.capture.product_delete_dialog nofilter}
dialog_ok_label = {intl l="Create this product"}
form_action = {url path='/admin/products/create'}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}
{/form}
{* -- Delete category confirmation dialog ----------------------------------- *}
{capture "category_delete_dialog"}
<input type="hidden" name="category_id" id="category_delete_id" value="" />
{module_include location='category_delete_form'}
{/capture}
{include
file = "includes/generic-confirm-dialog.html"
dialog_id = "category_delete_dialog"
dialog_title = {intl l="Delete category"}
dialog_message = {intl l="Do you really want to delete this category and all its content ?"}
form_action = {url path='/admin/categories/delete'}
form_content = {$smarty.capture.category_delete_dialog nofilter}
}
{* -- Delete product confirmation dialog ------------------------------------ *}
{capture "product_delete_dialog"}
<input type="hidden" name="product_id" id="product_delete_id" value="" />
{module_include location='product_delete_form'}
{/capture}
{include
file = "includes/generic-confirm-dialog.html"
dialog_id = "product_delete_dialog"
dialog_title = {intl l="Delete product"}
dialog_message = {intl l="Do you really want to delete this product ?"}
form_action = {url path='/admin/products/delete'}
form_content = {$smarty.capture.product_delete_dialog nofilter}
}
{/block}
{block name="javascript-initialization"}
@@ -483,11 +564,15 @@
form_name = "thelia.admin.category.creation"
}
{include
file = "includes/generic-js-dialog.html"
dialog_id = "product_creation_dialog"
form_name = "thelia.admin.product.creation"
}
{* Toggle object visibility *}
$(".categoryVisibleToggle").on('switch-change', function(event, data) {
console.log("yaya");
$.ajax({
url : "{url path='admin/categories/toggle-online'}",
data : {
@@ -497,6 +582,17 @@
});
});
$(".productVisibleToggle").on('switch-change', function(event, data) {
$.ajax({
url : "{url path='admin/products/toggle-online'}",
data : {
product_id : $(this).data('id'),
action : 'visibilityToggle'
}
});
});
{* Inline editing of object position using bootstrap-editable *}
$('.categoryPositionChange').editable({
@@ -518,6 +614,25 @@
}
});
$('.productPositionChange').editable({
type : 'text',
title : '{intl l="Enter new product position"}',
mode : 'popup',
inputclass : 'input-mini',
placement : 'left',
success : function(response, newValue) {
// The URL template
var url = "{url path='/admin/products/update-position' product_id='__ID__' position='__POS__'}";
// Perform subtitutions
url = url.replace('__ID__', $(this).data('id'))
.replace('__POS__', newValue);
// Reload the page
location.href = url;
}
});
{* Change default status *}
$('.change-default').change(function(ev) {