Add code in config.xml in module in etc folder(Path : app/local/namespace/modulename/etc)
<events>
<checkout_type_onepage_save_order>
<observers>
<onestepcheckout_save_order_comment>
<type>helper</type>
<class>DCKAP_Onestepcheckout_Helper_Data</class>
<method>setOrderCommentCompatible1</method>
</onestepcheckout_save_order_comment>
</observers>
</checkout_type_onepage_save_order>
<checkout_type_onepage_save_order_after>
<observers>
<onestepcheckout_save_order_comment>
<type>helper</type>
<class>DCKAP_Onestepcheckout_Helper_Data</class>
<method>setOrderCommentCompatible2</method>
</onestepcheckout_save_order_comment>
</observers>
</checkout_type_onepage_save_order_after>
<sales_model_service_quote_submit_after>
<observers>
<onestepcheckout_service_quote_submit_order_comment>
<type>helper</type>
<class>DCKAP_Onestepcheckout_Helper_Data</class>
<method>setOrderCommentCompatible2</method>
</onestepcheckout_service_quote_submit_order_comment>
</observers>
</sales_model_service_quote_submit_after>
</events>
Add code in helper (path : app/code/local/namespace/modulename/helper)
public function isOrderComment() {
return Mage::getStoreConfig('onestepcheckout/general/comment');
}
public function setOrderCommentCompatible1($observer) {
if ($this->getCompatibility() != self::COMPATIBILITY_TYPE1) {
return;
}
if ($this->isOrderComment()) {
$orderComment = trim($this->_getRequest()->getPost('order_comment'));
if ($orderComment != "") {
$observer->getEvent()->getOrder()->addStatusHistoryComment($orderComment,true);
} else {
$observer->getEvent()->getOrder()->setOrderComment(Mage::getSingleton('checkout/session')->getOpcheckoutOrderComment());
Mage::getSingleton('checkout/session')->unsOpcheckoutOrderComment();
}
}
}
public function setOrderCommentCompatible2($observer) {
if ($this->getCompatibility() != self::COMPATIBILITY_TYPE2) {
return;
}
if ($this->isOrderComment()) {
$orderComment = trim($this->_getRequest()->getPost('order_comment'));
if ($orderComment == "") {
$orderComment = Mage::getSingleton('checkout/session')->getOpcheckoutOrderComment();
Mage::getSingleton('checkout/session')->unsOpcheckoutOrderComment();
}
$order = $observer->getEvent()->getOrder();
if ($order && ($orderComment != "")) {
if ($order->getId()) {
$resource = Mage::getSingleton('core/resource');
$sales_order = $resource->getTableName('sales_order');
$resource->getConnection('core_write')->update($sales_order, array('order_comment' => $orderComment), array('entity_id = ?' => $order->getId()));
}
}
}
}
Add code in template html file
<?php
echo "comment add".Mage::helper('onestepcheckout')->isOrderComment();
if(Mage::helper('onestepcheckout')->isOrderComment()):?>
<div>
<div>
<ol class="checkout-agreements-ol">
<li>
<?php $_MAX_CHAR = Mage::getStoreConfig('onestepcheckout/order/opcheckout_order_comment_length'); ?>
<?php $_msg = ''; $flag = false;?>
<?php if($_MAX_CHAR != '' && $_MAX_CHAR != 0): ?>
<?php $flag = true;?>
<?php $_msg = $this->__('Maximum Character(s):'.$_MAX_CHAR);?>
<?php endif; ?>
<label for="opcheckout_order_comment"><?php echo $this->__('Your Comment for this Order. ')?></label>
<br/><textarea name="opcheckout-order-comment" id="opcheckout_order_comment" class="opcheckout_order_comment"></textarea>
<?php echo $_msg ? $_msg : ''?>
<span id="comment_count_left"></span>
</li>
</ol>
<script type="text/javascript">
<?php if($flag): ?>
var MAX_CHAR = '<?php echo $_MAX_CHAR; ?>';
var msg = '<?php echo $this->__('Character Left: ')?>';
$('comment_count_left').innerHTML = msg+MAX_CHAR;
<?php endif; ?>
$('opcheckout_order_comment').observe('keyup',function(){
<?php if($flag):?>
var len = $(this).value.length;
if(len>MAX_CHAR){
$(this).value = $(this).value.substring(0, MAX_CHAR);
}
$('comment_count_left').innerHTML = msg+(MAX_CHAR - $(this).value.length);
<?php endif; ?>
$('hidden_opcheckout_order_comment').value = $(this).value;
});
</script>
</div>
</div>
<?php endif; ?>
<events>
<checkout_type_onepage_save_order>
<observers>
<onestepcheckout_save_order_comment>
<type>helper</type>
<class>DCKAP_Onestepcheckout_Helper_Data</class>
<method>setOrderCommentCompatible1</method>
</onestepcheckout_save_order_comment>
</observers>
</checkout_type_onepage_save_order>
<checkout_type_onepage_save_order_after>
<observers>
<onestepcheckout_save_order_comment>
<type>helper</type>
<class>DCKAP_Onestepcheckout_Helper_Data</class>
<method>setOrderCommentCompatible2</method>
</onestepcheckout_save_order_comment>
</observers>
</checkout_type_onepage_save_order_after>
<sales_model_service_quote_submit_after>
<observers>
<onestepcheckout_service_quote_submit_order_comment>
<type>helper</type>
<class>DCKAP_Onestepcheckout_Helper_Data</class>
<method>setOrderCommentCompatible2</method>
</onestepcheckout_service_quote_submit_order_comment>
</observers>
</sales_model_service_quote_submit_after>
</events>
Add code in helper (path : app/code/local/namespace/modulename/helper)
public function isOrderComment() {
return Mage::getStoreConfig('onestepcheckout/general/comment');
}
public function setOrderCommentCompatible1($observer) {
if ($this->getCompatibility() != self::COMPATIBILITY_TYPE1) {
return;
}
if ($this->isOrderComment()) {
$orderComment = trim($this->_getRequest()->getPost('order_comment'));
if ($orderComment != "") {
$observer->getEvent()->getOrder()->addStatusHistoryComment($orderComment,true);
} else {
$observer->getEvent()->getOrder()->setOrderComment(Mage::getSingleton('checkout/session')->getOpcheckoutOrderComment());
Mage::getSingleton('checkout/session')->unsOpcheckoutOrderComment();
}
}
}
public function setOrderCommentCompatible2($observer) {
if ($this->getCompatibility() != self::COMPATIBILITY_TYPE2) {
return;
}
if ($this->isOrderComment()) {
$orderComment = trim($this->_getRequest()->getPost('order_comment'));
if ($orderComment == "") {
$orderComment = Mage::getSingleton('checkout/session')->getOpcheckoutOrderComment();
Mage::getSingleton('checkout/session')->unsOpcheckoutOrderComment();
}
$order = $observer->getEvent()->getOrder();
if ($order && ($orderComment != "")) {
if ($order->getId()) {
$resource = Mage::getSingleton('core/resource');
$sales_order = $resource->getTableName('sales_order');
$resource->getConnection('core_write')->update($sales_order, array('order_comment' => $orderComment), array('entity_id = ?' => $order->getId()));
}
}
}
}
Add code in template html file
<?php
echo "comment add".Mage::helper('onestepcheckout')->isOrderComment();
if(Mage::helper('onestepcheckout')->isOrderComment()):?>
<div>
<div>
<ol class="checkout-agreements-ol">
<li>
<?php $_MAX_CHAR = Mage::getStoreConfig('onestepcheckout/order/opcheckout_order_comment_length'); ?>
<?php $_msg = ''; $flag = false;?>
<?php if($_MAX_CHAR != '' && $_MAX_CHAR != 0): ?>
<?php $flag = true;?>
<?php $_msg = $this->__('Maximum Character(s):'.$_MAX_CHAR);?>
<?php endif; ?>
<label for="opcheckout_order_comment"><?php echo $this->__('Your Comment for this Order. ')?></label>
<br/><textarea name="opcheckout-order-comment" id="opcheckout_order_comment" class="opcheckout_order_comment"></textarea>
<?php echo $_msg ? $_msg : ''?>
<span id="comment_count_left"></span>
</li>
</ol>
<script type="text/javascript">
<?php if($flag): ?>
var MAX_CHAR = '<?php echo $_MAX_CHAR; ?>';
var msg = '<?php echo $this->__('Character Left: ')?>';
$('comment_count_left').innerHTML = msg+MAX_CHAR;
<?php endif; ?>
$('opcheckout_order_comment').observe('keyup',function(){
<?php if($flag):?>
var len = $(this).value.length;
if(len>MAX_CHAR){
$(this).value = $(this).value.substring(0, MAX_CHAR);
}
$('comment_count_left').innerHTML = msg+(MAX_CHAR - $(this).value.length);
<?php endif; ?>
$('hidden_opcheckout_order_comment').value = $(this).value;
});
</script>
</div>
</div>
<?php endif; ?>
No comments:
Post a Comment