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;
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
*/
......@@ -65,8 +62,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements
*/
public function getWidgetTitle()
{
$widgetTitle = $this->getData('widget_title');
return $widgetTitle;
return $this->getData('widget_title');
}
/**
......@@ -74,8 +70,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements
*/
public function getWidgetContent()
{
$widgetContent = $this->getData('widget_content');
return $widgetContent;
return $this->getData('widget_content');
}
/**
......@@ -97,8 +92,8 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements
/**
* 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 @@
<label translate="true">category_selection</label>
<description translate="true">category_selection_description</description>
</parameter>
<parameter name="model" xsi:type="select" visible="true">
<parameter name="template" xsi:type="select" required="true" visible="true">
<label translate="true">template</label>
<options>
<option name="default" value="widget/category_widget.phtml" selected="true">
......
......@@ -4,60 +4,34 @@
?>
<div class="widget block block-static-block category-widget">
<div class="block-content">
<?php if($this->getModel() == "widget/category_widget.phtml") { ?>
<?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 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($categories != null): ?>
<div class="categories">
<?php
foreach($categories as $category):
$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 if($this->getWidgetContent() != null): ?>
<p class="content">
<?php echo $this->getWidgetContent(); ?>
</p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if($categories != null): ?>
<div class="categories">
<?php
/*
* TODO : Pouvoir sélectionner un template de rendu sans intervenir dans le code
*/
?>
<?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());
foreach($categories as $category):
$cat = $this->getCategoryModel($category->getId());
if($cat->getImageUrl() != null): ?>
<a class="category img-background" href="<?php echo $cat->getUrl(); ?>" style="background-image: url(<?php echo $cat->getImageUrl(); ?>)">
<span><?php echo $cat->getName(); ?></span>
</a>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php } else { ?>
<p class="message global demo">
<?php echo __('no_model'); ?>
</p>
<?php } ?>
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; ?>
</div>
</div>
......@@ -4,6 +4,20 @@
?>
<div class="widget block block-static-block category-widget">
<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): ?>
<div class="categories">
<?php
......@@ -12,7 +26,7 @@
$image = $cat->getImageUrl();
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>
</a>
<?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