diff --git a/Block/Widget/CategoryWidget.php b/Block/Widget/CategoryWidget.php index 49d7c3af4f9bfb05bc458561a3652403c16cf7ef..e7cca13716b91333633338e9e943e67a4394052c 100755 --- a/Block/Widget/CategoryWidget.php +++ b/Block/Widget/CategoryWidget.php @@ -1,7 +1,10 @@ <?php namespace NicolasBejean\CategoryWidget\Block\Widget; -class CategoryWidget extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface +use Magento\Framework\View\Element\Template; +use Magento\Widget\Block\BlockInterface; + +class CategoryWidget extends Template implements BlockInterface { /** * Category helper @@ -120,7 +123,10 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements */ public function getTemplate() { - return $this->getData('template'); + if ($this->hasData('template')) { + $this->setTemplate($this->getData('template')); + } + return $this->_template; } /** diff --git a/Model/Config/Source/CategoryList.php b/Model/Config/Source/CategoryList.php index be758b4cc4f9a87a2a655778138d1799db0ae80f..5e6a58a44e29e4932a22fce88ec9c19c8f6ebb77 100755 --- a/Model/Config/Source/CategoryList.php +++ b/Model/Config/Source/CategoryList.php @@ -18,7 +18,7 @@ class CategoryList implements ArrayInterface public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true) { - return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad); + return $this->_categoryHelper->getStoreCategories($sorted, $asCollection, $toLoad); } /* @@ -27,19 +27,15 @@ class CategoryList implements ArrayInterface */ public function toOptionArray() { - - $arr = $this->toArray(); $ret = []; - foreach ($arr as $key => $value) - { - + foreach ($arr as $key => $value) : $ret[] = [ 'value' => $key, 'label' => $value ]; - } + endforeach; return $ret; } @@ -50,19 +46,14 @@ class CategoryList implements ArrayInterface */ public function toArray() { - /* - * Le paramètre asCollection permet à true d'afficher le second niveau des catégories - */ - + /* Le paramètre asCollection permet à true d'afficher le second niveau des catégories */ $categories = $this->getStoreCategories(false,true,true); - $categoryList = array(); - foreach ($categories as $category){ - + foreach ($categories as $category) : $categoryList[$category->getEntityId()] = __($category->getName()); - } + endforeach; return $categoryList; } -} \ No newline at end of file +} diff --git a/etc/widget.xml b/etc/widget.xml index f27e6e03d1c4c61c4875bb0119fc11bacab9e9d1..1459aa5887dd61f64b209c4430c3409506aa5c3d 100755 --- a/etc/widget.xml +++ b/etc/widget.xml @@ -2,35 +2,35 @@ <widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd"> <widget id="nicolasbejean_categorywidget" class="NicolasBejean\CategoryWidget\Block\Widget\CategoryWidget"> - <label translate="true">widget_label</label> - <description translate="true">widget_description</description> + <label>widget_label</label> + <description>widget_description</description> <parameters> <parameter name="widget_title" xsi:type="text" visible="true" sort_order="1"> - <label translate="true">widget_title</label> + <label>widget_title</label> </parameter> <parameter name="widget_content" xsi:type="text" visible="true" sort_order="2"> - <label translate="true">widget_content</label> + <label>widget_content</label> </parameter> <parameter name="category_selection" xsi:type="multiselect" visible="true" sort_order="3" source_model="NicolasBejean\CategoryWidget\Model\Config\Source\CategoryList"> - <label translate="true">category_selection</label> - <description translate="true">category_selection_description</description> + <label>category_selection</label> + <description>category_selection_description</description> </parameter> <parameter name="category_image_width" xsi:type="text" visible="true" sort_order="4"> - <label translate="true">category_image_width</label> - <description translate="true">category_image_width_description</description> + <label>category_image_width</label> + <description>category_image_width_description</description> </parameter> <parameter name="category_image_height" xsi:type="text" visible="true" sort_order="5"> - <label translate="true">category_image_height</label> - <description translate="true">category_image_height_description</description> + <label>category_image_height</label> + <description>category_image_height_description</description> </parameter> <parameter name="template" xsi:type="select" required="true" visible="true" sort_order="6"> - <label translate="true">template</label> + <label>template</label> <options> <option name="img_background" value="widget/category_widget_img_background.phtml" selected="true"> - <label translate="true">default_template</label> + <label>default_template</label> </option> <option name="default" value="widget/category_widget.phtml"> - <label translate="true">other_template</label> + <label>other_template</label> </option> </options> </parameter>