phingko Posted December 14, 2015 Share Posted December 14, 2015 (edited) HI, I tried the module from this post ; https://www.prestashop.com/forums/topic/228277-get-customer-group-id-in-smarty/ So I want to show wholesale price when customer log in as wholesale customer which ID is 4, it works fine but the problem is when the customer is not logged in. It appears error that variable $customerdefaultgroup is undefined. in my customer group module, i have this hook header function; public function hookHeader() { global $smarty; $context = Context::getContext(); $id_lang = $context->cart->id_lang; $customer = $context->customer; $id_customer = $customer->id; $groups = Db::getInstance()->executeS("SELECT " ._DB_PREFIX_. "customer_group.id_group , " ._DB_PREFIX_. "group_lang.name FROM " ._DB_PREFIX_. "customer_group LEFT JOIN " ._DB_PREFIX_. "group_lang ON " ._DB_PREFIX_. "group_lang.id_group = " ._DB_PREFIX_. "customer_group.id_group WHERE " ._DB_PREFIX_. "customer_group.id_customer = '$id_customer' AND " ._DB_PREFIX_. "group_lang.id_lang = '$id_lang'"); if(!isset($groups[0])) $groups = FALSE; $smarty->assign('customerGroups', $groups); $defaultGroupId = Configuration::get('PS_CUSTOMER_GROUP'); $customerDefaultGroup = new Group($defaultGroupId); $smarty->assign('customerDefaultGroup' , $customerDefaultGroup); } Then on my product-list.tpl when customer log in as wholesale customer, which is customer group id = 4, it will show the WP price. <a class="lnk_more" href="{$product.link}" title="{l s='View' mod='homefeatured'}">{l s='View' mod='homefeatured'}</a> {if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE AND isset($cart->id_customer)} <p class="price_container"> {if $customerDefaultGroup>=4}<span class="rrp_price">RRP{convertPrice price=$product.orderprice}</span>{/if} <span class="price" style="float:right;">{if $customerDefaultGroup>=4}WP{else}RRP{/if}{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span> </p> {/if} The funny thing is the code works ok when customer log in, but if a customer doesn't log in and add items to cart, it will appear the error Notice: Undefined index: customerDefaultGroup in /var/www/....../cache/smarty/compile/66/de/fc/66defc1f2bf06d532797e725e346402f7c199a68.file.product-list.tpl.php on line 84 Can anyone help me what's wrong here? I have tried a lot of solution but can't figured out why the error could come out when it's declared. Help! Edited December 14, 2015 by phingko (see edit history) 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