From bb9e1d6999a8724ed38d0424af1b4e6f390604e3 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 21 Sep 2013 14:14:56 +0200 Subject: [PATCH] Finished product features management --- .../Thelia/Core/Template/Loop/Attribute.php | 17 +++++++------ .../lib/Thelia/Core/Template/Loop/Feature.php | 14 +++++++---- .../Model/Tools/PositionManagementTrait.php | 10 +++++--- .../includes/product-attributes-tab.html | 24 +++++++++++++++---- 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Attribute.php b/core/lib/Thelia/Core/Template/Loop/Attribute.php index f7b132a63..cb4a1cfdf 100755 --- a/core/lib/Thelia/Core/Template/Loop/Attribute.php +++ b/core/lib/Thelia/Core/Template/Loop/Attribute.php @@ -112,12 +112,18 @@ class Attribute extends BaseI18nLoop $use_attribute_pos = true; if (null !== $product) { - // Find the template assigned to the product. - $productObj = ProductQuery::create()->findPk($product); + // Find all template assigned to the products. + $products = ProductQuery::create()->findById($product); // Ignore if the product cannot be found. - if ($productObj !== null) - $template = $productObj->getTemplate(); + if ($products !== null) { + + // Create template array + if ($template == null) $template = array(); + + foreach($products as $product) + $template[] = $product->getTemplateId(); + } } if (null !== $template) { @@ -146,9 +152,6 @@ class Attribute extends BaseI18nLoop $orders = $this->getOrder(); - if ($template == null && ($order == "manual" || $order == "manual_reverse")) - throw new \InvalidException(Translator::getInstance()->trans("Can't use manual or manual_reverse order without a 'template' or 'produst' parameter")); - foreach ($orders as $order) { switch ($order) { case "id": diff --git a/core/lib/Thelia/Core/Template/Loop/Feature.php b/core/lib/Thelia/Core/Template/Loop/Feature.php index 45cf206eb..c8fb2b8f1 100755 --- a/core/lib/Thelia/Core/Template/Loop/Feature.php +++ b/core/lib/Thelia/Core/Template/Loop/Feature.php @@ -115,12 +115,18 @@ class Feature extends BaseI18nLoop $use_feature_pos = true; if (null !== $product) { - // Find the template assigned to the product. - $productObj = ProductQuery::create()->findPk($product); + // Find all template assigned to the products. + $products = ProductQuery::create()->findById($product); // Ignore if the product cannot be found. - if ($productObj !== null) - $template = $productObj->getTemplate(); + if ($products !== null) { + + // Create template array + if ($template == null) $template = array(); + + foreach($products as $product) + $template[] = $product->getTemplateId(); + } } if (null !== $template) { diff --git a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php index 0f08ec638..642d07402 100644 --- a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php +++ b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php @@ -126,7 +126,8 @@ trait PositionManagementTrait { $result->setDispatcher($this->getDispatcher())->setPosition($my_position)->save(); $cnx->commit(); - } catch (Exception $e) { + } + catch (Exception $e) { $cnx->rollback(); } } @@ -180,7 +181,9 @@ 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 @@ -189,7 +192,8 @@ trait PositionManagementTrait { ; $cnx->commit(); - } catch (Exception $e) { + } + catch (Exception $e) { $cnx->rollback(); } } diff --git a/templates/admin/default/includes/product-attributes-tab.html b/templates/admin/default/includes/product-attributes-tab.html index 796884fd3..b245e22ec 100644 --- a/templates/admin/default/includes/product-attributes-tab.html +++ b/templates/admin/default/includes/product-attributes-tab.html @@ -10,7 +10,11 @@
-

{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." + tpl_mgmt_url={url path='/admin/configuration/templates'} + } +

@@ -75,6 +85,12 @@

{intl l='Product Features'}

+

{intl + l="You can change feature products and their positions in the template configuration page." + tpl_mgmt_url={url path='/admin/configuration/templates/update' template_id=$TEMPLATE} + } +

+
@@ -88,7 +104,7 @@ - {loop name="product-features" type="feature" order="manual" product="$product_id" backend_context="1" lang="$edit_language_id"} + {loop name="product-features" type="feature" order="manual" product=$product_id backend_context="1" lang="$edit_language_id"} @@ -144,9 +160,9 @@ {elseloop rel="product-features"} -
{$TITLE}
+
- {intl l="This product contains no features"} + {intl l="This product template does not contains any features"}