From 5857c07ef0b70a6fd5addb25cb6741dd3bd863ad Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 5 Dec 2013 15:57:56 +0100 Subject: [PATCH] Fixed issue 118 --- core/lib/Thelia/Action/Product.php | 4 ++++ core/lib/Thelia/Action/ProductSaleElement.php | 2 +- .../Controller/Admin/ProductController.php | 2 +- .../Event/Product/ProductSetTemplateEvent.php | 20 +++++++++++++++---- .../Thelia/Core/Template/Loop/Attribute.php | 7 +++++++ .../lib/Thelia/Core/Template/Loop/Feature.php | 7 +++++++ core/lib/Thelia/Model/Product.php | 2 +- 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/core/lib/Thelia/Action/Product.php b/core/lib/Thelia/Action/Product.php index f51d95f28..4fccbf3f6 100644 --- a/core/lib/Thelia/Action/Product.php +++ b/core/lib/Thelia/Action/Product.php @@ -282,8 +282,12 @@ class Product extends BaseAction implements EventSubscriberInterface $product->setTemplateId($template_id)->save($con); + // Create a new default product sale element + $product->createProductSaleElement($con, 0, 0, 0, $event->getCurrencyId(), true); + // Store all the stuff ! $con->commit(); + } catch (\Exception $ex) { $con->rollback(); diff --git a/core/lib/Thelia/Action/ProductSaleElement.php b/core/lib/Thelia/Action/ProductSaleElement.php index 9c40025d8..cad3be374 100644 --- a/core/lib/Thelia/Action/ProductSaleElement.php +++ b/core/lib/Thelia/Action/ProductSaleElement.php @@ -67,7 +67,7 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface if ($salesElement == null) { // Create a new default product sale element - $salesElement = $event->getProduct()->createDefaultProductSaleElement($con, 0, 0, 0, $event->getCurrencyId(), true); + $salesElement = $event->getProduct()->createProductSaleElement($con, 0, 0, 0, $event->getCurrencyId(), true); } else { // This (new) one is the default $salesElement->setIsDefault(true)->save($con); diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 9aa2d279e..d415317c0 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -652,7 +652,7 @@ class ProductController extends AbstractCrudController $this->dispatch( TheliaEvents::PRODUCT_SET_TEMPLATE, - new ProductSetTemplateEvent($product, $template_id) + new ProductSetTemplateEvent($product, $template_id, $this->getCurrentEditionCurrency()->getId()) ); } diff --git a/core/lib/Thelia/Core/Event/Product/ProductSetTemplateEvent.php b/core/lib/Thelia/Core/Event/Product/ProductSetTemplateEvent.php index 1847ca48f..af28ca73f 100644 --- a/core/lib/Thelia/Core/Event/Product/ProductSetTemplateEvent.php +++ b/core/lib/Thelia/Core/Event/Product/ProductSetTemplateEvent.php @@ -22,18 +22,19 @@ /*************************************************************************************/ namespace Thelia\Core\Event\Product; - use Thelia\Model\Product; class ProductSetTemplateEvent extends ProductEvent { - public $template_id = null; + protected $template_id = null; + protected $currency_id = 0; - public function __construct(Product $product = null, $template_id) + public function __construct(Product $product = null, $template_id, $currency_id) { parent::__construct($product); $this->template_id = $template_id; + $this->currency_id = $currency_id; } public function getTemplateId() @@ -48,4 +49,15 @@ class ProductSetTemplateEvent extends ProductEvent return $this; } -} + public function getCurrencyId() + { + return $this->currency_id; + } + + public function setCurrencyId($currency_id) + { + $this->currency_id = $currency_id; + + return $this; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/Attribute.php b/core/lib/Thelia/Core/Template/Loop/Attribute.php index 97b540f96..2225ced66 100755 --- a/core/lib/Thelia/Core/Template/Loop/Attribute.php +++ b/core/lib/Thelia/Core/Template/Loop/Attribute.php @@ -120,6 +120,12 @@ class Attribute extends BaseI18nLoop implements PropelSearchLoopInterface if (! is_null($tpl_id)) $template[] = $tpl_id; } } + + // franck@cqfdev.fr - 05/12/2013 : if the given product has no template + // or if the product cannot be found, do not return anything. + if (empty($template)) { + return null; + } } if (! empty($template)) { @@ -175,6 +181,7 @@ class Attribute extends BaseI18nLoop implements PropelSearchLoopInterface break; } } +echo "s=".$search->toString(); return $search; diff --git a/core/lib/Thelia/Core/Template/Loop/Feature.php b/core/lib/Thelia/Core/Template/Loop/Feature.php index 6f7f12c71..74d165562 100755 --- a/core/lib/Thelia/Core/Template/Loop/Feature.php +++ b/core/lib/Thelia/Core/Template/Loop/Feature.php @@ -110,6 +110,7 @@ class Feature extends BaseI18nLoop implements PropelSearchLoopInterface $this->useFeaturePosition = true; if (null !== $product) { + // Find all template assigned to the products. $products = ProductQuery::create()->findById($product); @@ -125,6 +126,12 @@ class Feature extends BaseI18nLoop implements PropelSearchLoopInterface if (! is_null($tpl_id)) $template[] = $tpl_id; } } + + // franck@cqfdev.fr - 05/12/2013 : if the given product has no template + // or if the product cannot be found, do not return anything. + if (empty($template)) { + return null; + } } if (! empty($template)) { diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index f2e838be2..3855c46c1 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -202,7 +202,7 @@ class Product extends BaseProduct ->save($con) ; - // Create an empty product price in the default currency + // Create an empty product price in the provided currency $product_price = new ProductPrice(); $product_price