Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 547127f1 authored by Nicolas's avatar Nicolas
Browse files

Corrections : Possibilité de choisir entre 2 templates sans intervenir dans le code

parent a329f4f9
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,6 @@ namespace NicolasBejean\CategoryWidget\Block\Widget; ...@@ -3,9 +3,6 @@ namespace NicolasBejean\CategoryWidget\Block\Widget;
class CategoryWidget extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface class CategoryWidget extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
{ {
protected $_template = "widget/category_widget.phtml";
/*protected $_template;*/
/** /**
* Default value for products count that will be shown * Default value for products count that will be shown
*/ */
...@@ -65,8 +62,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements ...@@ -65,8 +62,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements
*/ */
public function getWidgetTitle() public function getWidgetTitle()
{ {
$widgetTitle = $this->getData('widget_title'); return $this->getData('widget_title');
return $widgetTitle;
} }
/** /**
...@@ -74,8 +70,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements ...@@ -74,8 +70,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements
*/ */
public function getWidgetContent() public function getWidgetContent()
{ {
$widgetContent = $this->getData('widget_content'); return $this->getData('widget_content');
return $widgetContent;
} }
/** /**
...@@ -97,8 +92,8 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements ...@@ -97,8 +92,8 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements
/** /**
* Récupère le template du widget * Récupère le template du widget
*/ */
public function getModel() public function getTemplate()
{ {
return $this->getData('model'); return $this->getData('template');
} }
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<label translate="true">category_selection</label> <label translate="true">category_selection</label>
<description translate="true">category_selection_description</description> <description translate="true">category_selection_description</description>
</parameter> </parameter>
<parameter name="model" xsi:type="select" visible="true"> <parameter name="template" xsi:type="select" required="true" visible="true">
<label translate="true">template</label> <label translate="true">template</label>
<options> <options>
<option name="default" value="widget/category_widget.phtml" selected="true"> <option name="default" value="widget/category_widget.phtml" selected="true">
......
...@@ -4,60 +4,34 @@ ...@@ -4,60 +4,34 @@
?> ?>
<div class="widget block block-static-block category-widget"> <div class="widget block block-static-block category-widget">
<div class="block-content"> <div class="block-content">
<?php if($this->getModel() == "widget/category_widget.phtml") { ?> <?php if($this->getWidgetTitle() != null || $this->getWidgetContent() != null): ?>
<?php if($this->getWidgetTitle() != null || $this->getWidgetContent() != null): ?> <div class="content-heading">
<div class="content-heading"> <?php if($this->getWidgetTitle() != null): ?>
<?php if($this->getWidgetTitle() != null): ?> <h2 class="title">
<h2 class="title"> <?php echo $this->getWidgetTitle(); ?>
<?php echo $this->getWidgetTitle(); ?> </h2>
</h2>
<?php endif; ?>
<?php if($this->getWidgetContent() != null): ?>
<p class="content">
<?php echo $this->getWidgetContent(); ?>
</p>
<?php endif; ?>
</div>
<?php endif; ?> <?php endif; ?>
<?php if($categories != null): ?> <?php if($this->getWidgetContent() != null): ?>
<div class="categories"> <p class="content">
<?php <?php echo $this->getWidgetContent(); ?>
foreach($categories as $category): </p>
$cat = $this->getCategoryModel($category->getId());
if($cat->getImageUrl() != null): ?>
<a class="category" href="<?php echo $cat->getUrl(); ?>">
<img src="<?php echo $cat->getImageUrl(); ?>" class="img-responsive category_image" alt="<?php echo $cat->getName(); ?>" />
<span><?php echo $cat->getName(); ?></span>
</a>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?> <?php endif; ?>
</div>
<?php endif; ?>
<?php if($categories != null): ?>
<div class="categories">
<?php <?php
/* foreach($categories as $category):
* TODO : Pouvoir sélectionner un template de rendu sans intervenir dans le code $cat = $this->getCategoryModel($category->getId());
*/
?>
<?php } elseif ($this->getModel("widget/category_widget_img_background.phtml")) { ?>
<?php if($categories != null): ?>
<div class="categories">
<?php
foreach($categories as $category):
$cat = $this->getCategoryModel($category->getId());
if($cat->getImageUrl() != null): ?> if($cat->getImageUrl() != null): ?>
<a class="category img-background" href="<?php echo $cat->getUrl(); ?>" style="background-image: url(<?php echo $cat->getImageUrl(); ?>)"> <a class="category" href="<?php echo $cat->getUrl(); ?>">
<span><?php echo $cat->getName(); ?></span> <img src="<?php echo $cat->getImageUrl(); ?>" class="img-responsive category_image" alt="<?php echo $cat->getName(); ?>" />
</a> <span><?php echo $cat->getName(); ?></span>
<?php endif; ?> </a>
<?php endforeach; ?> <?php endif; ?>
</div> <?php endforeach; ?>
<?php endif; ?> </div>
<?php } else { ?> <?php endif; ?>
<p class="message global demo">
<?php echo __('no_model'); ?>
</p>
<?php } ?>
</div> </div>
</div> </div>
...@@ -4,6 +4,20 @@ ...@@ -4,6 +4,20 @@
?> ?>
<div class="widget block block-static-block category-widget"> <div class="widget block block-static-block category-widget">
<div class="block-content"> <div class="block-content">
<?php if($this->getWidgetTitle() != null || $this->getWidgetContent() != null): ?>
<div class="content-heading">
<?php if($this->getWidgetTitle() != null): ?>
<h2 class="title">
<?php echo $this->getWidgetTitle(); ?>
</h2>
<?php endif; ?>
<?php if($this->getWidgetContent() != null): ?>
<p class="content">
<?php echo $this->getWidgetContent(); ?>
</p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if($categories != null): ?> <?php if($categories != null): ?>
<div class="categories"> <div class="categories">
<?php <?php
...@@ -12,7 +26,7 @@ ...@@ -12,7 +26,7 @@
$image = $cat->getImageUrl(); $image = $cat->getImageUrl();
if($image != null): ?> if($image != null): ?>
<a class="category" href="<?php echo $cat->getUrl(); ?>" style="background-image: url(\"<?php echo $image; ?>\")"> <a class="category" href="<?php echo $cat->getUrl(); ?>" style="background-image: url('<?php echo $image; ?>')">
<span><?php echo $cat->getName(); ?></span> <span><?php echo $cat->getName(); ?></span>
</a> </a>
<?php endif; ?> <?php endif; ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment