Jump to content

aveeva

Members
  • Content Count

    87
  • Joined

  • Last visited

Community Reputation

0 Neutral

About aveeva

  • Rank
    Regular Member
  1. Finally done with below script : <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); // $this->sendMailbasedOnSku($sku); $message = "<tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = "<p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; // $this->sendMail($finalMessage); $this->sendMailbasedOnSku($finalMessage,$sku); } } public function sendMail($message) { $body = "$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('Test mail'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); // $emailTemplate->setToEmail('abc@gmail.com'); if($sku == '2') { $emailTemplate->setToEmail('abc@gmail.com'); } elseif($sku == '3') { $emailTemplate->setToEmail('xyz@gmail.com'); } elseif($sku == '4') { $emailTemplate->setToEmail('qwe@gmail.com'); } else { $emailTemplate->setToEmail('ewq@gmail.com'); } $emailTemplate->send(); } public function sendMailbasedOnSku($message, $sku) { $body = "$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('Giri Test mail'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $chk_sku=(int)substr($sku, 0, 1); if($chk_sku == '2') { $emailTemplate->setToEmail('abc@gmail.com'); } elseif($chk_sku == '3') { $emailTemplate->setToEmail('xyz@gmail.com'); } elseif($chk_sku == '4') { $emailTemplate->setToEmail('qwe@gmail.com'); } else{ $emailTemplate->setToEmail('ewq@gmail.com'); } return $emailTemplate->send(); // try{ // return $emailTemplate->send(); // Mage::getSingleton('core/session')->addSuccess('Success message'); // }catch (Exception $e) // { // Mage::getSingleton('core/session')->addError($e->getMessage()); // } } } ?> But few correction are there, how to solve below logic, eg: If an order contains, 2 series of sku and 3 series of sku order mail received only by 3 series of sku mail not received 2 series of sku mail. another eg. If order placed with 3 products, sku- 22 (abc@gmail.com), sku - 33 (xyz@gmail.com), sku -44 (qwe@gmail.com) order received only qwe@gmail.com My condition, if the order contains 2 products means to send a separate mail. like 2 series of sku : 3 series of sku : 4 Series of sku : now order received highest value of sku,
  2. @Barand code : <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $this->sendMailbasedOnSku($sku); $message = "<tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; // $itemData[$list->getId()] = $message; $itemData[$orderNo][$skuFirst] = $message; } $finalMessage = "<p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMailbasedOnSku($finalMessage); } } public function sendMailbasedOnSku($message) { $body = "$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName(' Test mail'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $addys = [ 2 => 'abc@gmail.com', 3 => 'xyz@gmail.com', 4 => 'qwe@gmail.com' ]; // CHECK SKU FIRST DIGIT $chk_sku=(int)substr($sku, 0, 1); if($chk_sku == '2') { $sendTo = $addys[$chk_sku] ?? 'abc@gmail.com'; } elseif($chk_sku == '3') { $sendTo = $addys[$chk_sku] ?? 'xyz@gmail.com'; } elseif($chk_sku == '4') { $sendTo = $addys[$chk_sku] ?? 'qwe@gmail.com'; } else{ $emailTemplate->setToEmail('ewq@gmail.com'); } $emailTemplate->setToEmail($sendTo); return $emailTemplate->send(); } } ?> order not placed.
  3. getting error, <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $this->sendMailbasedOnSku($sku); $message = "<tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; // $itemData[$list->getId()] = $message; $itemData[$orderNo][$skuFirst] = $message; } $finalMessage = "<p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMailbasedOnSku($finalMessage); } } public function sendMailbasedOnSku($message) { $body = "$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('GIRI Test mail'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $addys = [ 2 => 'jeevarathinamit@gmail.com', 3 => 'aveevacool@gmail.com', 4 => 'zus710@gmail.com' ]; // CHECK SKU FIRST DIGIT $chk_sku=(int)substr($sku, 0, 1); if($chk_sku == '2') { $sendTo = $addys[$chk_sku] ?? 'jeevarathinamit@gmail.com'; } elseif($chk_sku == '3') { $sendTo = $addys[$chk_sku] ?? 'aveevacool@gmail.com'; } elseif($chk_sku == '4') { $sendTo = $addys[$chk_sku] ?? 'zus710@gmail.com'; } else{ $emailTemplate->setToEmail('giriwebsiteonline@gmail.com'); } return $emailTemplate->send(); } } ?> Could you help me with above script.
  4. @Barand here i can see only one mail id, $chk_sku=substr($sku, 0, 1); $sendTo = $addys[$chk_sku] ?? 'ewo@gmail.com'; How to add more than one mail id?
  5. @Barand Updated Code : <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $this->sendMailbasedOnSku($sku); $message = "<tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = " <p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMailbasedOnSku($finalMessage); } } public function sendMailbasedOnSku($message) { $body = "$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('Test mail'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $chk_sku=(int)substr($sku, 0, 1); $emailTemplate = Mage::getModel('core/email'); if($chk_sku == '2') { $emailTemplate->setToEmail('abc@gmail.com'); } elseif($chk_sku == '3') { $emailTemplate->setToEmail('xyz@gmail.com'); } elseif($chk_sku == '4') { $emailTemplate->setToEmail('qwe@gmail.com'); } else{ $emailTemplate->setToEmail('ewq@gmail.com'); } try{ $emailTemplate->send(); Mage::getSingleton('core/session')->addSuccess('Success message'); }catch (Exception $e) { Mage::getSingleton('core/session')->addError($e->getMessage()); } } } ?> Anything wrong?
  6. How to declare more than one mail id, $chk_sku=substr($sku, 0, 1); $sendTo = $addys[$chk_sku] ?? 'ewo@gmail.com';
  7. Final code : <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $this->sendMailbasedOnSku($sku); $message = "<tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = " <p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body = "$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('Test mail'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); // $emailTemplate->setToEmail('abc@gmail.com'); if($sku == '2') { $emailTemplate->setToEmail('abc@gmail.com'); } elseif($sku == '3') { $emailTemplate->setToEmail('xyz@gmail.com'); } elseif($sku == '4') { $emailTemplate->setToEmail('qwe@gmail.com'); } else { $emailTemplate->setToEmail('ewq@gmail.com'); } $emailTemplate->send(); } public function sendMailbasedOnSku($sku) { $chk_sku=(int)substr($sku, 0, 1); $emailTemplate = Mage::getModel('core/email'); if($chk_sku == '2') { $emailTemplate->setToEmail('abc@gmail.com'); } elseif($chk_sku == '3') { $emailTemplate->setToEmail('xyz@gmail.com'); } elseif($chk_sku == '4') { $emailTemplate->setToEmail('qwe@gmail.com'); } else{ $emailTemplate->setToEmail('ewq@gmail.com'); } try{ return $emailTemplate->send(); Mage::getSingleton('core/session')->addSuccess('Success message'); }catch (Exception $e) { Mage::getSingleton('core/session')->addError($e->getMessage()); } } } ?>
  8. @Barand After added $emailTemplate = Mage::getModel('core/email'); mail working, but if condition not working. As per my condition if sku start with 2 mail should go to abc@gmail.com but here mail received ewq@gmail.com (Final email id in my if condition). How to correct my script?
  9. Any help with my error, Code : <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $this->sendMailbasedOnSku($sku); $message = "<tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = " <p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body = "$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('Test mail'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); // $emailTemplate->setToEmail('abc@gmail.com'); if($sku == '2') { $emailTemplate->setToEmail('abc@gmail.com'); } elseif($sku == '3') { $emailTemplate->setToEmail('xyz@gmail.com'); } elseif($sku == '4') { $emailTemplate->setToEmail('qwe@gmail.com'); } else { $emailTemplate->setToEmail('ewq@gmail.com'); } $emailTemplate->send(); } public function sendMailbasedOnSku($sku) { // sku is 22302 $chk_sku=(int)substr($sku, 0, 1); if($chk_sku == '2') { $emailTemplate->setToEmail('abc@gmail.com'); } elseif($chk_sku == '3') { $emailTemplate->setToEmail('xyz@gmail.com'); } elseif($chk_sku == '4') { $emailTemplate->setToEmail('qwe@gmail.com'); } else{ $emailTemplate->setToEmail('ewq@gmail.com'); } try{ return $emailTemplate->send(); Mage::getSingleton('core/session')->addSuccess('Your request has been sent'); } catch (Exception $e) { Mage::getSingleton('core/session')->addError($e->getMessage()); } } } ?> error : [09-Jan-2020 04:53:42 UTC] PHP Fatal error: Uncaught Error: Call to a member function setToEmail() on null in C:\wamp64\www\magento\app\code\local\Gta\MerchantNotification\Model\Observer.php:99 Stack trace: #0 C:\wamp64\www\magento\app\code\local\Gta\MerchantNotification\Model\Observer.php(15): Gta_MerchantNotification_Model_Observer->sendMailbasedOnSku('22') #1 C:\wamp64\www\magento\app\code\core\Mage\Core\Model\App.php(1358): Gta_MerchantNotification_Model_Observer->merchantremainder(Object(Varien_Event_Observer)) #2 C:\wamp64\www\magento\app\code\core\Mage\Core\Model\App.php(1337): Mage_Core_Model_App->_callObserverMethod(Object(Gta_MerchantNotification_Model_Observer), 'merchantremaind...', Object(Varien_Event_Observer)) #3 C:\wamp64\www\magento\app\Mage.php(448): Mage_Core_Model_App->dispatchEvent('checkout_submit...', Array) #4 C:\wamp64\www\magento\app\code\core\Mage\Checkout\Model\Type\Onepage.php(872): Mage::dispatchEvent('checkout_submit...', Array) #5 C:\wamp64\www\magento\app\code\core\Mage\Checkout\controllers\OnepageController.php(579): M in C:\wamp64\www\magento\app\code\local\Gta\MerchantNotification\Model\Observer.php on line 99
  10. PHP mail function how to set recipient mail id based on if condition?
  11. I am using magento for sending mail with condition, My code: <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $extra = $order->getIncrementId(); $message = " <tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = " <p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body ="$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('abc'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $emailTemplate->setToEmail('abc@gmail.com'); $emailTemplate->send(); } } ?> Output : If order placed mail send to abc@gmail.com. How to set email sender based on SKU $sku from order. I want : 1) If SKU starts with 2, email should go to the mail id abc@gmail.com, screenshot : 2) If SKU starts with 3, email should go to the mail id xyz@gmail.com, screenshot : 3) If SKU starts with 4, email should go to the mail id qwe@gmail.com, screenshot : FYI - If an order contains 10 items email should go separately based on SKU. But an order id the same must include all the emails.
  12. Magento PHP mail function : <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $extra = $order->getIncrementId(); $message = " <tr> <td>$incrementid</td> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = "<table border='1'> <tr> <th>Id</th> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body ="$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('abc'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $emailTemplate->setToEmail('aveevacool@gmail.com'); $emailTemplate->send(); } } ?> Now my output like :
  13. PHP script return 20 UL LIST values like, < ul > A B C D E F G H I J K L M N O P Q R S T < /ul > How to display UL LIST into row wise 5 columns like A B C D E F G H I J K L M N O P Q R S T (20 ITEMS)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.