Clement.drj Posted May 27 Share Posted May 27 Bonjour à tous, Je souhaite afficher la colonne des codes promos sur ma page des commandes. Par quel moyen puis-je réaliser cette modification ? Si cela s’agit d’une requête SQL, pouvez-vous me donner quelques conseils ? Ci-jointe, vous trouverez une capture d'écran de ma page actuelle. Merci pour votre aide Link to comment Share on other sites More sharing options...
Mediacom87 Posted May 27 Share Posted May 27 Bonjour, la documentation officielle comporte des exemples pour ce genre de cas : https://devdocs.prestashop-project.org/8/modules/sample-modules/ Link to comment Share on other sites More sharing options...
Clement.drj Posted May 27 Author Share Posted May 27 Merci pour votre aide. Cela reste assez technique pour moi, pouvez-vous m'apporter plus de détails ? Merci. Link to comment Share on other sites More sharing options...
Mediacom87 Posted May 27 Share Posted May 27 Si cela est trop technique pour vous, alors vous pouvez passer par un module déjà existant comme celui-ci. Link to comment Share on other sites More sharing options...
Clement.drj Posted May 29 Author Share Posted May 29 Merci pour votre aide. Link to comment Share on other sites More sharing options...
ZHSoft Posted May 30 Share Posted May 30 Use the SQL export function that comes with the order list, and then modify the SQL and import it into SQL Manager. Link to comment Share on other sites More sharing options...
WebDesk Solution Posted June 7 Share Posted June 7 Hello @Clement.drj, To display the promo codes column on my orders page please follow the below steps Step 1: add the below code in the getColumns function to add a new column in order listing on the admin sideFile Path: src\Core\Grid\Definition\Factory\OrderGridDefinitionFactory.phpCode: ->add((new DataColumn('code')) ->setName($this->trans('Code', [], 'Admin.Global')) ->setOptions([ 'field' => 'code', 'sortable' => false, ]) ) Screenshot: https://prnt.sc/wRqfM6vMFZa_ Step 2: to get the promo code from db please use the below code to get from the database File Path: src\Core\Grid\Data\Factory\OrderGridDataFactory.phpCode: $sql = 'SELECT o.id_order, cr.code as promo_code FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'order_cart_rule ocr ON ocr.id_order = o.id_order LEFT JOIN ' . _DB_PREFIX_ . 'cart_rule cr ON ocr.id_cart_rule = cr.id_cart_rule'; $promoCodes = Db::getInstance()->executeS($sql); foreach ($promoCodes as $promoCode) { if ($promoCode['id_order'] == $record['id_order']) { if(!$promoCode['promo_code']){ $record['code'] = '-'; } else { $record['code'] = $promoCode['promo_code']; } } } add the above code to the given path from the screenshot belowScreenshot: https://prnt.sc/uZ0YcgCC-ClJStep 4: Clear Cache After making these changes, clear the cache to ensure the updates take effect. You can do this from the back office: Go to Advanced Parameters > Performance. Click on Clear Cache.Preview: https://prnt.sc/DxcjGagiwi-v Link to comment Share on other sites More sharing options...
hekai Posted June 25 Share Posted June 25 On 6/7/2024 at 11:23 PM, WebDesk Solution said: Hello @Clement.drj, To display the promo codes column on my orders page please follow the below steps Step 1: add the below code in the getColumns function to add a new column in order listing on the admin sideFile Path: src\Core\Grid\Definition\Factory\OrderGridDefinitionFactory.phpCode: ->add((new DataColumn('code')) ->setName($this->trans('Code', [], 'Admin.Global')) ->setOptions([ 'field' => 'code', 'sortable' => false, ]) ) Screenshot: https://prnt.sc/wRqfM6vMFZa_ Step 2: to get the promo code from db please use the below code to get from the database File Path: src\Core\Grid\Data\Factory\OrderGridDataFactory.phpCode: $sql = 'SELECT o.id_order, cr.code as promo_code FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'order_cart_rule ocr ON ocr.id_order = o.id_order LEFT JOIN ' . _DB_PREFIX_ . 'cart_rule cr ON ocr.id_cart_rule = cr.id_cart_rule'; $promoCodes = Db::getInstance()->executeS($sql); foreach ($promoCodes as $promoCode) { if ($promoCode['id_order'] == $record['id_order']) { if(!$promoCode['promo_code']){ $record['code'] = '-'; } else { $record['code'] = $promoCode['promo_code']; } } } add the above code to the given path from the screenshot belowScreenshot: https://prnt.sc/uZ0YcgCC-ClJStep 4: Clear Cache After making these changes, clear the cache to ensure the updates take effect. You can do this from the back office: Go to Advanced Parameters > Performance. Click on Clear Cache.Preview: https://prnt.sc/DxcjGagiwi-v There was an error, could you please help? Thank you Attempted to load class "Db" from namespace "PrestaShop\PrestaShop\Core\Grid\Data\Factory". Did you forget a "use" statement for another namespace? [Symfony\Component\Debug\Exception\ClassNotFoundException 0] Link to comment Share on other sites More sharing options...
critiks Posted July 30 Share Posted July 30 Same problem ?? Attempted to load class "Db" from namespace "PrestaShop\PrestaShop\Core\Grid\Data\Factory". Did you forget a "use" statement for another namespace? [Symfony\Component\Debug\Exception\ClassNotFoundException 0] Do i need to delete var > cache or do i need to add an other : use PrestaShop\PrestaShop\Core\Grid\... ? Any help ? Link to comment Share on other sites More sharing options...
critiks Posted July 30 Share Posted July 30 Solved : I add at the end of my file, for namespace : use Db; And i deleted the cache; it's works; But i can not filtered promo code in my grid ? Do somebody knows how can i filter my promo code in the order's admin grid ? 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