tovirio Posted November 10, 2015 Share Posted November 10, 2015 Is possible to get product by shop_id? Link to comment Share on other sites More sharing options...
Rolige Posted November 10, 2015 Share Posted November 10, 2015 Could you give more details about what you want to achieve? Link to comment Share on other sites More sharing options...
tovirio Posted November 11, 2015 Author Share Posted November 11, 2015 Yes, i want to use the function get the product , in my rss.php file Product::getProducts() The problem is that this function doesn't take in input the parameter id_shop. I have the option multistore on, so i have two shop with different ID. Is possible to use this function or another one to get the product of a determinate shop? Link to comment Share on other sites More sharing options...
Rolige Posted November 12, 2015 Share Posted November 12, 2015 That method currently get all the products filtered by id_shop, don't need nothing more to do. Link to comment Share on other sites More sharing options...
tovirio Posted November 13, 2015 Author Share Posted November 13, 2015 Maybe I explained myself wrong. I have two shop, and with my rss file inside my module i want a function that returns all the products of one shop. For example i have to path:http://localhost/prestashop/ for shop onehttp://localhost/prestashop2/ for shop two I want that the rss file called in the path:http://localhost/prestashop/modules/mymodule/rss.php (the path of first shop) return me the products of the second shop and not of the first shop.I think that i have to force the variable $context to get the product of the second shop in the path of the first. Can you explain me a way to do it?Thanks Link to comment Share on other sites More sharing options...
bellini13 Posted November 13, 2015 Share Posted November 13, 2015 I assume these shops are not part of a multi-store configuration, and therefore these shops do not share a database and they do not know anything about each other. If that is the case, then you need to write code so that rss feed would connect to the other stores database and obtain the products and combine them with products from its own store Link to comment Share on other sites More sharing options...
tovirio Posted November 13, 2015 Author Share Posted November 13, 2015 The Database is the same, and the shops are part of a multi-store configuration. Link to comment Share on other sites More sharing options...
bellini13 Posted November 13, 2015 Share Posted November 13, 2015 The the easiest way is to just execute a SQL command directly to get all the products select * from ps_products Link to comment Share on other sites More sharing options...
Rolige Posted November 13, 2015 Share Posted November 13, 2015 Maybe I explained myself wrong. I have two shop, and with my rss file inside my module i want a function that returns all the products of one shop. For example i have to path: http://localhost/prestashop/ for shop one http://localhost/prestashop2/ for shop two I want that the rss file called in the path: http://localhost/prestashop/modules/mymodule/rss.php (the path of first shop) return me the products of the second shop and not of the first shop. I think that i have to force the variable $context to get the product of the second shop in the path of the first. Can you explain me a way to do it? Thanks Yes I know what you want to achieve, and these method get all the products including the filter by id_shop, or do you want have the possibility to manage the id_shop? For example, now works this way... shop.com/one => Product::getProducts() => get all the products from the shop one shop.com/two => Product::getProducts() => get all the products from the shop two Do you want to achieve something as this example? shop.com/one => Product::getProducts($id_shop = 2) => get all the products from the shop two Link to comment Share on other sites More sharing options...
tovirio Posted November 13, 2015 Author Share Posted November 13, 2015 Yes , i want this : shop.com/one => Product::getProducts($id_shop = 2) => get all the products from the shop two Link to comment Share on other sites More sharing options...
Rolige Posted November 13, 2015 Share Posted November 13, 2015 Ok, you could add a new method in the class, something like this.... /** * Get all available products by id shop * * @param integer $id_shop Shop id * @param integer $id_lang Language id * @param integer $start Start number * @param integer $limit Number of products to return * @param string $order_by Field for ordering * @param string $order_way Way for ordering (ASC or DESC) * @return array Products details */ public static function getProductsByIdShop($id_shop, $id_lang, $start, $limit, $order_by, $order_way, $id_category = false, $only_active = false, Context $context = null) { if (!$context) $context = Context::getContext(); $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd') $order_by_prefix = 'p'; else if ($order_by == 'name') $order_by_prefix = 'pl'; else if ($order_by == 'position') $order_by_prefix = 'c'; if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by_prefix = $order_by[0]; $order_by = $order_by[1]; } $sql = 'SELECT p.*, product_shop.*, pl.* , m.`name` AS manufacturer_name, s.`name` AS supplier_name FROM `'._DB_PREFIX_.'product` p INNER JOIN `'._DB_PREFIX_.'product_shop` product_shop ON (product_shop.`id_product` = p.`id_product` AND product_shop.`id_shop` = '.(int)$id_shop.') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_shop` = '.(int)$id_shop.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'. ($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').' WHERE pl.`id_lang` = '.(int)$id_lang. ($id_category ? ' AND c.`id_category` = '.(int)$id_category : ''). ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($only_active ? ' AND product_shop.`active` = 1' : '').' ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way). ($limit > 0 ? ' LIMIT '.(int)$start.','.(int)$limit : ''); $rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if ($order_by == 'price') Tools::orderbyPrice($rq, $order_way); foreach ($rq as &$row) $row = Product::getTaxesInformations($row); return ($rq); } Call the method with: Product::getProductsByIdShop() Obviously now you must add the ID shop in the first parameter. 3 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