diff --git a/core/lib/Thelia/Action/Product.php b/core/lib/Thelia/Action/Product.php index 5b80436a3..47576c8cc 100644 --- a/core/lib/Thelia/Action/Product.php +++ b/core/lib/Thelia/Action/Product.php @@ -54,6 +54,10 @@ use Thelia\Model\FeatureQuery; use Thelia\Core\Event\FeatureProductDeleteEvent; use Thelia\Model\FeatureProductQuery; use Thelia\Model\ProductCategoryQuery; +use Thelia\Core\Event\ProductSetTemplateEvent; +use Thelia\Model\AttributeCombinationQuery; +use Thelia\Core\Template\Loop\ProductSaleElements; +use Thelia\Model\ProductSaleElementsQuery; class Product extends BaseAction implements EventSubscriberInterface { @@ -235,6 +239,24 @@ class Product extends BaseAction implements EventSubscriberInterface ; } + public function setProductTemplate(ProductSetTemplateEvent $event) { + + $product = $event->getProduct(); + + // Delete all product feature relations + FeatureProductQuery::create()->filterByProduct($product)->delete(); + + // Delete all product attributes sale elements + ProductSaleElementsQuery::create()->filterByProduct($product)->delete(); + + // Update the product template + $template_id = $event->getTemplateId(); + + // Set it to null if it's zero. + if ($template_id <= 0) $template_id = NULL; + + $product->setTemplateId($template_id)->save(); + } /** * Changes position, selecting absolute ou relative change. @@ -308,19 +330,13 @@ echo "value=".$event->getFeatureValue(); public function deleteFeatureProductValue(FeatureProductDeleteEvent $event) { - $featureProduct = new FeatureProduct(); - - $featureProduct - ->setDispatcher($this->getDispatcher()) - - ->setProductId($event->getProductId()) - ->setFeatureId($event->getFeatureId()) - - ->delete(); + $featureProduct = FeatureProductQuery::create() + ->filterByProductId($event->getProductId()) + ->filterByFeatureId($event->getFeatureId()) + ->delete() ; -echo "
Delete p=".$event->getProductId().", f=".$event->getFeatureId(); - $event->setFeatureProduct($featureProduct); + echo "
Delete p=".$event->getProductId().", f=".$event->getFeatureId(); } /** @@ -343,8 +359,11 @@ echo "
Delete p=".$event->getProductId().", f=".$event->getFeatureId(); TheliaEvents::PRODUCT_ADD_ACCESSORY => array("addAccessory", 128), TheliaEvents::PRODUCT_REMOVE_ACCESSORY => array("removeAccessory", 128), + TheliaEvents::PRODUCT_SET_TEMPLATE => array("setProductTemplate", 128), + TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE => array("updateFeatureProductValue", 128), TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE => array("deleteFeatureProductValue", 128), + ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 4d176d2fc..f345b0b5a 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -185,6 +185,9 @@ + + Thelia\Controller\Admin\ProductController::setProductTemplateAction + Thelia\Controller\Admin\ProductController::updateAttributesAndFeaturesAction diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 45bd94186..c36ebcec1 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -47,6 +47,7 @@ use Thelia\Core\Event\FeatureProductUpdateEvent; use Thelia\Model\FeatureQuery; use Thelia\Core\Event\FeatureProductDeleteEvent; use Thelia\Model\FeatureTemplateQuery; +use Thelia\Core\Event\ProductSetTemplateEvent; /** * Manages products @@ -479,12 +480,36 @@ class ProductController extends AbstractCrudController $this->redirectToEditionTemplate(); } + + /** + * Change product template for a given product. + * + * @param unknown $productId + */ + public function setProductTemplateAction($productId) { + // Check current user authorization + if (null !== $response = $this->checkAuth('admin.products.update')) return $response; + + $product = ProductQuery::create()->findPk($productId); + + if ($product != null) { + + $template_id = intval($this->getRequest()->get('template_id', 0)); + + $this->dispatch( + TheliaEvents::PRODUCT_SET_TEMPLATE, + new ProductSetTemplateEvent($product, $template_id) + ); + } + + $this->redirectToEditionTemplate(); + } + /** * Update product attributes and features */ public function updateAttributesAndFeaturesAction($productId) { - // et all features for the product's template $product = ProductQuery::create()->findPk($productId); if ($product != null) { @@ -492,6 +517,7 @@ class ProductController extends AbstractCrudController $featureTemplate = FeatureTemplateQuery::create()->filterByTemplateId($product->getTemplateId())->find(); if ($featureTemplate !== null) { + // Get all features for the template attached to this product $allFeatures = FeatureQuery::create() ->filterByFeatureTemplate($featureTemplate) @@ -499,17 +525,17 @@ class ProductController extends AbstractCrudController $updatedFeatures = array(); - // Update all features values + // Update all features values, starting with feature av. values $featureValues = $this->getRequest()->get('feature_value', array()); -echo "
list: "; print_r($featureValues); + foreach($featureValues as $featureId => $featureValueList) { - // Delete all values for this feature. + // Delete all features av. for this feature. $event = new FeatureProductDeleteEvent($productId, $featureId); $this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event); - // Add all selected values + // Add then all selected values foreach($featureValueList as $featureValue) { $event = new FeatureProductUpdateEvent($productId, $featureId, $featureValue); @@ -521,7 +547,7 @@ echo "
list: "; print_r($featureValues); // Update then features text values $featureTextValues = $this->getRequest()->get('feature_text_value', array()); -echo "
free text"; print_r($featureTextValues); + foreach($featureTextValues as $featureId => $featureValue) { // considere empty text as empty feature value (e.g., we will delete it) @@ -536,16 +562,23 @@ echo "
free text"; print_r($featureTextValues); // Delete features which don't have any values foreach($allFeatures as $feature) { + if (! in_array($feature->getId(), $updatedFeatures)) { $event = new FeatureProductDeleteEvent($productId, $feature->getId()); -echo "
delete $productId, ".$feature->getId()." - "; + $this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event); } } } -exit; } - $this->redirectToEditionTemplate(); + // If we have to stay on the same page, do not redirect to the succesUrl, + // just redirect to the edit page again. + if ($this->getRequest()->get('save_mode') == 'stay') { + $this->redirectToEditionTemplate($this->getRequest()); + } + + // Redirect to the category/product list + $this->redirectToListTemplate(); } } diff --git a/core/lib/Thelia/Core/Event/ProductSetTemplateEvent.php b/core/lib/Thelia/Core/Event/ProductSetTemplateEvent.php new file mode 100644 index 000000000..c7c6dc760 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ProductSetTemplateEvent.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; +use Thelia\Model\Product; +use Thelia\Core\Event\ActionEvent; + +class ProductSetTemplateEvent extends ProductEvent +{ + public $template_id = null; + + public function __construct(Product $product = null, $template_id) + { + parent::__construct($product); + + $this->template_id = $template_id; + } + + public function getTemplateId() + { + return $this->template_id; + } + + public function setTemplateId($template_id) + { + $this->template_id = $template_id; + + return $this; + } + +} diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index aee3d81e9..fb865c363 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -187,6 +187,8 @@ final class TheliaEvents const PRODUCT_ADD_CONTENT = "action.productAddContent"; const PRODUCT_REMOVE_CONTENT = "action.productRemoveContent"; + const PRODUCT_SET_TEMPLATE = "action.productSetTemplate"; + const PRODUCT_ADD_ACCESSORY = "action.productAddAccessory"; const PRODUCT_REMOVE_ACCESSORY = "action.productRemoveAccessory"; const PRODUCT_UPDATE_ACCESSORY_POSITION = "action.updateProductPosition"; diff --git a/core/lib/Thelia/Model/Base/AttributeCombination.php b/core/lib/Thelia/Model/Base/AttributeCombination.php index 14868edf7..ef840a5a1 100644 --- a/core/lib/Thelia/Model/Base/AttributeCombination.php +++ b/core/lib/Thelia/Model/Base/AttributeCombination.php @@ -78,13 +78,6 @@ abstract class AttributeCombination implements ActiveRecordInterface */ protected $product_sale_elements_id; - /** - * 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 @@ -120,24 +113,11 @@ abstract class AttributeCombination implements ActiveRecordInterface */ protected $alreadyInSave = false; - /** - * 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\AttributeCombination object. - * @see applyDefaults() */ public function __construct() { - $this->applyDefaultValues(); } /** @@ -420,17 +400,6 @@ abstract class AttributeCombination implements ActiveRecordInterface return $this->product_sale_elements_id; } - /** - * Get the [is_default] column value. - * - * @return boolean - */ - public function getIsDefault() - { - - return $this->is_default; - } - /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -546,35 +515,6 @@ abstract class AttributeCombination implements ActiveRecordInterface return $this; } // setProductSaleElementsId() - /** - * 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\AttributeCombination 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[] = AttributeCombinationTableMap::IS_DEFAULT; - } - - - return $this; - } // setIsDefault() - /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -627,10 +567,6 @@ abstract class AttributeCombination implements ActiveRecordInterface */ public function hasOnlyDefaultValues() { - if ($this->is_default !== false) { - return false; - } - // otherwise, everything was equal, so return TRUE return true; } // hasOnlyDefaultValues() @@ -667,16 +603,13 @@ abstract class AttributeCombination implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AttributeCombinationTableMap::translateFieldName('ProductSaleElementsId', TableMap::TYPE_PHPNAME, $indexType)]; $this->product_sale_elements_id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AttributeCombinationTableMap::translateFieldName('IsDefault', TableMap::TYPE_PHPNAME, $indexType)]; - $this->is_default = (null !== $col) ? (boolean) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AttributeCombinationTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AttributeCombinationTableMap::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 : AttributeCombinationTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AttributeCombinationTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -689,7 +622,7 @@ abstract class AttributeCombination implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 6; // 6 = AttributeCombinationTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 5; // 5 = AttributeCombinationTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\AttributeCombination object", 0, $e); @@ -952,9 +885,6 @@ abstract class AttributeCombination implements ActiveRecordInterface if ($this->isColumnModified(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID)) { $modifiedColumns[':p' . $index++] = 'PRODUCT_SALE_ELEMENTS_ID'; } - if ($this->isColumnModified(AttributeCombinationTableMap::IS_DEFAULT)) { - $modifiedColumns[':p' . $index++] = 'IS_DEFAULT'; - } if ($this->isColumnModified(AttributeCombinationTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -981,9 +911,6 @@ abstract class AttributeCombination implements ActiveRecordInterface case 'PRODUCT_SALE_ELEMENTS_ID': $stmt->bindValue($identifier, $this->product_sale_elements_id, PDO::PARAM_INT); 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; @@ -1055,12 +982,9 @@ abstract class AttributeCombination implements ActiveRecordInterface return $this->getProductSaleElementsId(); break; case 3: - return $this->getIsDefault(); - break; - case 4: return $this->getCreatedAt(); break; - case 5: + case 4: return $this->getUpdatedAt(); break; default: @@ -1095,9 +1019,8 @@ abstract class AttributeCombination implements ActiveRecordInterface $keys[0] => $this->getAttributeId(), $keys[1] => $this->getAttributeAvId(), $keys[2] => $this->getProductSaleElementsId(), - $keys[3] => $this->getIsDefault(), - $keys[4] => $this->getCreatedAt(), - $keys[5] => $this->getUpdatedAt(), + $keys[3] => $this->getCreatedAt(), + $keys[4] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1159,12 +1082,9 @@ abstract class AttributeCombination implements ActiveRecordInterface $this->setProductSaleElementsId($value); break; case 3: - $this->setIsDefault($value); - break; - case 4: $this->setCreatedAt($value); break; - case 5: + case 4: $this->setUpdatedAt($value); break; } // switch() @@ -1194,9 +1114,8 @@ abstract class AttributeCombination implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setAttributeId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setAttributeAvId($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setProductSaleElementsId($arr[$keys[2]]); - 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]]); + if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); } /** @@ -1211,7 +1130,6 @@ abstract class AttributeCombination implements ActiveRecordInterface if ($this->isColumnModified(AttributeCombinationTableMap::ATTRIBUTE_ID)) $criteria->add(AttributeCombinationTableMap::ATTRIBUTE_ID, $this->attribute_id); if ($this->isColumnModified(AttributeCombinationTableMap::ATTRIBUTE_AV_ID)) $criteria->add(AttributeCombinationTableMap::ATTRIBUTE_AV_ID, $this->attribute_av_id); if ($this->isColumnModified(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID)) $criteria->add(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, $this->product_sale_elements_id); - if ($this->isColumnModified(AttributeCombinationTableMap::IS_DEFAULT)) $criteria->add(AttributeCombinationTableMap::IS_DEFAULT, $this->is_default); if ($this->isColumnModified(AttributeCombinationTableMap::CREATED_AT)) $criteria->add(AttributeCombinationTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(AttributeCombinationTableMap::UPDATED_AT)) $criteria->add(AttributeCombinationTableMap::UPDATED_AT, $this->updated_at); @@ -1290,7 +1208,6 @@ abstract class AttributeCombination implements ActiveRecordInterface $copyObj->setAttributeId($this->getAttributeId()); $copyObj->setAttributeAvId($this->getAttributeAvId()); $copyObj->setProductSaleElementsId($this->getProductSaleElementsId()); - $copyObj->setIsDefault($this->getIsDefault()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); if ($makeNew) { @@ -1481,12 +1398,10 @@ abstract class AttributeCombination implements ActiveRecordInterface $this->attribute_id = null; $this->attribute_av_id = null; $this->product_sale_elements_id = 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); diff --git a/core/lib/Thelia/Model/Base/AttributeCombinationQuery.php b/core/lib/Thelia/Model/Base/AttributeCombinationQuery.php index e0f4ee0ea..291ff7725 100644 --- a/core/lib/Thelia/Model/Base/AttributeCombinationQuery.php +++ b/core/lib/Thelia/Model/Base/AttributeCombinationQuery.php @@ -24,14 +24,12 @@ use Thelia\Model\Map\AttributeCombinationTableMap; * @method ChildAttributeCombinationQuery orderByAttributeId($order = Criteria::ASC) Order by the attribute_id column * @method ChildAttributeCombinationQuery orderByAttributeAvId($order = Criteria::ASC) Order by the attribute_av_id column * @method ChildAttributeCombinationQuery orderByProductSaleElementsId($order = Criteria::ASC) Order by the product_sale_elements_id column - * @method ChildAttributeCombinationQuery orderByIsDefault($order = Criteria::ASC) Order by the is_default column * @method ChildAttributeCombinationQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildAttributeCombinationQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildAttributeCombinationQuery groupByAttributeId() Group by the attribute_id column * @method ChildAttributeCombinationQuery groupByAttributeAvId() Group by the attribute_av_id column * @method ChildAttributeCombinationQuery groupByProductSaleElementsId() Group by the product_sale_elements_id column - * @method ChildAttributeCombinationQuery groupByIsDefault() Group by the is_default column * @method ChildAttributeCombinationQuery groupByCreatedAt() Group by the created_at column * @method ChildAttributeCombinationQuery groupByUpdatedAt() Group by the updated_at column * @@ -57,14 +55,12 @@ use Thelia\Model\Map\AttributeCombinationTableMap; * @method ChildAttributeCombination findOneByAttributeId(int $attribute_id) Return the first ChildAttributeCombination filtered by the attribute_id column * @method ChildAttributeCombination findOneByAttributeAvId(int $attribute_av_id) Return the first ChildAttributeCombination filtered by the attribute_av_id column * @method ChildAttributeCombination findOneByProductSaleElementsId(int $product_sale_elements_id) Return the first ChildAttributeCombination filtered by the product_sale_elements_id column - * @method ChildAttributeCombination findOneByIsDefault(boolean $is_default) Return the first ChildAttributeCombination filtered by the is_default column * @method ChildAttributeCombination findOneByCreatedAt(string $created_at) Return the first ChildAttributeCombination filtered by the created_at column * @method ChildAttributeCombination findOneByUpdatedAt(string $updated_at) Return the first ChildAttributeCombination filtered by the updated_at column * * @method array findByAttributeId(int $attribute_id) Return ChildAttributeCombination objects filtered by the attribute_id column * @method array findByAttributeAvId(int $attribute_av_id) Return ChildAttributeCombination objects filtered by the attribute_av_id column * @method array findByProductSaleElementsId(int $product_sale_elements_id) Return ChildAttributeCombination objects filtered by the product_sale_elements_id column - * @method array findByIsDefault(boolean $is_default) Return ChildAttributeCombination objects filtered by the is_default column * @method array findByCreatedAt(string $created_at) Return ChildAttributeCombination objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildAttributeCombination objects filtered by the updated_at column * @@ -155,7 +151,7 @@ abstract class AttributeCombinationQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ATTRIBUTE_ID, ATTRIBUTE_AV_ID, PRODUCT_SALE_ELEMENTS_ID, IS_DEFAULT, CREATED_AT, UPDATED_AT FROM attribute_combination WHERE ATTRIBUTE_ID = :p0 AND ATTRIBUTE_AV_ID = :p1 AND PRODUCT_SALE_ELEMENTS_ID = :p2'; + $sql = 'SELECT ATTRIBUTE_ID, ATTRIBUTE_AV_ID, PRODUCT_SALE_ELEMENTS_ID, CREATED_AT, UPDATED_AT FROM attribute_combination WHERE ATTRIBUTE_ID = :p0 AND ATTRIBUTE_AV_ID = :p1 AND PRODUCT_SALE_ELEMENTS_ID = :p2'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); @@ -389,33 +385,6 @@ abstract class AttributeCombinationQuery extends ModelCriteria return $this->addUsingAlias(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, $productSaleElementsId, $comparison); } - /** - * Filter the query on the is_default column - * - * Example usage: - * - * $query->filterByIsDefault(true); // WHERE is_default = true - * $query->filterByIsDefault('yes'); // WHERE is_default = true - * - * - * @param boolean|string $isDefault The value to use as filter. - * Non-boolean arguments are converted using the following rules: - * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true - * * 0, '0', 'false', 'off', and 'no' are converted to boolean false - * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildAttributeCombinationQuery 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(AttributeCombinationTableMap::IS_DEFAULT, $isDefault, $comparison); - } - /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/ProductSaleElements.php b/core/lib/Thelia/Model/Base/ProductSaleElements.php index fa887dc8a..eb6aa2b1a 100644 --- a/core/lib/Thelia/Model/Base/ProductSaleElements.php +++ b/core/lib/Thelia/Model/Base/ProductSaleElements.php @@ -103,10 +103,18 @@ abstract class ProductSaleElements implements ActiveRecordInterface /** * The value for the weight field. + * Note: this column has a database default value of: 0 * @var double */ protected $weight; + /** + * 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 @@ -178,6 +186,8 @@ abstract class ProductSaleElements implements ActiveRecordInterface { $this->promo = 0; $this->newness = 0; + $this->weight = 0; + $this->is_default = false; } /** @@ -513,6 +523,17 @@ abstract class ProductSaleElements implements ActiveRecordInterface return $this->weight; } + /** + * Get the [is_default] column value. + * + * @return boolean + */ + public function getIsDefault() + { + + return $this->is_default; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -704,6 +725,35 @@ abstract class ProductSaleElements implements ActiveRecordInterface return $this; } // setWeight() + /** + * 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\ProductSaleElements 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[] = ProductSaleElementsTableMap::IS_DEFAULT; + } + + + return $this; + } // setIsDefault() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -764,6 +814,14 @@ abstract class ProductSaleElements implements ActiveRecordInterface return false; } + if ($this->weight !== 0) { + return false; + } + + if ($this->is_default !== false) { + return false; + } + // otherwise, everything was equal, so return TRUE return true; } // hasOnlyDefaultValues() @@ -812,13 +870,16 @@ abstract class ProductSaleElements implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ProductSaleElementsTableMap::translateFieldName('Weight', TableMap::TYPE_PHPNAME, $indexType)]; $this->weight = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductSaleElementsTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : ProductSaleElementsTableMap::translateFieldName('IsDefault', TableMap::TYPE_PHPNAME, $indexType)]; + $this->is_default = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : ProductSaleElementsTableMap::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 ? 8 + $startcol : ProductSaleElementsTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : ProductSaleElementsTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -831,7 +892,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 9; // 9 = ProductSaleElementsTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 10; // 10 = ProductSaleElementsTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\ProductSaleElements object", 0, $e); @@ -1145,6 +1206,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface if ($this->isColumnModified(ProductSaleElementsTableMap::WEIGHT)) { $modifiedColumns[':p' . $index++] = 'WEIGHT'; } + if ($this->isColumnModified(ProductSaleElementsTableMap::IS_DEFAULT)) { + $modifiedColumns[':p' . $index++] = 'IS_DEFAULT'; + } if ($this->isColumnModified(ProductSaleElementsTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1183,6 +1247,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface case 'WEIGHT': $stmt->bindValue($identifier, $this->weight, 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; @@ -1273,9 +1340,12 @@ abstract class ProductSaleElements implements ActiveRecordInterface return $this->getWeight(); break; case 7: - return $this->getCreatedAt(); + return $this->getIsDefault(); break; case 8: + return $this->getCreatedAt(); + break; + case 9: return $this->getUpdatedAt(); break; default: @@ -1314,8 +1384,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface $keys[4] => $this->getPromo(), $keys[5] => $this->getNewness(), $keys[6] => $this->getWeight(), - $keys[7] => $this->getCreatedAt(), - $keys[8] => $this->getUpdatedAt(), + $keys[7] => $this->getIsDefault(), + $keys[8] => $this->getCreatedAt(), + $keys[9] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach($virtualColumns as $key => $virtualColumn) @@ -1392,9 +1463,12 @@ abstract class ProductSaleElements implements ActiveRecordInterface $this->setWeight($value); break; case 7: - $this->setCreatedAt($value); + $this->setIsDefault($value); break; case 8: + $this->setCreatedAt($value); + break; + case 9: $this->setUpdatedAt($value); break; } // switch() @@ -1428,8 +1502,9 @@ abstract class ProductSaleElements implements ActiveRecordInterface if (array_key_exists($keys[4], $arr)) $this->setPromo($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setNewness($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setWeight($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]); + if (array_key_exists($keys[7], $arr)) $this->setIsDefault($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setUpdatedAt($arr[$keys[9]]); } /** @@ -1448,6 +1523,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface if ($this->isColumnModified(ProductSaleElementsTableMap::PROMO)) $criteria->add(ProductSaleElementsTableMap::PROMO, $this->promo); if ($this->isColumnModified(ProductSaleElementsTableMap::NEWNESS)) $criteria->add(ProductSaleElementsTableMap::NEWNESS, $this->newness); if ($this->isColumnModified(ProductSaleElementsTableMap::WEIGHT)) $criteria->add(ProductSaleElementsTableMap::WEIGHT, $this->weight); + if ($this->isColumnModified(ProductSaleElementsTableMap::IS_DEFAULT)) $criteria->add(ProductSaleElementsTableMap::IS_DEFAULT, $this->is_default); if ($this->isColumnModified(ProductSaleElementsTableMap::CREATED_AT)) $criteria->add(ProductSaleElementsTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ProductSaleElementsTableMap::UPDATED_AT)) $criteria->add(ProductSaleElementsTableMap::UPDATED_AT, $this->updated_at); @@ -1519,6 +1595,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface $copyObj->setPromo($this->getPromo()); $copyObj->setNewness($this->getNewness()); $copyObj->setWeight($this->getWeight()); + $copyObj->setIsDefault($this->getIsDefault()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -2445,6 +2522,7 @@ abstract class ProductSaleElements implements ActiveRecordInterface $this->promo = null; $this->newness = null; $this->weight = null; + $this->is_default = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php b/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php index 6e9068002..c8201ed0b 100644 --- a/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php +++ b/core/lib/Thelia/Model/Base/ProductSaleElementsQuery.php @@ -28,6 +28,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method ChildProductSaleElementsQuery orderByPromo($order = Criteria::ASC) Order by the promo column * @method ChildProductSaleElementsQuery orderByNewness($order = Criteria::ASC) Order by the newness column * @method ChildProductSaleElementsQuery orderByWeight($order = Criteria::ASC) Order by the weight column + * @method ChildProductSaleElementsQuery orderByIsDefault($order = Criteria::ASC) Order by the is_default column * @method ChildProductSaleElementsQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildProductSaleElementsQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -38,6 +39,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method ChildProductSaleElementsQuery groupByPromo() Group by the promo column * @method ChildProductSaleElementsQuery groupByNewness() Group by the newness column * @method ChildProductSaleElementsQuery groupByWeight() Group by the weight column + * @method ChildProductSaleElementsQuery groupByIsDefault() Group by the is_default column * @method ChildProductSaleElementsQuery groupByCreatedAt() Group by the created_at column * @method ChildProductSaleElementsQuery groupByUpdatedAt() Group by the updated_at column * @@ -71,6 +73,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method ChildProductSaleElements findOneByPromo(int $promo) Return the first ChildProductSaleElements filtered by the promo column * @method ChildProductSaleElements findOneByNewness(int $newness) Return the first ChildProductSaleElements filtered by the newness column * @method ChildProductSaleElements findOneByWeight(double $weight) Return the first ChildProductSaleElements filtered by the weight column + * @method ChildProductSaleElements findOneByIsDefault(boolean $is_default) Return the first ChildProductSaleElements filtered by the is_default column * @method ChildProductSaleElements findOneByCreatedAt(string $created_at) Return the first ChildProductSaleElements filtered by the created_at column * @method ChildProductSaleElements findOneByUpdatedAt(string $updated_at) Return the first ChildProductSaleElements filtered by the updated_at column * @@ -81,6 +84,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; * @method array findByPromo(int $promo) Return ChildProductSaleElements objects filtered by the promo column * @method array findByNewness(int $newness) Return ChildProductSaleElements objects filtered by the newness column * @method array findByWeight(double $weight) Return ChildProductSaleElements objects filtered by the weight column + * @method array findByIsDefault(boolean $is_default) Return ChildProductSaleElements objects filtered by the is_default column * @method array findByCreatedAt(string $created_at) Return ChildProductSaleElements objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildProductSaleElements objects filtered by the updated_at column * @@ -171,7 +175,7 @@ abstract class ProductSaleElementsQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, PRODUCT_ID, REF, QUANTITY, PROMO, NEWNESS, WEIGHT, CREATED_AT, UPDATED_AT FROM product_sale_elements WHERE ID = :p0'; + $sql = 'SELECT ID, PRODUCT_ID, REF, QUANTITY, PROMO, NEWNESS, WEIGHT, IS_DEFAULT, CREATED_AT, UPDATED_AT FROM product_sale_elements WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -537,6 +541,33 @@ abstract class ProductSaleElementsQuery extends ModelCriteria return $this->addUsingAlias(ProductSaleElementsTableMap::WEIGHT, $weight, $comparison); } + /** + * Filter the query on the is_default column + * + * Example usage: + * + * $query->filterByIsDefault(true); // WHERE is_default = true + * $query->filterByIsDefault('yes'); // WHERE is_default = true + * + * + * @param boolean|string $isDefault The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildProductSaleElementsQuery 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(ProductSaleElementsTableMap::IS_DEFAULT, $isDefault, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Map/AttributeCombinationTableMap.php b/core/lib/Thelia/Model/Map/AttributeCombinationTableMap.php index 031ecfd81..c13b85bbf 100644 --- a/core/lib/Thelia/Model/Map/AttributeCombinationTableMap.php +++ b/core/lib/Thelia/Model/Map/AttributeCombinationTableMap.php @@ -57,7 +57,7 @@ class AttributeCombinationTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 6; + const NUM_COLUMNS = 5; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class AttributeCombinationTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 6; + const NUM_HYDRATE_COLUMNS = 5; /** * the column name for the ATTRIBUTE_ID field @@ -84,11 +84,6 @@ class AttributeCombinationTableMap extends TableMap */ const PRODUCT_SALE_ELEMENTS_ID = 'attribute_combination.PRODUCT_SALE_ELEMENTS_ID'; - /** - * the column name for the IS_DEFAULT field - */ - const IS_DEFAULT = 'attribute_combination.IS_DEFAULT'; - /** * the column name for the CREATED_AT field */ @@ -111,12 +106,12 @@ class AttributeCombinationTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('AttributeId', 'AttributeAvId', 'ProductSaleElementsId', 'IsDefault', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('attributeId', 'attributeAvId', 'productSaleElementsId', 'isDefault', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AttributeCombinationTableMap::ATTRIBUTE_ID, AttributeCombinationTableMap::ATTRIBUTE_AV_ID, AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, AttributeCombinationTableMap::IS_DEFAULT, AttributeCombinationTableMap::CREATED_AT, AttributeCombinationTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ATTRIBUTE_ID', 'ATTRIBUTE_AV_ID', 'PRODUCT_SALE_ELEMENTS_ID', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('attribute_id', 'attribute_av_id', 'product_sale_elements_id', 'is_default', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + self::TYPE_PHPNAME => array('AttributeId', 'AttributeAvId', 'ProductSaleElementsId', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('attributeId', 'attributeAvId', 'productSaleElementsId', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AttributeCombinationTableMap::ATTRIBUTE_ID, AttributeCombinationTableMap::ATTRIBUTE_AV_ID, AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, AttributeCombinationTableMap::CREATED_AT, AttributeCombinationTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ATTRIBUTE_ID', 'ATTRIBUTE_AV_ID', 'PRODUCT_SALE_ELEMENTS_ID', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('attribute_id', 'attribute_av_id', 'product_sale_elements_id', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) ); /** @@ -126,12 +121,12 @@ class AttributeCombinationTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('AttributeId' => 0, 'AttributeAvId' => 1, 'ProductSaleElementsId' => 2, 'IsDefault' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), - self::TYPE_STUDLYPHPNAME => array('attributeId' => 0, 'attributeAvId' => 1, 'productSaleElementsId' => 2, 'isDefault' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), - self::TYPE_COLNAME => array(AttributeCombinationTableMap::ATTRIBUTE_ID => 0, AttributeCombinationTableMap::ATTRIBUTE_AV_ID => 1, AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID => 2, AttributeCombinationTableMap::IS_DEFAULT => 3, AttributeCombinationTableMap::CREATED_AT => 4, AttributeCombinationTableMap::UPDATED_AT => 5, ), - self::TYPE_RAW_COLNAME => array('ATTRIBUTE_ID' => 0, 'ATTRIBUTE_AV_ID' => 1, 'PRODUCT_SALE_ELEMENTS_ID' => 2, 'IS_DEFAULT' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), - self::TYPE_FIELDNAME => array('attribute_id' => 0, 'attribute_av_id' => 1, 'product_sale_elements_id' => 2, 'is_default' => 3, 'created_at' => 4, 'updated_at' => 5, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + self::TYPE_PHPNAME => array('AttributeId' => 0, 'AttributeAvId' => 1, 'ProductSaleElementsId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), + self::TYPE_STUDLYPHPNAME => array('attributeId' => 0, 'attributeAvId' => 1, 'productSaleElementsId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), + self::TYPE_COLNAME => array(AttributeCombinationTableMap::ATTRIBUTE_ID => 0, AttributeCombinationTableMap::ATTRIBUTE_AV_ID => 1, AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID => 2, AttributeCombinationTableMap::CREATED_AT => 3, AttributeCombinationTableMap::UPDATED_AT => 4, ), + self::TYPE_RAW_COLNAME => array('ATTRIBUTE_ID' => 0, 'ATTRIBUTE_AV_ID' => 1, 'PRODUCT_SALE_ELEMENTS_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), + self::TYPE_FIELDNAME => array('attribute_id' => 0, 'attribute_av_id' => 1, 'product_sale_elements_id' => 2, 'created_at' => 3, 'updated_at' => 4, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) ); /** @@ -153,7 +148,6 @@ class AttributeCombinationTableMap extends TableMap $this->addForeignPrimaryKey('ATTRIBUTE_ID', 'AttributeId', 'INTEGER' , 'attribute', 'ID', true, null, null); $this->addForeignPrimaryKey('ATTRIBUTE_AV_ID', 'AttributeAvId', 'INTEGER' , 'attribute_av', 'ID', true, null, null); $this->addForeignPrimaryKey('PRODUCT_SALE_ELEMENTS_ID', 'ProductSaleElementsId', 'INTEGER' , 'product_sale_elements', 'ID', 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() @@ -371,14 +365,12 @@ class AttributeCombinationTableMap extends TableMap $criteria->addSelectColumn(AttributeCombinationTableMap::ATTRIBUTE_ID); $criteria->addSelectColumn(AttributeCombinationTableMap::ATTRIBUTE_AV_ID); $criteria->addSelectColumn(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID); - $criteria->addSelectColumn(AttributeCombinationTableMap::IS_DEFAULT); $criteria->addSelectColumn(AttributeCombinationTableMap::CREATED_AT); $criteria->addSelectColumn(AttributeCombinationTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ATTRIBUTE_ID'); $criteria->addSelectColumn($alias . '.ATTRIBUTE_AV_ID'); $criteria->addSelectColumn($alias . '.PRODUCT_SALE_ELEMENTS_ID'); - $criteria->addSelectColumn($alias . '.IS_DEFAULT'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php b/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php index 70b3819f9..1e894ef24 100644 --- a/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php +++ b/core/lib/Thelia/Model/Map/ProductSaleElementsTableMap.php @@ -57,7 +57,7 @@ class ProductSaleElementsTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 9; + const NUM_COLUMNS = 10; /** * The number of lazy-loaded columns @@ -67,7 +67,7 @@ class ProductSaleElementsTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 9; + const NUM_HYDRATE_COLUMNS = 10; /** * the column name for the ID field @@ -104,6 +104,11 @@ class ProductSaleElementsTableMap extends TableMap */ const WEIGHT = 'product_sale_elements.WEIGHT'; + /** + * the column name for the IS_DEFAULT field + */ + const IS_DEFAULT = 'product_sale_elements.IS_DEFAULT'; + /** * the column name for the CREATED_AT field */ @@ -126,12 +131,12 @@ class ProductSaleElementsTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'ProductId', 'Ref', 'Quantity', 'Promo', 'Newness', 'Weight', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'ref', 'quantity', 'promo', 'newness', 'weight', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID, ProductSaleElementsTableMap::PRODUCT_ID, ProductSaleElementsTableMap::REF, ProductSaleElementsTableMap::QUANTITY, ProductSaleElementsTableMap::PROMO, ProductSaleElementsTableMap::NEWNESS, ProductSaleElementsTableMap::WEIGHT, ProductSaleElementsTableMap::CREATED_AT, ProductSaleElementsTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'REF', 'QUANTITY', 'PROMO', 'NEWNESS', 'WEIGHT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'product_id', 'ref', 'quantity', 'promo', 'newness', 'weight', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + self::TYPE_PHPNAME => array('Id', 'ProductId', 'Ref', 'Quantity', 'Promo', 'Newness', 'Weight', 'IsDefault', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'productId', 'ref', 'quantity', 'promo', 'newness', 'weight', 'isDefault', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID, ProductSaleElementsTableMap::PRODUCT_ID, ProductSaleElementsTableMap::REF, ProductSaleElementsTableMap::QUANTITY, ProductSaleElementsTableMap::PROMO, ProductSaleElementsTableMap::NEWNESS, ProductSaleElementsTableMap::WEIGHT, ProductSaleElementsTableMap::IS_DEFAULT, ProductSaleElementsTableMap::CREATED_AT, ProductSaleElementsTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'PRODUCT_ID', 'REF', 'QUANTITY', 'PROMO', 'NEWNESS', 'WEIGHT', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'product_id', 'ref', 'quantity', 'promo', 'newness', 'weight', 'is_default', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) ); /** @@ -141,12 +146,12 @@ class ProductSaleElementsTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'Ref' => 2, 'Quantity' => 3, 'Promo' => 4, 'Newness' => 5, 'Weight' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'createdAt' => 7, 'updatedAt' => 8, ), - self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID => 0, ProductSaleElementsTableMap::PRODUCT_ID => 1, ProductSaleElementsTableMap::REF => 2, ProductSaleElementsTableMap::QUANTITY => 3, ProductSaleElementsTableMap::PROMO => 4, ProductSaleElementsTableMap::NEWNESS => 5, ProductSaleElementsTableMap::WEIGHT => 6, ProductSaleElementsTableMap::CREATED_AT => 7, ProductSaleElementsTableMap::UPDATED_AT => 8, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'REF' => 2, 'QUANTITY' => 3, 'PROMO' => 4, 'NEWNESS' => 5, 'WEIGHT' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ), - self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'created_at' => 7, 'updated_at' => 8, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, ) + self::TYPE_PHPNAME => array('Id' => 0, 'ProductId' => 1, 'Ref' => 2, 'Quantity' => 3, 'Promo' => 4, 'Newness' => 5, 'Weight' => 6, 'IsDefault' => 7, 'CreatedAt' => 8, 'UpdatedAt' => 9, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'productId' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'isDefault' => 7, 'createdAt' => 8, 'updatedAt' => 9, ), + self::TYPE_COLNAME => array(ProductSaleElementsTableMap::ID => 0, ProductSaleElementsTableMap::PRODUCT_ID => 1, ProductSaleElementsTableMap::REF => 2, ProductSaleElementsTableMap::QUANTITY => 3, ProductSaleElementsTableMap::PROMO => 4, ProductSaleElementsTableMap::NEWNESS => 5, ProductSaleElementsTableMap::WEIGHT => 6, ProductSaleElementsTableMap::IS_DEFAULT => 7, ProductSaleElementsTableMap::CREATED_AT => 8, ProductSaleElementsTableMap::UPDATED_AT => 9, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'PRODUCT_ID' => 1, 'REF' => 2, 'QUANTITY' => 3, 'PROMO' => 4, 'NEWNESS' => 5, 'WEIGHT' => 6, 'IS_DEFAULT' => 7, 'CREATED_AT' => 8, 'UPDATED_AT' => 9, ), + self::TYPE_FIELDNAME => array('id' => 0, 'product_id' => 1, 'ref' => 2, 'quantity' => 3, 'promo' => 4, 'newness' => 5, 'weight' => 6, 'is_default' => 7, 'created_at' => 8, 'updated_at' => 9, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) ); /** @@ -171,7 +176,8 @@ class ProductSaleElementsTableMap extends TableMap $this->addColumn('QUANTITY', 'Quantity', 'FLOAT', true, null, null); $this->addColumn('PROMO', 'Promo', 'TINYINT', false, null, 0); $this->addColumn('NEWNESS', 'Newness', 'TINYINT', false, null, 0); - $this->addColumn('WEIGHT', 'Weight', 'FLOAT', false, null, null); + $this->addColumn('WEIGHT', 'Weight', 'FLOAT', false, null, 0); + $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() @@ -355,6 +361,7 @@ class ProductSaleElementsTableMap extends TableMap $criteria->addSelectColumn(ProductSaleElementsTableMap::PROMO); $criteria->addSelectColumn(ProductSaleElementsTableMap::NEWNESS); $criteria->addSelectColumn(ProductSaleElementsTableMap::WEIGHT); + $criteria->addSelectColumn(ProductSaleElementsTableMap::IS_DEFAULT); $criteria->addSelectColumn(ProductSaleElementsTableMap::CREATED_AT); $criteria->addSelectColumn(ProductSaleElementsTableMap::UPDATED_AT); } else { @@ -365,6 +372,7 @@ class ProductSaleElementsTableMap extends TableMap $criteria->addSelectColumn($alias . '.PROMO'); $criteria->addSelectColumn($alias . '.NEWNESS'); $criteria->addSelectColumn($alias . '.WEIGHT'); + $criteria->addSelectColumn($alias . '.IS_DEFAULT'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 8521d8dc5..6114b8acf 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -108,7 +108,7 @@ class Product extends BaseProduct ->setProduct($this) ->setCategoryId($defaultCategoryId) ->setDefaultCategory(true) - ->save($con) + ->save() ; } } diff --git a/install/thelia.sql b/install/thelia.sql index efa72b629..503040a88 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -325,7 +325,6 @@ CREATE TABLE `attribute_combination` `attribute_id` INTEGER NOT NULL, `attribute_av_id` INTEGER NOT NULL, `product_sale_elements_id` INTEGER NOT NULL, - `is_default` TINYINT(1) DEFAULT 0, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`attribute_id`,`attribute_av_id`,`product_sale_elements_id`), @@ -363,7 +362,8 @@ CREATE TABLE `product_sale_elements` `quantity` FLOAT NOT NULL, `promo` TINYINT DEFAULT 0, `newness` TINYINT DEFAULT 0, - `weight` FLOAT, + `weight` FLOAT DEFAULT 0, + `is_default` TINYINT(1) DEFAULT 0, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), diff --git a/local/config/schema.xml b/local/config/schema.xml index 98cf32ffb..88a3d2a9d 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -55,7 +55,7 @@ - + @@ -254,7 +254,6 @@ - @@ -282,7 +281,8 @@ - + + diff --git a/templates/admin/default/includes/product-attributes-tab.html b/templates/admin/default/includes/product-attributes-tab.html index c02e4093a..796884fd3 100644 --- a/templates/admin/default/includes/product-attributes-tab.html +++ b/templates/admin/default/includes/product-attributes-tab.html @@ -1,157 +1,175 @@
-
- - +
+
+ - {include - file="includes/inner-form-toolbar.html" - hide_submit_buttons=false - close_url="{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" - } + + -
- {intl l="To use features or attributes on this product, please select a product template. You can define product templates in the Configuration section of the administration."} -
+
+
+
+

{intl l="To use features or attributes on this product, please select a product template. You can define product templates in the Configuration section of the administration."}

-
-
- + -
- +
+ - - - -
-
-
- - {ifloop rel="product_template"} - - {* -- Begin attributes management ------------------------------- *} - -
- {loop name="product_template" type="template" id={$TEMPLATE|default:0}}{/loop} - -
-
-

{intl l='Product Attributes'}

+ + + +
+
-
+ +
+
- {* -- End attributes management ---------------------------------- *} + {* Check if a product template is defined *} - {* -- Begin features management ---------------------------------- *} + {loop name="product_template" type="template" id={$TEMPLATE|default:0}}{/loop} -
-
-
+ {ifloop rel="product_template"} +
+
+

{intl l='Product Attributes and Features'}

-

{intl l='Product Features'}

-

{intl l='Enter here product features'}

+
-
-
- - - - + + - {module_include location='product_features_table_header'} + {include + file="includes/inner-form-toolbar.html" + hide_submit_buttons=false + close_url="{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" + } - - - - {loop name="product-features" type="feature" order="manual" product="$product_id" backend_context="1" lang="$edit_language_id"} - - + {* -- Begin attributes management ------------------------------- *} - + + {module_include location='product_features_table_row'} + + + {/loop} + + {elseloop rel="product-features"} + + + + {/elseloop} + +
{intl l='Feature Name'}{intl l='Feature value for this product'}
{$TITLE} - {* Multiple values *} +
+
+
+

{intl l='Product Attributes'}

- {ifloop rel="product-features-av"} +
Please code me baby, oh yeah ! Code me NOW !
+
+
+
- {loop name="free-text-value" exclude_free_text="true" type="feature_value" product=$product_id feature=$ID backend_context="1" lang="$edit_language_id"} - value={$FEATURE_AV_ID}: {$TITLE}
- {/loop} + {* -- Begin features management ---------------------------------- *} - {capture "select_options"} - {loop name="product-features-av" type="feature-availability" feature=$ID order="manual" backend_context="1" lang="$edit_language_id"} - - {$options_count = $LOOP_COUNT} {* LOOP_COUNT is only available inside the loop ! *} - {/loop} - {/capture} +
+
+
+

{intl l='Product Features'}

-
- -
+
+ + + + + - - {intl l='Use ctrl+clic to select more than one value. You can also clear selected values.' id=$ID} - + {module_include location='product_features_table_header'} - {/ifloop} + + - {* Free feature *} + + {loop name="product-features" type="feature" order="manual" product="$product_id" backend_context="1" lang="$edit_language_id"} + + - {elseloop rel="product-features-av"} - {* Get the free text value *} + + {* load all selected values in an array to speed up things a little *} - {module_include location='product_features_table_row'} + {$selected = array()} - - {/loop} + {loop name="free-text-value" exclude_free_text="true" type="feature_value" product=$product_id feature=$ID backend_context="1" lang="$edit_language_id"} + {$selected[] = $FEATURE_AV_ID} + {/loop} - {elseloop rel="product-features"} - - - - {/elseloop} - -
{intl l='Feature Name'}{intl l='Feature value for this product'}
{$TITLE} + {* Multiple values *} - {loop name="free-text-value" exclude_feature_availability="1" type="feature_value" product=$product_id feature=$ID backend_context="1" lang="$edit_language_id"} - {$feature_value=$FREE_TEXT_VALUE} - {/loop} + {ifloop rel="product-features-av"} - - {/elseloop} -
-
- {intl l="This product contains no features"} -
-
-
-
-
+ {capture "select_options"} + {loop name="product-features-av" type="feature-availability" feature=$ID order="manual" backend_context="1" lang="$edit_language_id"} + - {* -- End features management ------------------------------- *} -
- {/ifloop} + {$options_count = $LOOP_COUNT} {* LOOP_COUNT is only available inside the loop ! *} + {/loop} + {/capture} - {elseloop rel="product_template"} -
-
+
+ +
-
- {intl l="This product is not attached to any product template. If you want to use features or attributes on this product, please select the proper template. You can define product templates in the Configuration section."} -
-
+ + {intl l='Use ctrl+clic to select more than one value. You can also clear selected values.' id=$ID} + + {/ifloop} + + {* Free text *} + + {elseloop rel="product-features-av"} + {* Get the free text value *} + + {loop name="free-text-value" exclude_feature_availability="1" type="feature_value" product=$product_id feature=$ID backend_context="1" lang="$edit_language_id"} + {$feature_value=$FREE_TEXT_VALUE} + {/loop} + + + {/elseloop} +
+
+ {intl l="This product contains no features"} +
+
+ + + + + - {/elseloop} + + {/ifloop} - - + {elseloop rel="product_template"} +
+
+

{* bouuuuuh ! *} +
+ {intl l="This product is not attached to any product template. If you want to use features or attributes on this product, please select the proper template. You can define product templates in the Configuration section."} +
+
+
+ {/elseloop} + \ No newline at end of file diff --git a/templates/admin/default/includes/product-general-tab.html b/templates/admin/default/includes/product-general-tab.html index 71a7247b2..3eb2d6fe0 100644 --- a/templates/admin/default/includes/product-general-tab.html +++ b/templates/admin/default/includes/product-general-tab.html @@ -17,7 +17,7 @@ {/form_field} {form_field form=$form field='success_url'} - + {/form_field} {form_field form=$form field='locale'}