Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed 'Initial order status change', introduced in v.1.2.7 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Observer/ChangeOrderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* IDEALIAGroup srl
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @copyright Copyright (c) 2014 IDEALIAGroup srl (http://www.idealiagroup.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace MSP\CashOnDelivery\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Model\QuoteRepository;
use Magento\Sales\Api\Data\OrderInterface;

class ChangeOrderStatus implements ObserverInterface
{
const CODE = 'msp_cashondelivery';
const XML_PATH_ORDER_STATUS = 'payment/msp_cashondelivery/order_status';

/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_scopeConfig = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface');
/** @var OrderInterface $order */
$order = $observer->getEvent()->getOrder();

if ($order->getPayment()->getMethod() == static::CODE) {
$currentStatus = $order->getStatus();
$customStatus = $_scopeConfig->getValue(static::XML_PATH_ORDER_STATUS);
if ($currentStatus != $customStatus) {
$order->setStatus($customStatus);
$order->save();
}
}
}
}
5 changes: 5 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
instance="MSP\CashOnDelivery\Observer\SalesModelServiceQuoteSubmitBefore"/>
</event>

<event name="sales_order_place_after">
<observer name="msp_change_order_status"
instance="MSP\CashOnDelivery\Observer\ChangeOrderStatus" />
</event>

</config>