Jump to content

getWidgetVariables return 1 - image slider module


Recommended Posts

Hi

I have a small problem with the Image_slider module. I wanted to rework it a bit to display some recently purchased items in the store. However, there is a problem. adding a new value to 'getWidgetVariables' returns 1

test.png.ae868e2834b7b85b2c82fabc986079b6.png

 

pre.png.e09127cb30247f416f8864ff9a5cb7dd.png

public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        $testData = [
            ['name' => 'P 1', 'description' => 'desc 1', 'image' => 'url1.jpg', 'link' => 'link1'],
            ['name' => 'P 2', 'description' => 'desc 2', 'image' => 'url2.jpg', 'link' => 'link2'],
        ];
        return [
            'lastPurchasedProducts' => $testData,
            'test' => 'Test'
        ];
//        $slides = $this->getSlides(true);
//        if (is_array($slides)) {
//            foreach ($slides as &$slide) {
//                $slide['sizes'] = @getimagesize((__DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $slide['image']));
//                if (isset($slide['sizes'][3]) && $slide['sizes'][3]) {
//                    $slide['size'] = $slide['sizes'][3];
//                }
//            }
//        }
//
//        $config = $this->getConfigFieldsValues();
//        return [
//            'homeslider' => [
//                'speed' => $config['HOMESLIDER_SPEED'],
//                'pause' => $config['HOMESLIDER_PAUSE_ON_HOVER'] ? 'hover' : '',
//                'wrap' => $config['HOMESLIDER_WRAP'] ? 'true' : 'false',
//                'slides' => $slides,
//            ],
//        ];

    }

ps_imageslider.php

<h1>test</h1>
<div class="last-purchased-products">
  <h1>{$test}</h1>
  <pre>{$lastPurchasedProducts|@print_r}</pre>
  <ul>
    {foreach from=$lastPurchasedProducts item=product}
      <li>
        {$product.name}
{*        <a href="{$product.product_link}">*}
{*          <img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" alt="{$product.product_title}">*}
{*          <strong>{$product.product_title}</strong>*}
{*        </a>*}
{*        <p>{$product.product_description|truncate:100}</p>*}
{*        Ilość: {$product.product_quantity} <br>*}
{*        Zakupiono: {$product.date_add|date_format:"%Y-%m-%d %H:%M"}*}
      </li>
    {/foreach}
  </ul>
</div>

ps_imageslider.php

public function renderWidget($hookName = null, array $configuration = [])
    {
        if (!$this->isCached($this->templateFile, $this->getCacheId())) {
            $this->smarty->assign($this->getWidgetVariables($hookName, $configuration));
        }

        return $this->fetch($this->templateFile, $this->getCacheId());

    }

I tried to combine this also in array_merge(...) and in it add these new variables, but still nothing

Have any of you encountered this problem?

Link to comment
Share on other sites

Hi.

public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        $slides = $this->getSlides(true);
        if (is_array($slides)) {
            foreach ($slides as &$slide) {
                $slide['sizes'] = @getimagesize((__DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $slide['image']));
                if (isset($slide['sizes'][3]) && $slide['sizes'][3]) {
                    $slide['size'] = $slide['sizes'][3];
                }
            }
        }

        $config = $this->getConfigFieldsValues();

        $testData = [
            ['title' => 'P 1', 'description' => 'desc 1', 'image_url' => 'url1.jpg', 'url' => 'link1', 'legend' => ''],
            ['title' => 'P 2', 'description' => 'desc 2', 'image_url' => 'url2.jpg', 'url' => 'link2', 'legend' => ''],
        ];

        return [
            'homeslider' => [
                'speed' => $config['HOMESLIDER_SPEED'],
                'pause' => $config['HOMESLIDER_PAUSE_ON_HOVER'] ? 'hover' : '',
                'wrap' => $config['HOMESLIDER_WRAP'] ? 'true' : 'false',
                'slides' => $testData /*$slides*/,
            ],
        ];

    }

 

OR

public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        $slides = $this->getSlides(true);
        if (is_array($slides)) {
            foreach ($slides as &$slide) {
                $slide['sizes'] = @getimagesize((__DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $slide['image']));
                if (isset($slide['sizes'][3]) && $slide['sizes'][3]) {
                    $slide['size'] = $slide['sizes'][3];
                }
            }
        }

        $config = $this->getConfigFieldsValues();


        $slides[] = 
            [
                'id_slide' => '1', 
                'position' => '1',
                'active' => '1',
                'title' => 'P 1', 
                'url' => 'link1',
                'legend' => 'p-1',
                'description' => 'desc 1', 
                'image' => 'url1.jpg',
                'image_url' => 'url1.jpg',
                'sizes' => @getimagesize('url1.jpg') ,
                'size' => 'width="1110" height="340"',
            ];
        $slides[] = [
                'id_slide' => '2', 
                'position' => '2',
                'active' => '1',
                'title' => 'P 2', 
                'url' => 'link2',
                'legend' => 'p-2',
                'description' => 'desc 2', 
                'image' => 'url2.jpg',
                'image_url' => 'url2.jpg', 
                'sizes' => @getimagesize('url2.jpg'),
                'size' => 'width="1110" height="340"'
        ];

        return [
            'homeslider' => [
                'speed' => $config['HOMESLIDER_SPEED'],
                'pause' => $config['HOMESLIDER_PAUSE_ON_HOVER'] ? 'hover' : '',
                'wrap' => $config['HOMESLIDER_WRAP'] ? 'true' : 'false',
                'slides' => $slides,
            ],
        ];

    }

and not change slider.tpl !!!

Edited by ps8modules.com (see edit history)
Link to comment
Share on other sites

Hi. Unfortunately it doesn't change anything. The point is that instead of the standard slider, I would like to convert this to show recently purchased products in the store

sql.thumb.png.6b42ceba7ab0a748dce3d5f7aae29a43.png

But after dropping the results into the template

public function renderWidget($hookName = null, array $configuration = [])
    {
//        if (!$this->isCached($this->templateFile, $this->getCacheId())) {
//            $this->smarty->assign($this->getWidgetVariables($hookName, $configuration));

        $products = $this->getLastPurchasedProducts();
            $this->smarty->assign(['p' => $products]);
//        }

        return $this->fetch($this->templateFile, $this->getCacheId());

    }

and print it into slider.tpl:

<pre>{print_r($p)}</pre>

I see only 1 😕

Link to comment
Share on other sites

Zip your module and upload it here.
We can't see what you changed where!
You are standing against a wall and you want to pass 😄
I gave you a code that works.
If you don't want to load the images stored in the module, just comment out a few lines and no TPL needs to be changed!

image.thumb.png.7169def8a25e821e1e081ae1d19ffe2c.png

Edited by ps8modules.com (see edit history)
Link to comment
Share on other sites

I want to rework this module so that when I enable the option in the Module Configuration “LATEST_PURCHASES” it shows the five most recently purchased items.
To the module itself, I added in the `public function renderForm()` this switch responsible for this, however, it too does not appear in the admin panel

 

There is also a function `public function getLastPurchasedProducts($limit = 5, $id_lang = null)` that is responsible for this.

ps_imageslider.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...