ITI Posted August 12, 2014 Share Posted August 12, 2014 (edited) Is there a way to display the price from any group?I have different groups in the back office, but at the front end I Always want to show the not logged in price.(beside the price what is in the group with discount, so the user can see the price not logged in (or other group) and his price)I found a function getSpecificPrice, can I use that in my template, and if yes how to use it?I really hope somebody have an solution, thanx in advance Edited August 12, 2014 by ITI (see edit history) Link to comment Share on other sites More sharing options...
Paul C Posted August 12, 2014 Share Posted August 12, 2014 (edited) This has been asked a few time and I can't remember if I ever provided my method (still ps 1.5.x but should be fine in 1.6.x). First you need a function to calculate the group price: /** * Get product group price * Support function for hookDisplayRightColumnProduct() * @param integer $id_product Product id * @param integer $id_group (default value: NULL) * @param boolean $usetax prices including/excluding taxes (optional) * @param integer $id_product_attribute Product attribute id (optional). * NULL does apply the default combination price impact. * @param variable_reference $specificPriceOutput. * If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object * @return float Product price */ public static function getGroupPriceStatic($id_product, $id_group = null, $usetax = true, $price_display_precision = 6, $id_product_attribute = null, &$specific_price_output = null) { $context = Context::getContext(); // Basic checks if (!Validate::isBool($usetax) || !Validate::isUnsignedId($id_product)) die(Tools::displayError()); // Initialise defaults if (!$id_group) $id_group = Configuration::get('PS_DEFAULT_CUSTOMER_GROUP'); $id_currency = (int)Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT'); $id_country = (int)Validate::isLoadedObject($context->currency) ? (int)$context->country->id : Configuration::get('PS_COUNTRY_DEFAULT'); $id_state = 0; $zipcode = 0; // Populate address parameters if ($id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) { $address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) { $id_country = (int)$address_infos['id_country']; $id_state = (int)$address_infos['id_state']; $zipcode = $address_infos['postcode']; } } else if (isset($context->customer->geoloc_id_country)) { $id_country = (int)$context->customer->geoloc_id_country; $id_state = (int)$context->customer->id_state; $zipcode = (int)$context->customer->postcode; } // Verify tax options (parameter may be overridden here) if (Tax::excludeTaxeOption()) $usetax = false; if ($usetax != false && !empty($address_infos['vat_number']) && $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') && Configuration::get('VATNUMBER_MANAGEMENT')) $usetax = false; // Calculate price return Product::priceCalculation( (int)$context->shop->id, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency, $id_group, 1, $usetax, $price_display_precision, false, true, true, $specific_price_output, true, 0, false, 0, 1 ); } I placed the above in a module. In my case I wanted to have a RRP, so stored that as an absolute group price on a per product basis. To get the value into the templates I added an override in classes/Product.php (EDIT: To be clear that's in override/classes/Product.php and requires additional code to be fully function i.e. a class declaration): public static function getTaxesInformations($row, Context $context = null) { $row = parent::getTaxesInformations($row, $context); $module = Module::getInstanceByName('yourmodulethatcontainsthefunction'); $row['rrp_price'] = $module->getGroupPriceStatic($row['id_product'], (int)MembershipCard::getRRPGroup(), true, 6, ((isset($row['id_product_attribute']) AND !empty($row['id_product_attribute'])) ? (int)($row['id_product_attribute']) : null)); return $row; } You'll see in the above the function MembershipCard::getRRPGroup() - this just returns the id of the customer group I used to store the recommended retail prices and would be replaced with the id of the customer discount group you want to show. Obviously you then need to add markup as appropriate in your templates. Should appear wherever there's a reference to a product just the same as the price does (but under a different member variable name, of course). If you have multiple groups then you could loop through all of them adding the prices to a suitable variable (or array) to let you display them all. Paul Edited August 13, 2014 by Paul C (see edit history) 1 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