clubreseau Posted November 10, 2023 Share Posted November 10, 2023 ce code sélectionnent uniquement le dernier produit même si le client commande 2 produits public function hookDisplayAdminOrder($params){ $id_order = (int)Tools::getValue('id_order'); $sql1 = 'SELECT product_id from order_detail where id_order = '.(int)$id_order; $data1 = Db::getInstance()->getRow($sql1); $prodid = $data1['product_id']; $sql2 = 'SELECT url from scrape_ali_info where id_product='.$prodid; $data2 = Db::getInstance()->getRow($sql2); $this->context->smarty->assign(array( 'id_product' => $id_product, 'ali_url' => $data2['url'], 'id_order' => $id_order )); return $this->display(__FILE__, 'views/templates/admin/vieworder.tpl'); } Je ne vois que le dernier produit. Je souhaite voir tous les produits que le client achète. J'ai juste besoin de modifier ce code Link to comment Share on other sites More sharing options...
ps8modules Posted November 11, 2023 Share Posted November 11, 2023 (edited) Bonjour. hook: public function hookDisplayAdminOrder($params) { $id_order = (int)Tools::getValue('id_order'); $sql1 = 'SELECT product_id FROM order_detail WHERE id_order = '.(int)$id_order; /* change to executeS $data1 = Db::getInstance()->getRow($sql1); */ $data1 = Db::getInstance()->executeS($sql1); /* add product and ali url array */ $productArray = array(); /* add to array */ foreach ($data1 as $d1) { $sql2 = 'SELECT url FROM scrape_ali_info WHERE id_product = '.(int)$d1['product_id']; /* change to getValue $data2 = Db::getInstance()->getRow($sql2); */ $data2 = isset(Db::getInstance()->getValue($sql2)) ? $data2 : ''; $productArray[] = array('product_id' => $d1['product_id'], 'ali_url' => $data2); } /* remove $prodid = $data1['product_id']; */ /* change all $this->context->smarty->assign(array( 'id_product' => $id_product, 'ali_url' => $data2['url'], 'id_order' => $id_order ));*/ $this->context->smarty->assign(array( 'products' => $productArray, 'id_order' => $id_order )) return $this->display(__FILE__, 'views/templates/admin/vieworder.tpl'); } TPL: {block name="ali_url"} {if isset($products) && $products && isset($id_order) && $id_order} order id: {$id_order} {foreach from=$products item=product} product id: {$product.product_id} ali url: {$product.ali_url} {/foreach} {/if} {/block} Edited November 11, 2023 by ps8moduly.cz (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