diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 4ad7b526b..e760f8dde 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -56,6 +56,19 @@ abstract class BaseLoop ); } + public function __call($name, $arguments) { + if (substr($name, 0, 3) == 'get') { + + $argName = strtolower(substr($name, 3)); + + return $this->getArg($argName)->getValue(); + } + + throw new \InvalidArgumentException(sprintf("Unsupported magic method %s. only getArgname() is supported.", $name)); + + } + + /** * Create a new Loop * diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index c3000baad..96809f5dc 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -100,21 +100,20 @@ class Category extends BaseLoop { $search = CategoryQuery::create(); - $id = $this->getArgValue('id'); + $id = $this->getId(); if (!is_null($id)) { $search->filterById($id, Criteria::IN); } - - $parent = $this->getArgValue('parent'); + $parent = $this->getParent(); if (!is_null($parent)) { $search->filterByParent($parent); } - $current = $this->getArgValue('current'); + $current = $this->getCurrent(); if ($current === true) { $search->filterById($this->request->get("category_id")); @@ -123,22 +122,22 @@ class Category extends BaseLoop } - $exclude = $this->getArgValue('exclude'); + $exclude = $this->getExclude(); if (!is_null($exclude)) { $search->filterById($exclude, Criteria::NOT_IN); } - $link = $this->getArgValue('link'); + $link = $this->getLink(); if (!is_null($link)) { $search->filterByLink($link); } - $search->filterByVisible($this->getArgValue('visible') ? 1 : 0); + $search->filterByVisible($this->getVisible() ? 1 : 0); - $orders = $this->getArgValue('order'); + $orders = $this->getOrder(); if(null === $orders) { $search->orderByPosition(); @@ -161,8 +160,9 @@ class Category extends BaseLoop } } + $random = $this->getRandom(); - if ($this->getArgValue('random') === true) { + if ($random === true) { $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); } diff --git a/core/lib/Thelia/Core/Template/Loop/Feed.php b/core/lib/Thelia/Core/Template/Loop/Feed.php index 8d6626013..f76c0c049 100644 --- a/core/lib/Thelia/Core/Template/Loop/Feed.php +++ b/core/lib/Thelia/Core/Template/Loop/Feed.php @@ -44,17 +44,8 @@ class Feed extends BaseLoop public function getArgDefinitions() { return new ArgumentCollection( - new Argument( - 'url', - new TypeCollection(new Type\AnyType()) - ), - new Argument( - 'timeout', - new TypeCollection( - new Type\IntType() - ), - 10 - ) + Argument::createAnyTypeArgument('url', null, true), + Argument::createIntTypeArgument('timeout', 10) ); } @@ -73,17 +64,17 @@ class Feed extends BaseLoop } } - $feed = new \SimplePie($this->getArgValue('url'), THELIA_ROOT . 'cache/feeds'); + $feed = new \SimplePie($this->getUrl(), THELIA_ROOT . 'cache/feeds'); $feed->init(); $feed->handle_content_type(); - $feed->set_timeout($this->getArgValue('timeout')); + $feed->set_timeout($this->getTimeout()); $items = $feed->get_items(); - $limit = min(count($items), $this->getArgValue('limit')); + $limit = min(count($items), $this->getLimit()); $loopResult = new LoopResult(); diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 16f6864d5..001c5c750 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -24,8 +24,6 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; - -use Symfony\Component\Config\Definition\Exception\Exception; use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; @@ -100,24 +98,24 @@ class Product extends BaseLoop $search->withColumn('CASE WHEN ' . ProductTableMap::PROMO . '=1 THEN ' . ProductTableMap::PRICE2 . ' ELSE ' . ProductTableMap::PRICE . ' END', 'real_price'); - $id = $this->getArgValue('id'); + $id = $this->getId(); if (!is_null($id)) { $search->filterById($id, Criteria::IN); } - $ref = $this->getArgValue('ref'); + $ref = $this->getRef(); if (!is_null($ref)) { $search->filterByRef($ref, Criteria::IN); } - $category = $this->getArgValue('category'); + $category = $this->getCategory(); if (!is_null($category)) { $categories = CategoryQuery::create()->filterById($category, Criteria::IN)->find(); - $depth = $this->getArgValue('depth'); + $depth = $this->getDepth(); if(null !== $depth) { foreach(CategoryQuery::findAllChild($category, $depth) as $subCategory) { @@ -131,7 +129,7 @@ class Product extends BaseLoop ); } - $new = $this->getArgValue('new'); + $new = $this->getNew(); if ($new === true) { $search->filterByNewness(1, Criteria::EQUAL); @@ -139,7 +137,7 @@ class Product extends BaseLoop $search->filterByNewness(0, Criteria::EQUAL); } - $promo = $this->getArgValue('promo'); + $promo = $this->getPromo(); if ($promo === true) { $search->filterByPromo(1, Criteria::EQUAL); @@ -147,13 +145,13 @@ class Product extends BaseLoop $search->filterByNewness(0, Criteria::EQUAL); } - $min_stock = $this->getArgValue('min_stock'); + $min_stock = $this->getMin_stock(); if (null != $min_stock) { $search->filterByQuantity($min_stock, Criteria::GREATER_EQUAL); } - $min_price = $this->getArgValue('min_price'); + $min_price = $this->getMin_price(); if(null !== $min_price) { /** @@ -170,7 +168,7 @@ class Product extends BaseLoop ->where(array('not_in_promo_min_price', 'in_promo_min_price'), Criteria::LOGICAL_OR); } - $max_price = $this->getArgValue('max_price'); + $max_price = $this->getMax_price(); if(null !== $max_price) { /** @@ -187,19 +185,19 @@ class Product extends BaseLoop ->where(array('not_in_promo_max_price', 'in_promo_max_price'), Criteria::LOGICAL_OR); } - $min_weight = $this->getArgValue('min_weight'); + $min_weight = $this->getMin_weight(); if(null !== $min_weight) { $search->filterByWeight($min_weight, Criteria::GREATER_EQUAL); } - $max_weight = $this->getArgValue('max_weight'); + $max_weight = $this->getMax_weight(); if(null !== $max_weight) { $search->filterByWeight($max_weight, Criteria::LESS_EQUAL); } - $current = $this->getArgValue('current'); + $current = $this->getCurrent(); if ($current === true) { $search->filterById($this->request->get("product_id")); @@ -207,7 +205,7 @@ class Product extends BaseLoop $search->filterById($this->request->get("product_id"), Criteria::NOT_IN); } - $current_category = $this->getArgValue('current_category'); + $current_category = $this->getCurrent_category(); if ($current_category === true) { $search->filterByCategory( @@ -233,9 +231,9 @@ class Product extends BaseLoop ); } - $search->filterByVisible($this->getArgValue('visible')); + $search->filterByVisible($this->getVisible()); - $orders = $this->getArgValue('order'); + $orders = $this->getOrder(); if(null === $orders) { $search->orderByPosition(); @@ -284,14 +282,14 @@ class Product extends BaseLoop } } - $random = $this->getArgValue('random'); + $random = $this->getRandom(); if ($random === true) { $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); } - $exclude = $this->getArgValue('exclude'); + $exclude = $this->getExclude(); if (!is_null($exclude)) { $search->filterById($exclude, Criteria::NOT_IN);