First you need to track order status changes,
Magento is provide to track old data and new changed data
using getOrigData()
and getData()
on save event fire.So easily using the feature,you can get changes Status and on basic of this,you can fire the Sms
Error:
When sales_order_save_after event is fire
then you can get only one order data
that means code at observer is wrong.
Solution:
As i said that when Model is saving then you can get old and new Data using
Current Data: $Object->getOrigData();
and
Changing new Data : $object->getData()
Using those function when you can easy track order status changes
.
And suggesting to you that use event sales_order_save_commit_after instead of sales_order_save_after
because if any issue has occurred during the save magento is roll back to old data and show the errors.
you can Old status by $OldStatus=$order->getOrigData('status'
)
and new Status
$NewStatus=$order->getData('status');
Code:
public function sendSMS($observer)
{
$order = $observer->getEvent()->getOrder();
if (!$order->getId()) {
//order not saved in the database
return $this;
}
/* @var $order Mage_Sales_Model_Order */
$OldData=$order->getOrigData();
$NewData=$order->getData();
$OldState==$order->getOrigData('state');
$NewState=$order->getState();
$OldStatus=$order->getOrigData('status');
$NewStatus=$order->getStatus();
/* Fire sms when New Status and old Statu are not same */
if($OldStatus!=$NewStatus){
//fire sms;
$smsMessageTemp =Mage::getModel('core/variable')->loadByCode('template_sms_order_placement_confirmation')->getValue('plain');
}
return $this;
}
yes, Magento 2 still allows you to define the default values inside a configuration file.
namespace\modulename\etc\config.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<sectionname>
<groupname>
<fieldid>1</fieldid>
</groupname>
</sectionname>
</default>
</config>
System configuration system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="namespace_tab" translate="label" sortOrder="1">
<label>COnfig Title</label>
</tab>
<section id="sectionname" translate="label" sortOrder="1" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Some Title</label>
<tab>namespace_tab</tab>
<resource>Namespace_Modulename::system_config</resource>
<group id="groupname" translate="label" type="text" sortOrder="1" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Some Configuration</label>
<field id="fieldid" translate="label" type="select" sortOrder="1"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable in frontend</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
Best Answer
Add the following to the
<orderPlaceMessage>
element:This will add these validation CSS classes used by prototype.js. If you enter a longer value, you will see this generic validation message:
So it is a good idea to add a comment as well to let the user know what this range is:
If the limit is important for data integrity, you should also add server side validatation, using a backend model. Digital Pianism already linked a tutorial for this: http://alanstorm.com/magento_system_config_validation
And if you want to know more about the various options in system.xml, there is: http://alanstorm.com/magento_system_configuration_in_depth_tutorial