1

I found code hot sellers widget in cms block,

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" products_per_page="5" products_count="5" template="product/widget/content/grid.phtml" conditions_encoded="a:2:[i:1;a:4:[s:4:type;s:50:Magento|CatalogWidget|Model|Rule|Condition|Combine;s:10:aggregator;s:3:all;s:5:value;s:1:1;s:9:new_child;s:0:``;]s:4:1--1;a:4:[s:4:type;s:50:Magento|CatalogWidget|Model|Rule|Condition|Product;s:9:attribute;s:3:sku;s:8:operator;s:2:();s:5:value;s:60:WS12, WT09, MT07, MH07, 24-MB02, 24-WB04, 241-MB08, 240-LV05;]]"}}

But i got error when replace a product have sku WS12 by WSH12.

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" products_per_page="5" products_count="5" template="product/widget/content/grid.phtml" conditions_encoded="a:2:[i:1;a:4:[s:4:type;s:50:Magento|CatalogWidget|Model|Rule|Condition|Combine;s:10:aggregator;s:3:all;s:5:value;s:1:1;s:9:new_child;s:0:``;]s:4:1--1;a:4:[s:4:type;s:50:Magento|CatalogWidget|Model|Rule|Condition|Product;s:9:attribute;s:3:sku;s:8:operator;s:2:();s:5:value;s:60:WSH12, WT09, MT07, MH07, 24-MB02, 24-WB04, 241-MB08, 240-LV05;]]"}}

Error filtering template: Notice: unserialize(): Error at offset magento widget

I don't know how to add or replace products in widget right way.

Update

After struggle with this issue i resolved it by my self. I wrote script create conditions_encode by using class Magento\Widget\Helper\Conditions; It has encode function.

Using encode value and replace conditions_encoded products will update.

<?php

use Magento\Framework\App\Bootstrap;
use Magento\Widget\Helper\Conditions;
require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$cons= array(
    "1"=>array(
        "type"=>'Magento\CatalogWidget\Model\Rule\Condition\Combine',
        "aggregator"=>'all',
        "value"=>'1',
        "new_child"=>'',
    ),
    "1--1"=>array(
        'type'=>'Magento\CatalogWidget\Model\Rule\Condition\Product',
        'attribute'=>'sku',
        'operator'=>'()',
        'value'=>'crowe-sweater,Easy Full Dress,Herve Leger,Striped Maxi Dress,Daisy Lace Trim Blouse',
    )
);
$a=new Conditions();
$s=$a->encode($cons);
echo "<pre>";
echo($s);
echo "</pre>";exit;
0

I have check this issue. You have to added new widget for update products and remove old one, else you need to check that condition that added when widget was created and need to follow this condition. There is no any way to edit that catalog list widget which is added in static block directly.

1
  • I've just updated right way to do it. Thanks – long thanh Sep 20 '16 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.