cyanoxide Posted February 16, 2017 Share Posted February 16, 2017 I've got a custom controller set up that extends from the front controller, it's fairly basic and currently contains the following: class StockController extends FrontController{ public function init(){ parent::init(); } public function initContent(){ $this->display_column_left = false; $this->display_column_right = false; parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'stockcontroller.tpl'); } } This is all working correctly as it stands but I would like to use Product::getproducts(); so I can display a full list of products available and their stock levels. After looking at all the various posts on here regarding the topic I was assuming I could add the following into init or init content but it just gives me a fatal error message. $products = Product::getProducts($this->context->language->id, 0, 100); $products_all = Product::getProductsProperties($this->context->language->id, $products); $this->context->smarty->assign(array( 'products' => $products_all )); What am I missing? Link to comment Share on other sites More sharing options...
cyanoxide Posted February 17, 2017 Author Share Posted February 17, 2017 (edited) Checking the PHP error log gives me the following: [17-Feb-2017 11:05:58 Europe/London] PHP Warning: Missing argument 5 for ProductCore::getProducts(), called in /var/www/webroot/ROOT/controllers/front/stocklistController.php on line 22 and defined in /var/www/webroot/ROOT/classes/Product.php on line 1190 Edited February 17, 2017 by cyanoxide (see edit history) Link to comment Share on other sites More sharing options...
YopixelAE Posted February 18, 2017 Share Posted February 18, 2017 Hello, You missed the required order_way parameter. Cf. public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,$only_active = false, Context $context = null) Link to comment Share on other sites More sharing options...
cyanoxide Posted February 21, 2017 Author Share Posted February 21, 2017 Hello, You missed the required order_way parameter. Cf. public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,$only_active = false, Context $context = null) Thank you for this observation, I've added in parameters for both $order_by and $order_way and I'm no longer seeing the "fatal error" message I was receiving but I'm still not seeing the product array on my display page. Using {$products|@print_r} in the .tpl file all I'm seeing is "Array ( ) 1" so I'm assuming something is still missing. Link to comment Share on other sites More sharing options...
YopixelAE Posted February 21, 2017 Share Posted February 21, 2017 And what about var_dump($products_all) before assiging to smarty ? Link to comment Share on other sites More sharing options...
cyanoxide Posted February 21, 2017 Author Share Posted February 21, 2017 And what about var_dump($products_all) before assiging to smarty ? That puts "array(0) { }" at the top of my page. Link to comment Share on other sites More sharing options...
cyanoxide Posted March 1, 2017 Author Share Posted March 1, 2017 Anyone have an suggestions regarding this? Link to comment Share on other sites More sharing options...
YopixelAE Posted March 1, 2017 Share Posted March 1, 2017 Maybe that your id_lang (required parameter for getProducts function) is not defined.$id_lang = $this->context->language->id;$products = Product::getProducts($id_lang, 0, 100 ... ...);var_dump($id_lang) // Returns ?If false, before your init function, insert : public function __construct() { parent::__construct(); $this->context = Context::getContext(); } Link to comment Share on other sites More sharing options...
cyanoxide Posted March 6, 2017 Author Share Posted March 6, 2017 Okay, I've tried doing that and var_dump($id_lang) displays "null" on my page so I've added the code and the "null" changed to "int(1)" Testing the product list at this point throught the tpl still just displays "Array () 1". Here is the code I've currently got based on your suggestions. <?php class MotorsportController extends FrontController{ public function __construct(){ parent::__construct(); $this->context = Context::getContext(); } public function init(){ parent::init(); } public function initContent(){ $this->display_column_left = false; $this->display_column_right = false; parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'motorsport.tpl'); $id_lang = $this->context->language->id; $products = Product::getProducts($id_lang, 0, 1000, 'asc', 'asc'); var_dump($id_lang); $products_all = Product::getProductsProperties($id_lang, $products); $this->context->smarty->assign(array( 'products' => $products_all )); } } And I'm trying to call it on the tpl file with (I've tried it without the "@" also with no change. {$products|@print_r} Link to comment Share on other sites More sharing options...
YopixelAE Posted March 6, 2017 Share Posted March 6, 2017 (edited) Now that your var $id_lang is ok, test your var $products. Warning, one of your parameter is not correct. $order_by should be 'id_product' or 'price' or 'date_add' or 'date_upd' BUT NOT 'asc' var_dump($id_lang); // Should return 1 or 2 and so. $products = Product::getProducts($id_lang, 0, 1000, 'id_product', 'asc', false, false, false, true, null); // Required parameters $id_lang, $start (here 0), $limit (here 1000), $order_by (here 'id_product'), $order_way ('here asc') var_dump($products); // Should return an array of products Edited March 6, 2017 by Yopixel (see edit history) Link to comment Share on other sites More sharing options...
cyanoxide Posted March 7, 2017 Author Share Posted March 7, 2017 Okay thank you, progress has been made. I'm now seeing the array of of product properties. The bad news is that this array doesn't contain the attributes or the quantity values for them. I've now got access to the default attribute id and quantity and the quantity of all attributes combined but not the other two attributes. Link to comment Share on other sites More sharing options...
YopixelAE Posted March 7, 2017 Share Posted March 7, 2017 but not the other two attributes. Are they out of stock ? Link to comment Share on other sites More sharing options...
cyanoxide Posted March 7, 2017 Author Share Posted March 7, 2017 Are they out of stock ? Afraid not there should be 13 in one of the attributes and 6 in the other for the product I was looking at but it didn't display any information on either of them. Link to comment Share on other sites More sharing options...
YopixelAE Posted March 7, 2017 Share Posted March 7, 2017 (edited) Please paste here the array of products properties - coming from the var_dump($products_all); - Edited March 7, 2017 by Yopixel (see edit history) Link to comment Share on other sites More sharing options...
cyanoxide Posted March 7, 2017 Author Share Posted March 7, 2017 I stripped out the personal information and set the range to just the first product in the list. array(1) { [0]=> array(80) { ["id_product"]=> string(2) "54" ["id_supplier"]=> string(1) "2" ["id_manufacturer"]=> string(1) "0" ["id_category_default"]=> string(2) "15" ["id_shop_default"]=> string(1) "1" ["id_tax_rules_group"]=> string(2) "65" ["on_sale"]=> string(1) "0" ["online_only"]=> string(1) "0" ["ean13"]=> string(13) "5060460900017" ["upc"]=> string(0) "" ["ecotax"]=> string(8) "0.000000" ["quantity"]=> int(22) ["minimal_quantity"]=> string(1) "1" ["price"]=> float(195) ["wholesale_price"]=> string(8) "0.000000" ["unity"]=> string(0) "" ["unit_price_ratio"]=> string(8) "0.000000" ["additional_shipping_cost"]=> string(4) "0.00" ["reference"]=> string(7) "ref1" ["supplier_reference"]=> string(0) "" ["location"]=> string(0) "" ["width"]=> string(8) "0.000000" ["height"]=> string(8) "0.000000" ["depth"]=> string(8) "0.000000" ["weight"]=> string(8) "1.000000" ["out_of_stock"]=> string(1) "2" ["quantity_discount"]=> string(1) "0" ["customizable"]=> string(1) "0" ["uploadable_files"]=> string(1) "0" ["text_fields"]=> string(1) "0" ["active"]=> string(1) "1" ["redirect_type"]=> string(3) "404" ["id_product_redirected"]=> string(1) "0" ["available_for_order"]=> string(1) "1" ["available_date"]=> string(10) "0000-00-00" ["condition"]=> string(3) "new" ["show_price"]=> string(1) "1" ["indexed"]=> string(1) "1" ["visibility"]=> string(4) "both" ["cache_is_pack"]=> string(1) "0" ["cache_has_attachments"]=> string(1) "0" ["is_virtual"]=> string(1) "0" ["cache_default_attribute"]=> string(3) "280" ["date_add"]=> string(19) "2015-10-23 13:58:44" ["date_upd"]=> string(19) "2017-03-07 09:49:54" ["advanced_stock_management"]=> string(1) "0" ["pack_stock_type"]=> string(1) "3" ["id_shop"]=> string(1) "1" ["id_lang"]=> string(1) "1" ["description"]=> string(1132) "Lorem ipsem dolor set amet." ["description_short"]=> string(189) "Lorem ipsem dolor set amet." ["link_rewrite"]=> string(9) "product1" ["meta_description"]=> string(0) "" ["meta_keywords"]=> string(0) "" ["meta_title"]=> string(26) "Product Metaname" ["name"]=> string(9) "Product Name" ["available_now"]=> string(0) "" ["available_later"]=> string(27) "AVAILABILITY: ON BACK ORDER" ["manufacturer_name"]=> NULL ["supplier_name"]=> string(7) "Supplier" ["rate"]=> float(20) ["tax_name"]=> string(10) "VAT UK 20%" ["id_product_attribute"]=> string(3) "280" ["allow_oosp"]=> int(0) ["category"]=> string(12) "category" ["link"]=> string(52) "https://www.example.com/category/product.html" ["attribute_price"]=> float(0) ["price_tax_exc"]=> float(162.5) ["price_without_reduction"]=> float(195) ["reduction"]=> float(0) ["specific_prices"]=> array(19) { ["id_specific_price"]=> string(4) "3154" ["id_specific_price_rule"]=> string(1) "0" ["id_cart"]=> string(1) "0" ["id_product"]=> string(2) "54" ["id_shop"]=> string(1) "0" ["id_shop_group"]=> string(1) "0" ["id_currency"]=> string(1) "8" ["id_country"]=> string(1) "0" ["id_group"]=> string(1) "0" ["id_customer"]=> string(1) "0" ["id_product_attribute"]=> string(1) "0" ["price"]=> string(10) "162.500000" ["from_quantity"]=> string(1) "1" ["reduction"]=> string(8) "0.000000" ["reduction_tax"]=> string(1) "1" ["reduction_type"]=> string(6) "amount" ["from"]=> string(19) "0000-00-00 00:00:00" ["to"]=> string(19) "0000-00-00 00:00:00" ["score"]=> string(2) "40" } ["quantity_all_versions"]=> int(36) ["id_image"]=> string(10) "en-default" ["attachments"]=> array(0) { } ["virtual"]=> int(0) ["pack"]=> int(0) ["packItems"]=> array(0) { } ["nopackprice"]=> int(0) ["customization_required"]=> bool(false) } } Link to comment Share on other sites More sharing options...
YopixelAE Posted March 7, 2017 Share Posted March 7, 2017 Simply use: Product::getAttributeCombinationsById($id_product_attribute, $id_lang) to fletch all attributes of your product. The argument id_product_attribute is available in previous array ($products_all) Link to comment Share on other sites More sharing options...
cyanoxide Posted March 8, 2017 Author Share Posted March 8, 2017 Hey again, I've tried adding that in but it doesn't seem to be having any effect. I can grab the attribute id for each product (The original one I was testing uses an attr id of 280) using $attr_id = $product_all[0][id_product_attribute]; or the same without the "[0]" in a foreach loop which I currently have but passing those variables over to getAttributeCombinationsById just gives me blank arrays. I also tried passing "280" directly into the method but that also didn't work so I must be missing something here. This is what I've got now. $id_lang = $this->context->language->id; $products = Product::getProducts($id_lang, 0, 5, 'id_product', 'asc'); $products_all = Product::getProductsProperties($id_lang, $products); foreach ($products_all as $product_all) { $attr_id = $product_all[id_product_attribute]; $product_attr = Product::getAttributeCombinationsById($attr_id, $id_lang); var_dump($product_attr); } Thank you for all your help with this so far. It's proving to be a lot more difficult than I first expected but it is giving me some excellent insight on how prestashop works. Link to comment Share on other sites More sharing options...
sandrayin Posted August 28, 2017 Share Posted August 28, 2017 Hey again, I've tried adding that in but it doesn't seem to be having any effect. I can grab the attribute id for each product (The original one I was testing uses an attr id of 280) using $attr_id = $product_all[0][id_product_attribute]; or the same without the "[0]" in a foreach loop which I currently have but passing those variables over to getAttributeCombinationsById just gives me blank arrays. I also tried passing "280" directly into the method but that also didn't work so I must be missing something here. This is what I've got now. $id_lang = $this->context->language->id; $products = Product::getProducts($id_lang, 0, 5, 'id_product', 'asc'); $products_all = Product::getProductsProperties($id_lang, $products); foreach ($products_all as $product_all) { $attr_id = $product_all[id_product_attribute]; $product_attr = Product::getAttributeCombinationsById($attr_id, $id_lang); var_dump($product_attr); } Thank you for all your help with this so far. It's proving to be a lot more difficult than I first expected but it is giving me some excellent insight on how prestashop works. You want to achieve something like this? https://www.tinybibiya.com/stocklist Link to comment Share on other sites More sharing options...
ernestto Posted April 8, 2018 Share Posted April 8, 2018 Hola, quiero agregar contenido en pie de cada categoria y pense usar ContentBox. Cuando creo el HOOK pense usar displayProductTabContent. ¿voy bien? 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