cancel
Showing results for 
Search instead for 
Did you mean: 

Get products by coupon

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Get products by coupon

Hello!

I want to get products by coupon code filtered whether by SKU or Mark so I can get theses details:

,order date price before discount , price after discount, name /surname of the client, telephone , country and product name 

For order date ,price before discount and price after discount I got them named 'created_at','subtotal' and 'grand_total' from the table sales_flate_order . But I can not find the other items

Thanks in advance

3 REPLIES 3

Re: Get products by coupon

Hello @ahmed_chouihi 

 

Use the below code for your requirement:

 

<?php
require '../app/Mage.php';
Mage::app();
$order_collection = Mage::getModel('sales/order')
    ->getCollection()
    ->addFieldToFilter('coupon_code','496672')
    ->setPageSize(50)
    ->setCurPage($p)
    ->setOrder('entity_id', 'DESC');
foreach ($order_collection as $order) {
    echo $order->getIncrementId().'<br>';
}
?>

You will get all the orders where the coupon code 496672 is used, using the above code.

Hope it helps.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: Get products by coupon

Thanks for your answer , but this will show many fields not specific fields.

Re: Get products by coupon

I have used your script and it is causing this error 

PHP Fatal error:  Uncaught exception 'Zend_Exception' with message 'dbModel read resource does not implement Zend_Db_Adapter_Abstract' in /var/www/magento/lib/Varien/Data/Collection/Db.php:187
Stack trace:
#0 /var/www/magento/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php(134): Varien_Data_Collection_Db->setConnection(false)
#1 /var/www/magento/app/code/core/Mage/Core/Model/Config.php(1354): Mage_Core_Model_Resource_Db_Collection_Abstract->__construct(Object(Mage_Sales_Model_Resource_Order))
#2 /var/www/magento/app/code/core/Mage/Core/Model/Config.php(1386): Mage_Core_Model_Config->getModelInstance('sales_resource/...', Object(Mage_Sales_Model_Resource_Order))
#3 /var/www/magento/app/Mage.php(491): Mage_Core_Model_Config->getResourceModelInstance('sales/order_col...', Object(Mage_Sales_Model_Resource_Order))
#4 /var/www/magento/app/code/core/Mage/Core/Model/Abstract.php(208): Mage::getResourceModel('sales/order_col...', Object(Mage_Sales_Model_Resource_Order))
#5 /var/www/magento/app/code/core/Mage/Core/Mode in /var/www/magento/lib/Varien/Data/Collection/Db.php on line 187

Keep in mind that I am using magento 1.9

Thanks in advance