1

I've been searching and reading about passing data between phtml files in the last couple of hours but I haven't find a solution to my problem.

I'm passing an array with a product object and a category names array, like this:

<?php echo $this->getLayout()->createBlock('catalog/product_list')->assign(array("_product"=>$_item,"_categ_names"=>$categs_names))->setTemplate('catalog/product/view/type/product_listing.phtml')->toHtml(); ?> 

from related.phtml . The data passed is displayed correctly and everything is alright, except the fact that for every product sent/displayed a warning appears in system.log:

Warning: addcslashes() expects parameter 1 to be string, object given  in ...\trunk\lib\Zend\Db\Adapter\Pdo\Abstract.php on line 296

There are no type checks in lib\Zend\Db\Adapter\Pdo\Abstract.php for arrays, only for int and float, and then the addcslashes function is called.

protected function _quote($value)
{
    if (is_int($value) || is_float($value)) {
        return $value;
    }
    // Fix for null-byte injection
    $value = addcslashes($value, "\000\032");
    $this->_connect();
    return $this->_connection->quote($value);
}

I've tried to pass data with different functions, like setData, assign or dirrectly in createBlock, but the behaviour is the same.

The weird thing is that in createBlock function can be passed arrays, as seen here:

public function createBlock($type, $name='', array $attributes = array())

and then added with:

->addData($attributes);

but the same warning appears.

Edited, with code for product_listing.phtml:

<?php  
$_helper = $this->helper('catalog/output');
?>
<a 
  href="<?php echo $_product->getProductUrl() ?>"
  title="<?php echo $this->stripTags($this->getImageLabel($_product,   'small_image'), null, true) ?>"
  class="product-image text-center">
    <img
        class="img-responsive"
        src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(280); ?>"
        width="280"
        height="280"
        alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
</a>
<h2 class="product-name">
<a 
    href="<?php echo $_product->getProductUrl() ?>"
    title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
        <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
</a>
</h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php if($_product->getPrice() == 0 && in_array("Etichete electronice",$_categ_names)):?>
<p class="special-price-text"><?php echo __("Pret personalizat");?></p>   
<?php else: ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<?php endif;?>
<?php if($_product->getPrice() > $_product->getFinalPrice()): ?>
<div class="sales_icon_wrapper">
    <span class="sales_icon"><?php echo $this->__('Promo') ?> %</span>
</div>
<?php endif; ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
    <?php if($_product->getPrice() == 0 && in_array("Etichete electronice",$_categ_names)):?>
        <a href="/contact" title="<?php echo $this->__('Solicita oferta') ?>" class="button btn-cart btn btn-primary"><?php echo $this->__('Solicita oferta') ?></a>
    <?php else: ?>
        <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Order')) ?>" class="button btn-cart btn btn-primary" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><?php echo $this->__('Order') ?></button>
    <?php endif;?>
<?php else: ?>
    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
<div class="clearfix"></div>

Has anyone encountered the same problem or is it just me? Can anyone help me solve this?

Thanks!

  • Please add your code for product_listing.phtml – Jaimin Sutariya Feb 11 '17 at 5:33
  • @JaiminSutariya , I've added the code for product_listing.phtml. – Melania Jitaru Feb 11 '17 at 13:33
  • 1
    @MelaniaJitaru did you find a fix for this? I'm experiencing the same issue – Ricky Odin Matthews May 30 '17 at 10:36
  • 2
    @RickyOdinMatthews Yes, I did. I actually found that the problem was not with how the data was passed to the other template or what functions were used. I tracked the problem to the 'Mage\Catalog\Block\Product\List.php' block, at line 74, where the categoryId was set with '$categories->getIterator()', which is in fact an object, thus, the error. I've extended the block and passed the category entity_id as categoryId. – Melania Jitaru May 31 '17 at 8:35
  • could you please share the solution, as answer, ty – Mer Gh Oct 31 '18 at 15:54

Your Answer

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

Browse other questions tagged or ask your own question.