Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By gmorel (24) and others # Via gmorel (12) and others * 'master' of https://github.com/thelia/thelia: (43 commits) Working : upload file/image : fix sanitizeFileName Working : images : enhance display Working : Fix : Unit test Working : Fix : Unit test Working : Fix : Image Management + Document Management Working : FileManager :Add some more unit tests Working : Add a link on documents Working : fix url document + refactor : naming conventions Working : refactor : naming conventions Working : upload : fix unit test WIP : upload documents : add action, ctrl, event Finished product combination basic function WIP : upload document : add forms Working : upload image : fix return URL to images tab Working : upload image : fix fallback and delete links on refresh Formatted combination table Impemented combination creation Working : Upload image : Fix upload validation - Image format allowed - manual-reverse order on image loop Upload allow only for images ... Conflicts: core/lib/Thelia/Model/Base/AttributeTemplate.php core/lib/Thelia/Model/Base/AttributeTemplateQuery.php core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php install/faker.php install/thelia.sql local/config/schema.xml templates/admin/default/assets/js/coupon.js tests/functionnal/casperjs/exe/00_parameters.js tests/functionnal/casperjs/exe/31_coupons_rule.js
This commit is contained in:
@@ -3,8 +3,29 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\AttributeTemplate as BaseAttributeTemplate;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class AttributeTemplate extends BaseAttributeTemplate
|
||||
class AttributeTemplate extends BaseAttributeTemplate
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our template
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query)
|
||||
{
|
||||
$query->filterByTemplateId($this->getTemplateId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,12 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* The value for the attribute_templatecol field.
|
||||
* @var string
|
||||
*/
|
||||
protected $attribute_templatecol;
|
||||
|
||||
/**
|
||||
* The value for the created_at field.
|
||||
* @var string
|
||||
@@ -410,6 +416,17 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [attribute_templatecol] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAttributeTemplatecol()
|
||||
{
|
||||
|
||||
return $this->attribute_templatecol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [created_at] column value.
|
||||
*
|
||||
@@ -542,6 +559,27 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
return $this;
|
||||
} // setPosition()
|
||||
|
||||
/**
|
||||
* Set the value of [attribute_templatecol] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\AttributeTemplate The current object (for fluent API support)
|
||||
*/
|
||||
public function setAttributeTemplatecol($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->attribute_templatecol !== $v) {
|
||||
$this->attribute_templatecol = $v;
|
||||
$this->modifiedColumns[] = AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setAttributeTemplatecol()
|
||||
|
||||
/**
|
||||
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
|
||||
*
|
||||
@@ -633,13 +671,16 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AttributeTemplateTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->position = (null !== $col) ? (int) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AttributeTemplateTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AttributeTemplateTableMap::translateFieldName('AttributeTemplatecol', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->attribute_templatecol = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : AttributeTemplateTableMap::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 ? 5 + $startcol : AttributeTemplateTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : AttributeTemplateTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
if ($col === '0000-00-00 00:00:00') {
|
||||
$col = null;
|
||||
}
|
||||
@@ -652,7 +693,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
$this->ensureConsistency();
|
||||
}
|
||||
|
||||
return $startcol + 6; // 6 = AttributeTemplateTableMap::NUM_HYDRATE_COLUMNS.
|
||||
return $startcol + 7; // 7 = AttributeTemplateTableMap::NUM_HYDRATE_COLUMNS.
|
||||
|
||||
} catch (Exception $e) {
|
||||
throw new PropelException("Error populating \Thelia\Model\AttributeTemplate object", 0, $e);
|
||||
@@ -911,6 +952,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::POSITION)) {
|
||||
$modifiedColumns[':p' . $index++] = 'POSITION';
|
||||
}
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL)) {
|
||||
$modifiedColumns[':p' . $index++] = 'ATTRIBUTE_TEMPLATECOL';
|
||||
}
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::CREATED_AT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
|
||||
}
|
||||
@@ -940,6 +984,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
case 'POSITION':
|
||||
$stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
|
||||
break;
|
||||
case 'ATTRIBUTE_TEMPLATECOL':
|
||||
$stmt->bindValue($identifier, $this->attribute_templatecol, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'CREATED_AT':
|
||||
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
|
||||
break;
|
||||
@@ -1021,9 +1068,12 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
return $this->getPosition();
|
||||
break;
|
||||
case 4:
|
||||
return $this->getCreatedAt();
|
||||
return $this->getAttributeTemplatecol();
|
||||
break;
|
||||
case 5:
|
||||
return $this->getCreatedAt();
|
||||
break;
|
||||
case 6:
|
||||
return $this->getUpdatedAt();
|
||||
break;
|
||||
default:
|
||||
@@ -1059,8 +1109,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
$keys[1] => $this->getAttributeId(),
|
||||
$keys[2] => $this->getTemplateId(),
|
||||
$keys[3] => $this->getPosition(),
|
||||
$keys[4] => $this->getCreatedAt(),
|
||||
$keys[5] => $this->getUpdatedAt(),
|
||||
$keys[4] => $this->getAttributeTemplatecol(),
|
||||
$keys[5] => $this->getCreatedAt(),
|
||||
$keys[6] => $this->getUpdatedAt(),
|
||||
);
|
||||
$virtualColumns = $this->virtualColumns;
|
||||
foreach($virtualColumns as $key => $virtualColumn)
|
||||
@@ -1122,9 +1173,12 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
$this->setPosition($value);
|
||||
break;
|
||||
case 4:
|
||||
$this->setCreatedAt($value);
|
||||
$this->setAttributeTemplatecol($value);
|
||||
break;
|
||||
case 5:
|
||||
$this->setCreatedAt($value);
|
||||
break;
|
||||
case 6:
|
||||
$this->setUpdatedAt($value);
|
||||
break;
|
||||
} // switch()
|
||||
@@ -1155,8 +1209,9 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
if (array_key_exists($keys[1], $arr)) $this->setAttributeId($arr[$keys[1]]);
|
||||
if (array_key_exists($keys[2], $arr)) $this->setTemplateId($arr[$keys[2]]);
|
||||
if (array_key_exists($keys[3], $arr)) $this->setPosition($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]]);
|
||||
if (array_key_exists($keys[4], $arr)) $this->setAttributeTemplatecol($arr[$keys[4]]);
|
||||
if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]);
|
||||
if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1172,6 +1227,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::ATTRIBUTE_ID)) $criteria->add(AttributeTemplateTableMap::ATTRIBUTE_ID, $this->attribute_id);
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::TEMPLATE_ID)) $criteria->add(AttributeTemplateTableMap::TEMPLATE_ID, $this->template_id);
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::POSITION)) $criteria->add(AttributeTemplateTableMap::POSITION, $this->position);
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL)) $criteria->add(AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL, $this->attribute_templatecol);
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::CREATED_AT)) $criteria->add(AttributeTemplateTableMap::CREATED_AT, $this->created_at);
|
||||
if ($this->isColumnModified(AttributeTemplateTableMap::UPDATED_AT)) $criteria->add(AttributeTemplateTableMap::UPDATED_AT, $this->updated_at);
|
||||
|
||||
@@ -1240,6 +1296,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
$copyObj->setAttributeId($this->getAttributeId());
|
||||
$copyObj->setTemplateId($this->getTemplateId());
|
||||
$copyObj->setPosition($this->getPosition());
|
||||
$copyObj->setAttributeTemplatecol($this->getAttributeTemplatecol());
|
||||
$copyObj->setCreatedAt($this->getCreatedAt());
|
||||
$copyObj->setUpdatedAt($this->getUpdatedAt());
|
||||
if ($makeNew) {
|
||||
@@ -1381,6 +1438,7 @@ abstract class AttributeTemplate implements ActiveRecordInterface
|
||||
$this->attribute_id = null;
|
||||
$this->template_id = null;
|
||||
$this->position = null;
|
||||
$this->attribute_templatecol = null;
|
||||
$this->created_at = null;
|
||||
$this->updated_at = null;
|
||||
$this->alreadyInSave = false;
|
||||
|
||||
@@ -25,6 +25,7 @@ use Thelia\Model\Map\AttributeTemplateTableMap;
|
||||
* @method ChildAttributeTemplateQuery orderByAttributeId($order = Criteria::ASC) Order by the attribute_id column
|
||||
* @method ChildAttributeTemplateQuery orderByTemplateId($order = Criteria::ASC) Order by the template_id column
|
||||
* @method ChildAttributeTemplateQuery orderByPosition($order = Criteria::ASC) Order by the position column
|
||||
* @method ChildAttributeTemplateQuery orderByAttributeTemplatecol($order = Criteria::ASC) Order by the attribute_templatecol column
|
||||
* @method ChildAttributeTemplateQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
|
||||
* @method ChildAttributeTemplateQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
|
||||
*
|
||||
@@ -32,6 +33,7 @@ use Thelia\Model\Map\AttributeTemplateTableMap;
|
||||
* @method ChildAttributeTemplateQuery groupByAttributeId() Group by the attribute_id column
|
||||
* @method ChildAttributeTemplateQuery groupByTemplateId() Group by the template_id column
|
||||
* @method ChildAttributeTemplateQuery groupByPosition() Group by the position column
|
||||
* @method ChildAttributeTemplateQuery groupByAttributeTemplatecol() Group by the attribute_templatecol column
|
||||
* @method ChildAttributeTemplateQuery groupByCreatedAt() Group by the created_at column
|
||||
* @method ChildAttributeTemplateQuery groupByUpdatedAt() Group by the updated_at column
|
||||
*
|
||||
@@ -54,6 +56,7 @@ use Thelia\Model\Map\AttributeTemplateTableMap;
|
||||
* @method ChildAttributeTemplate findOneByAttributeId(int $attribute_id) Return the first ChildAttributeTemplate filtered by the attribute_id column
|
||||
* @method ChildAttributeTemplate findOneByTemplateId(int $template_id) Return the first ChildAttributeTemplate filtered by the template_id column
|
||||
* @method ChildAttributeTemplate findOneByPosition(int $position) Return the first ChildAttributeTemplate filtered by the position column
|
||||
* @method ChildAttributeTemplate findOneByAttributeTemplatecol(string $attribute_templatecol) Return the first ChildAttributeTemplate filtered by the attribute_templatecol column
|
||||
* @method ChildAttributeTemplate findOneByCreatedAt(string $created_at) Return the first ChildAttributeTemplate filtered by the created_at column
|
||||
* @method ChildAttributeTemplate findOneByUpdatedAt(string $updated_at) Return the first ChildAttributeTemplate filtered by the updated_at column
|
||||
*
|
||||
@@ -61,6 +64,7 @@ use Thelia\Model\Map\AttributeTemplateTableMap;
|
||||
* @method array findByAttributeId(int $attribute_id) Return ChildAttributeTemplate objects filtered by the attribute_id column
|
||||
* @method array findByTemplateId(int $template_id) Return ChildAttributeTemplate objects filtered by the template_id column
|
||||
* @method array findByPosition(int $position) Return ChildAttributeTemplate objects filtered by the position column
|
||||
* @method array findByAttributeTemplatecol(string $attribute_templatecol) Return ChildAttributeTemplate objects filtered by the attribute_templatecol column
|
||||
* @method array findByCreatedAt(string $created_at) Return ChildAttributeTemplate objects filtered by the created_at column
|
||||
* @method array findByUpdatedAt(string $updated_at) Return ChildAttributeTemplate objects filtered by the updated_at column
|
||||
*
|
||||
@@ -151,7 +155,7 @@ abstract class AttributeTemplateQuery extends ModelCriteria
|
||||
*/
|
||||
protected function findPkSimple($key, $con)
|
||||
{
|
||||
$sql = 'SELECT ID, ATTRIBUTE_ID, TEMPLATE_ID, POSITION, CREATED_AT, UPDATED_AT FROM attribute_template WHERE ID = :p0';
|
||||
$sql = 'SELECT ID, ATTRIBUTE_ID, TEMPLATE_ID, POSITION, ATTRIBUTE_TEMPLATECOL, CREATED_AT, UPDATED_AT FROM attribute_template WHERE ID = :p0';
|
||||
try {
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
|
||||
@@ -408,6 +412,35 @@ abstract class AttributeTemplateQuery extends ModelCriteria
|
||||
return $this->addUsingAlias(AttributeTemplateTableMap::POSITION, $position, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the attribute_templatecol column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByAttributeTemplatecol('fooValue'); // WHERE attribute_templatecol = 'fooValue'
|
||||
* $query->filterByAttributeTemplatecol('%fooValue%'); // WHERE attribute_templatecol LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $attributeTemplatecol The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildAttributeTemplateQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByAttributeTemplatecol($attributeTemplatecol = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($attributeTemplatecol)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $attributeTemplatecol)) {
|
||||
$attributeTemplatecol = str_replace('*', '%', $attributeTemplatecol);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL, $attributeTemplatecol, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the created_at column
|
||||
*
|
||||
|
||||
@@ -25,4 +25,28 @@ class CategoryDocument extends BaseCategoryDocument
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Document parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setCategoryId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Document parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getCategoryId();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Thelia\Model\Base\CategoryImage as BaseCategoryImage;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
@@ -25,4 +27,29 @@ class CategoryImage extends BaseCategoryImage
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Image parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setCategoryId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getCategoryId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,28 @@ class ContentDocument extends BaseContentDocument
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Document parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setContentId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Document parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getContentId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,28 @@ class ContentImage extends BaseContentImage
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Image parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setContentId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getContentId();
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,66 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\FeatureProduct as BaseFeatureProduct;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Core\Event\FeatureProductEvent;
|
||||
|
||||
class FeatureProduct extends BaseFeatureProduct
|
||||
class FeatureProduct extends BaseFeatureProduct
|
||||
{
|
||||
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEFEATURE_PRODUCT, new FeatureProductEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CREATEFEATURE_PRODUCT, new FeatureProductEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEFEATURE_PRODUCT, new FeatureProductEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEFEATURE_PRODUCT, new FeatureProductEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEFEATURE_PRODUCT, new FeatureProductEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_DELETEFEATURE_PRODUCT, new FeatureProductEvent($this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,30 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\FeatureTemplate as BaseFeatureTemplate;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class FeatureTemplate extends BaseFeatureTemplate
|
||||
class FeatureTemplate extends BaseFeatureTemplate
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our template
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query)
|
||||
{
|
||||
$query->filterByTemplateId($this->getTemplateId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
// Set the current position for the new object
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,28 @@ class FolderDocument extends BaseFolderDocument
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Document parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setFolderId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Document parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getFolderId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,28 @@ class FolderImage extends BaseFolderImage
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Image parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setFolderId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getFolderId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class AttributeTemplateTableMap extends TableMap
|
||||
/**
|
||||
* The total number of columns
|
||||
*/
|
||||
const NUM_COLUMNS = 6;
|
||||
const NUM_COLUMNS = 7;
|
||||
|
||||
/**
|
||||
* The number of lazy-loaded columns
|
||||
@@ -67,7 +67,7 @@ class AttributeTemplateTableMap extends TableMap
|
||||
/**
|
||||
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
|
||||
*/
|
||||
const NUM_HYDRATE_COLUMNS = 6;
|
||||
const NUM_HYDRATE_COLUMNS = 7;
|
||||
|
||||
/**
|
||||
* the column name for the ID field
|
||||
@@ -89,6 +89,11 @@ class AttributeTemplateTableMap extends TableMap
|
||||
*/
|
||||
const POSITION = 'attribute_template.POSITION';
|
||||
|
||||
/**
|
||||
* the column name for the ATTRIBUTE_TEMPLATECOL field
|
||||
*/
|
||||
const ATTRIBUTE_TEMPLATECOL = 'attribute_template.ATTRIBUTE_TEMPLATECOL';
|
||||
|
||||
/**
|
||||
* the column name for the CREATED_AT field
|
||||
*/
|
||||
@@ -111,12 +116,12 @@ class AttributeTemplateTableMap extends TableMap
|
||||
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
|
||||
*/
|
||||
protected static $fieldNames = array (
|
||||
self::TYPE_PHPNAME => array('Id', 'AttributeId', 'TemplateId', 'Position', 'CreatedAt', 'UpdatedAt', ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id', 'attributeId', 'templateId', 'position', 'createdAt', 'updatedAt', ),
|
||||
self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID, AttributeTemplateTableMap::ATTRIBUTE_ID, AttributeTemplateTableMap::TEMPLATE_ID, AttributeTemplateTableMap::POSITION, AttributeTemplateTableMap::CREATED_AT, AttributeTemplateTableMap::UPDATED_AT, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID', 'ATTRIBUTE_ID', 'TEMPLATE_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ),
|
||||
self::TYPE_FIELDNAME => array('id', 'attribute_id', 'template_id', 'position', 'created_at', 'updated_at', ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
|
||||
self::TYPE_PHPNAME => array('Id', 'AttributeId', 'TemplateId', 'Position', 'AttributeTemplatecol', 'CreatedAt', 'UpdatedAt', ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id', 'attributeId', 'templateId', 'position', 'attributeTemplatecol', 'createdAt', 'updatedAt', ),
|
||||
self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID, AttributeTemplateTableMap::ATTRIBUTE_ID, AttributeTemplateTableMap::TEMPLATE_ID, AttributeTemplateTableMap::POSITION, AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL, AttributeTemplateTableMap::CREATED_AT, AttributeTemplateTableMap::UPDATED_AT, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID', 'ATTRIBUTE_ID', 'TEMPLATE_ID', 'POSITION', 'ATTRIBUTE_TEMPLATECOL', 'CREATED_AT', 'UPDATED_AT', ),
|
||||
self::TYPE_FIELDNAME => array('id', 'attribute_id', 'template_id', 'position', 'attribute_templatecol', 'created_at', 'updated_at', ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -126,12 +131,12 @@ class AttributeTemplateTableMap extends TableMap
|
||||
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
|
||||
*/
|
||||
protected static $fieldKeys = array (
|
||||
self::TYPE_PHPNAME => array('Id' => 0, 'AttributeId' => 1, 'TemplateId' => 2, 'Position' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'attributeId' => 1, 'templateId' => 2, 'position' => 3, 'createdAt' => 4, 'updatedAt' => 5, ),
|
||||
self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID => 0, AttributeTemplateTableMap::ATTRIBUTE_ID => 1, AttributeTemplateTableMap::TEMPLATE_ID => 2, AttributeTemplateTableMap::POSITION => 3, AttributeTemplateTableMap::CREATED_AT => 4, AttributeTemplateTableMap::UPDATED_AT => 5, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID' => 0, 'ATTRIBUTE_ID' => 1, 'TEMPLATE_ID' => 2, 'POSITION' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ),
|
||||
self::TYPE_FIELDNAME => array('id' => 0, 'attribute_id' => 1, 'template_id' => 2, 'position' => 3, 'created_at' => 4, 'updated_at' => 5, ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
|
||||
self::TYPE_PHPNAME => array('Id' => 0, 'AttributeId' => 1, 'TemplateId' => 2, 'Position' => 3, 'AttributeTemplatecol' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'attributeId' => 1, 'templateId' => 2, 'position' => 3, 'attributeTemplatecol' => 4, 'createdAt' => 5, 'updatedAt' => 6, ),
|
||||
self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID => 0, AttributeTemplateTableMap::ATTRIBUTE_ID => 1, AttributeTemplateTableMap::TEMPLATE_ID => 2, AttributeTemplateTableMap::POSITION => 3, AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL => 4, AttributeTemplateTableMap::CREATED_AT => 5, AttributeTemplateTableMap::UPDATED_AT => 6, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID' => 0, 'ATTRIBUTE_ID' => 1, 'TEMPLATE_ID' => 2, 'POSITION' => 3, 'ATTRIBUTE_TEMPLATECOL' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ),
|
||||
self::TYPE_FIELDNAME => array('id' => 0, 'attribute_id' => 1, 'template_id' => 2, 'position' => 3, 'attribute_templatecol' => 4, 'created_at' => 5, 'updated_at' => 6, ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -155,6 +160,7 @@ class AttributeTemplateTableMap extends TableMap
|
||||
$this->addForeignKey('ATTRIBUTE_ID', 'AttributeId', 'INTEGER', 'attribute', 'ID', true, null, null);
|
||||
$this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', true, null, null);
|
||||
$this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null);
|
||||
$this->addColumn('ATTRIBUTE_TEMPLATECOL', 'AttributeTemplatecol', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
|
||||
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
|
||||
} // initialize()
|
||||
@@ -323,6 +329,7 @@ class AttributeTemplateTableMap extends TableMap
|
||||
$criteria->addSelectColumn(AttributeTemplateTableMap::ATTRIBUTE_ID);
|
||||
$criteria->addSelectColumn(AttributeTemplateTableMap::TEMPLATE_ID);
|
||||
$criteria->addSelectColumn(AttributeTemplateTableMap::POSITION);
|
||||
$criteria->addSelectColumn(AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL);
|
||||
$criteria->addSelectColumn(AttributeTemplateTableMap::CREATED_AT);
|
||||
$criteria->addSelectColumn(AttributeTemplateTableMap::UPDATED_AT);
|
||||
} else {
|
||||
@@ -330,6 +337,7 @@ class AttributeTemplateTableMap extends TableMap
|
||||
$criteria->addSelectColumn($alias . '.ATTRIBUTE_ID');
|
||||
$criteria->addSelectColumn($alias . '.TEMPLATE_ID');
|
||||
$criteria->addSelectColumn($alias . '.POSITION');
|
||||
$criteria->addSelectColumn($alias . '.ATTRIBUTE_TEMPLATECOL');
|
||||
$criteria->addSelectColumn($alias . '.CREATED_AT');
|
||||
$criteria->addSelectColumn($alias . '.UPDATED_AT');
|
||||
}
|
||||
|
||||
@@ -87,12 +87,46 @@ class Product extends BaseProduct
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updateDefaultCategory($defaultCategoryId) {
|
||||
|
||||
// Allow uncategorized products (NULL instead of 0, to bypass delete cascade constraint)
|
||||
if ($defaultCategoryId <= 0) $defaultCategoryId = NULL;
|
||||
|
||||
// Update the default category
|
||||
$productCategory = ProductCategoryQuery::create()
|
||||
->filterByProductId($this->getId())
|
||||
->filterByDefaultCategory(true)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
|
||||
exit;
|
||||
// Delete the old default category
|
||||
if ($productCategory !== null) $productCategory->delete();
|
||||
|
||||
// Add the new default category
|
||||
$productCategory = new ProductCategory();
|
||||
|
||||
$productCategory
|
||||
->setProduct($this)
|
||||
->setCategoryId($defaultCategoryId)
|
||||
->setDefaultCategory(true)
|
||||
->save()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new product, along with the default category ID
|
||||
*
|
||||
* @param int $defaultCategoryId the default category ID of this product
|
||||
* @param float $basePrice the product base price
|
||||
* @param int $priceCurrencyId the price currency Id
|
||||
* @param int $taxRuleId the product tax rule ID
|
||||
* @param float $baseWeight base weight in Kg
|
||||
*/
|
||||
public function create($defaultCategoryId) {
|
||||
|
||||
public function create($defaultCategoryId, $basePrice, $priceCurrencyId, $taxRuleId, $baseWeight) {
|
||||
|
||||
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
|
||||
|
||||
@@ -105,18 +139,13 @@ class Product extends BaseProduct
|
||||
$this->save($con);
|
||||
|
||||
// Add the default category
|
||||
$pc = new ProductCategory();
|
||||
|
||||
$pc
|
||||
->setProduct($this)
|
||||
->setCategoryId($defaultCategoryId)
|
||||
->setDefaultCategory(true)
|
||||
->save($con)
|
||||
;
|
||||
$this->updateDefaultCategory($defaultCategoryId);
|
||||
|
||||
// Set the position
|
||||
$this->setPosition($this->getNextPosition())->save($con);
|
||||
|
||||
$this->setTaxRuleId($taxRuleId);
|
||||
|
||||
// Create an empty product sale element
|
||||
$sale_elements = new ProductSaleElements();
|
||||
|
||||
@@ -125,7 +154,8 @@ class Product extends BaseProduct
|
||||
->setRef($this->getRef())
|
||||
->setPromo(0)
|
||||
->setNewness(0)
|
||||
->setWeight(0)
|
||||
->setWeight($baseWeight)
|
||||
->setIsDefault(true)
|
||||
->save($con)
|
||||
;
|
||||
|
||||
@@ -134,9 +164,9 @@ class Product extends BaseProduct
|
||||
|
||||
$product_price
|
||||
->setProductSaleElements($sale_elements)
|
||||
->setPromoPrice(0)
|
||||
->setPrice(0)
|
||||
->setCurrency(CurrencyQuery::create()->findOneByByDefault(true))
|
||||
->setPromoPrice($basePrice)
|
||||
->setPrice($basePrice)
|
||||
->setCurrencyId($priceCurrencyId)
|
||||
->save($con)
|
||||
;
|
||||
|
||||
|
||||
@@ -11,11 +11,22 @@ class ProductAssociatedContent extends BaseProductAssociatedContent {
|
||||
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our product
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByProductId($this->getProductId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT_ASSOCIATED_CONTENT, new ProductAssociatedContentEvent($this));
|
||||
|
||||
return true;
|
||||
|
||||
@@ -26,4 +26,28 @@ class ProductDocument extends BaseProductDocument
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Document parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setProductId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Document parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getProductId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,28 @@ class ProductImage extends BaseProductImage
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Image parent id
|
||||
*
|
||||
* @param int $parentId parent id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentId($parentId)
|
||||
{
|
||||
$this->setProductId($parentId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image parent id
|
||||
*
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
return $this->getProductId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,8 @@ trait PositionManagementTrait {
|
||||
$result->setDispatcher($this->getDispatcher())->setPosition($my_position)->save();
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
@@ -179,7 +180,10 @@ trait PositionManagementTrait {
|
||||
|
||||
try {
|
||||
foreach ($results as $result) {
|
||||
$result->setDispatcher($this->getDispatcher())->setPosition($result->getPosition() + $delta)->save($cnx);
|
||||
|
||||
$objNewPosition = $result->getPosition() + $delta;
|
||||
|
||||
$result->setDispatcher($this->getDispatcher())->setPosition($objNewPosition)->save($cnx);
|
||||
}
|
||||
|
||||
$this
|
||||
@@ -188,7 +192,8 @@ trait PositionManagementTrait {
|
||||
;
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user