ArsalanAnsari Posted February 17, 2015 Share Posted February 17, 2015 (edited) I am not getting any result if i sort that query as "ORDER BY id_category_default ASC" but without sorting its working fine. Notice: Array to string conversion in /srv/website/classes/Product.php public static function getDefaultCategory_byid($id_user) { $default_category = Db::getInstance()->executeS(' SELECT DISTINCT `id_category_default` FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'favorite_product` fp ON p.id_product = fp.id_product WHERE fp.id_customer='.(int)$id_user).' ORDER BY id_category_default ASC'; return $default_category; } my tpl codes something like that. {assign var=cat_val value=Product::getDefaultCategory_byid($cart->id_customer)} {foreach from=$cat_val item=items} <div class="page-heading"> <h1 class="page-heading product-listing"> <span class="cat-name">{FrontController::getCategoryName($items.id_category_default)|escape:'html':'UTF-8'}</span> </h1> </div> {/foreach} Please help. Thanks in advance. PS Version: 1.6.0.9 Edited February 17, 2015 by ArsalanAnsari (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted February 17, 2015 Share Posted February 17, 2015 Notice: Array to string conversion in /srv/website/classes/Product.php why not include the line number and the line of code that is receiving the notice? executeS returns an array. so your code would return an array of 'id_category_default'. somewhere in your code that array is being converted to a String. you also should not be using Product and FrontController classes directly in your smarty template, it is extremely bad coding standards. Why don't you try to explain what you are trying to accomplish, and perhaps you will get assistance Link to comment Share on other sites More sharing options...
ArsalanAnsari Posted February 17, 2015 Author Share Posted February 17, 2015 Notice: Array to string conversion in /srv/website/classes/Product.php why not include the line number and the line of code that is receiving the notice? executeS returns an array. so your code would return an array of 'id_category_default'. somewhere in your code that array is being converted to a String. you also should not be using Product and FrontController classes directly in your smarty template, it is extremely bad coding standards. Why don't you try to explain what you are trying to accomplish, and perhaps you will get assistance Thanks for the reply. What actually i need to get "Favorite products" with the category name as heading on top of the products. a complete code of favoriteproducts-account.tpl file as below. {* * 2007-2014 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} {capture name=path} <a href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}"> {l s='My account' mod='favoriteproducts'} </a> <span class="navigation-pipe">{$navigationPipe}</span> <span class="navigation_page">{l s='My favorite products' mod='favoriteproducts'}</span> {/capture} <div id="favoriteproducts_block_account"> <h1 class="page-heading product-listing">{l s='My favorite products' mod='favoriteproducts'}</h1> {if $favoriteProducts} {assign var=cat_val value=Product::getDefaultCategory_byid($cart->id_customer)} {foreach from=$cat_val item=items} <div class="page-heading ajax_heading_{$items.id_category_default} clearfix"><h1 class="page-heading product-listing"><span class="cat-name">{FrontController::getCategoryName($items.id_category_default)|escape:'html':'UTF-8'}</span></h1></div> {assign var=cat_item value=Product::getDefaultCategoryfav($cart->id_customer,$items.id_category_default)} <ul class="product_list grid row"> {foreach from=$cat_item item=products} <li class="ajax_block_product col-xs-12 col-ms-6 col-sm-3 col-md-4 col-lg-3 first-in-line last-line first-item-of-tablet-line first-item-of-mobile-line last-mobile-line"> <div class="product-container" itemscope> <div class="left-block"> <div class="product-image-container"> <a class="product_img_link" href="{$link->getProductLink($products.id_product, null, null, null, null, 1)|escape:'html':'UTF-8'}" itemprop="url"> <img class="replace-2x img-responsive img_0" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} src="{$link->getImageLink('image', Product::getimage($products.id_product), 'home_default')|escape:'html':'UTF-8'}" itemprop="image"/> </a> <div class="functional-buttons functional-buttons-grid clearfix"> {if isset($quick_view) && $quick_view} <div class="quickview col-xs-6"> <a class="quick-view" href="{$link->getProductLink($products.id_product, null, null, null, null, 1)|escape:'html':'UTF-8'}" rel="{$link->getProductLink($products.id_product, null, null, null, null, 1)|escape:'html':'UTF-8'}" title="{l s='Quick view'}"> {l s='Quick view'} </a> </div> {/if} </div> </div> </div> <p class="s_title_block"> <a href="{$link->getProductLink($products.id_product, null, null, null, null, 1)|escape:'html':'UTF-8'}"> {Product::getProductName($products.id_product)|truncate:35:'...'|escape:'html':'UTF-8'} </a> </p> <div itemprop="offers" itemscope class="content_price"> <span itemprop="price" class="price product-price"> {convertPrice price=Product::getDefaultpricefav($products.id_product)|escape:'html':'UTF-8'} </span> </div> <div class="button-container"> {if isset($static_token)} <a class="button ajax_add_to_cart_button btn" href="{$link->getPageLink('cart',false, NULL, "add=1&id_product={$products.id_product|intval}&token={$static_token}", false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product="{$products.id_product|intval}"> <span>{l s='Add to cart'}</span> </a> {else} <a class="button ajax_add_to_cart_button btn" href="{$link->getPageLink('cart',false, NULL, 'add=1&id_product={$products.id_product|intval}', false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product="{$products.id_product|intval}"> <span>{l s='Add to cart'}</span> </a> {/if} </div> <div class="remove"> <a href="#" onclick="return false" rel="ajax_id_favoriteproduct_{$products.id_product}"> <i class="icon-remove"></i> </a> </div> </div> </li> {/foreach} </ul> {/foreach} {else} <p class="alert alert-warning">{l s='No favorite products have been determined just yet. ' mod='favoriteproducts'}</p> {/if} <ul class="footer_links clearfix"> <li> <a class="btn btn-default button button-small" href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}"> <span> <i class="icon-chevron-left"></i>{l s='Back to your account' mod='favoriteproducts'} </span> </a> </li> </ul> </div> and functions i created on Product.php public static function getDefaultCategoryfav($id_user, $id_category) { $default_category = Db::getInstance()->executeS(' SELECT fp.id_product FROM '._DB_PREFIX_.'product p, '._DB_PREFIX_.'favorite_product fp WHERE fp.id_product = p.id_product AND fp.id_customer='.(int)$id_user.' AND p.id_category_default='.(int)$id_category); return $default_category; } public static function getDefaultCategory_byid($id_user) { $default_category = Db::getInstance()->executeS(' SELECT DISTINCT `id_category_default` FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'favorite_product` fp ON p.id_product = fp.id_product WHERE fp.id_customer='.(int)$id_user); return $default_category; } public static function getDefaultpricefav($id) { $default_category = Db::getInstance()->getValue(' SELECT product_shop.`price` FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' WHERE p.`id_product` = '.(int)$id); return $default_category; } public function getimage($id) { $default_category = Db::getInstance()->getValue(' SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `id_product` = '.(int)$id); return $default_category; } please share how can i use Product and FrontController classes in proper way. thanks Link to comment Share on other sites More sharing options...
bellini13 Posted February 17, 2015 Share Posted February 17, 2015 I don't intend on providing you code, but I can answer or help you locate the issue you are having. so like I stated before, you received a php notice about converting an array to a string, what line of code was that? Link to comment Share on other sites More sharing options...
ArsalanAnsari Posted February 17, 2015 Author Share Posted February 17, 2015 I don't intend on providing you code, but I can answer or help you locate the issue you are having. so like I stated before, you received a php notice about converting an array to a string, what line of code was that? Line# 5676 The code mention in Product.php " WHERE fp.id_customer='.(int)$id_user). ORDER BY id_category_default ASC'; " Link to comment Share on other sites More sharing options...
bellini13 Posted February 17, 2015 Share Posted February 17, 2015 " WHERE fp.id_customer='.(int)$id_user). ORDER BY id_category_default ASC'; " well the only variable in that statement is $id_user, and I doubt that is an array. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now