VillanyLeo Posted June 4, 2024 Share Posted June 4, 2024 I'm working on a membership for my ecommerce site, where the premium membership subscribers have access to a variety of exclusive discounts on select products. The membership is already working, and the products are selected by setting the specific (discount) price for the membership group. The thing is, I want to show people (even those who are not members) the member discount as well, so that they will subscribe to the program. I already made this feature for the product page by overriding the ProductController the following way: <?php class ProductController extends ProductControllerCore { public function initContent() { parent::initContent(); // Ensure product object is available $product = $this->context->controller->getProduct(); $full_price = Product::getPriceStatic($product->id, false, null, 6, null, false, false); // Initialize a variable to store the specific price for group id 5 $club_price = null; if ($product) { // Get specific prices for the product $specific_prices = SpecificPrice::getByProductId($product->id); if ($specific_prices) { foreach ($specific_prices as $specific_price) { if ($specific_price['id_group'] == 5) { $club_price = round($full_price - $specific_price['reduction']); break; // Stop looping once we find the price for group 5 } } } } // Assign the specific price to the Smarty variable $this->context->smarty->assign('club_price', $club_price); } } It basically takes the reduction value of the products from specific_prices table, where id_group is 5, and subtracts this reduction from the full prices, and the value it displays will be the price I want. The problem is, I want to display this same price for the product listing page as well, and I tried a similar method for CategoryController, but I can't seem to find out why it won't work. This is how I tried to override my CategoryController: <?php class CategoryController extends CategoryControllerCore { public function initContent() { parent::initContent(); $products = $this->cat_products; // Get the products in the category foreach ($products as &$product) { $full_price = Product::getPriceStatic($product['id_product'], false, null, 6, null, false, false); $club_price = null; $specific_prices = SpecificPrice::getByProductId($product['id_product']); if ($specific_prices) { foreach ($specific_prices as $specific_price) { if ($specific_price['id_group'] == 5) { $club_price = round($full_price $specific_price['reduction']); break; } } } $product['club_price'] = $club_price; // Add club_price to the product array } $this->context->smarty->assign('products', $products); // Reassign the modified products array } } Whenever I try to display $product.club_price, it only displays 'Array' on the page. I tried to find the solution for hours, but no success yet. Link to comment Share on other sites More sharing options...
ventura Posted June 5, 2024 Share Posted June 5, 2024 I think it would be a better option to do it through a module located for example in displayProductPriceBlock. 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