Jump to content

Affiche les codes promo sur la page COMMANDES


Recommended Posts

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

 

 

Capture d'écran 2024-05-27 094956.png

Link to comment
Share on other sites

  • 2 weeks later...

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 side
File Path: src\Core\Grid\Definition\Factory\OrderGridDefinitionFactory.php
Code:

->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.php
Code:

$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 below
Screenshot: https://prnt.sc/uZ0YcgCC-ClJ

Step 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

  • 3 weeks later...
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 side
File Path: src\Core\Grid\Definition\Factory\OrderGridDefinitionFactory.php
Code:

->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.php
Code:

$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 below
Screenshot: https://prnt.sc/uZ0YcgCC-ClJ

Step 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

  • 1 month later...

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...