From c03c3f9ed93031cf8e0302b4118685b726c5deca Mon Sep 17 00:00:00 2001 From: iesus Date: Wed, 21 Mar 2018 09:10:38 +0000 Subject: [PATCH] let store choose reference and status more freely --- .../Checkout/Model/Payment/Acknowledge.php | 10 ++++- .../Model/System/Source/Svea/Reference.php | 43 +++++++++++++++++++ .../controllers/ValidationController.php | 16 +++++-- .../community/Svea/Checkout/etc/config.xml | 3 ++ .../community/Svea/Checkout/etc/system.xml | 16 ++++++- 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 app/code/community/Svea/Checkout/Model/System/Source/Svea/Reference.php diff --git a/app/code/community/Svea/Checkout/Model/Payment/Acknowledge.php b/app/code/community/Svea/Checkout/Model/Payment/Acknowledge.php index 72a5e15..d33970f 100755 --- a/app/code/community/Svea/Checkout/Model/Payment/Acknowledge.php +++ b/app/code/community/Svea/Checkout/Model/Payment/Acknowledge.php @@ -90,13 +90,19 @@ public function acknowledge($quote, $mode, $sveaId) $magentoOrder->setCustomerEmail($sveaData->getData('EmailAddress')); } - $status = Mage::getStoreConfig('payment/SveaCheckout/order_status_after_acknowledge'); + $statusText = Mage::getStoreConfig('payment/SveaCheckout/order_status_after_acknowledge'); $message = $helper->__("Order was acknowledged by Svea."); $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); + $state = Mage::getModel('sales/order_status') + ->getCollection() + ->joinStates() + ->addFieldToFilter('main_table.status', $statusText) + ->getFirstItem(); + $magentoOrder - ->setState(Mage_Sales_Model_Order::STATE_NEW, $status, $message, false) + ->setState($state->getState(), $statusText, $message, false) ->save(); $magentoOrder->getSendConfirmation(null); diff --git a/app/code/community/Svea/Checkout/Model/System/Source/Svea/Reference.php b/app/code/community/Svea/Checkout/Model/System/Source/Svea/Reference.php new file mode 100644 index 0000000..9b48d96 --- /dev/null +++ b/app/code/community/Svea/Checkout/Model/System/Source/Svea/Reference.php @@ -0,0 +1,43 @@ + + */ +class Svea_Checkout_Model_System_Source_Svea_Reference +{ + /** + * Creates a list of available reference options. + * countries and locales. + * + * @return array + */ + public function toOptionArray() + { + return [ + [ + 'label' => Mage::helper('sveacheckout')->__('Suffixed Order ID'), + 'title' => Mage::helper('sveacheckout')->__('Suffixed Order ID'), + 'value' => 'suffixed-order-id', + ], + [ + 'label' => Mage::helper('sveacheckout')->__('Suffixed Increment ID'), + 'title' => Mage::helper('sveacheckout')->__('Suffixed Increment ID'), + 'value' => 'suffixed-increment-id', + ], + [ + 'label' => Mage::helper('sveacheckout')->__('Plain Order ID'), + 'title' => Mage::helper('sveacheckout')->__('Plain Order ID'), + 'value' => 'plain-order-id', + ], + [ + 'label' => Mage::helper('sveacheckout')->__('Plain Increment ID'), + 'title' => Mage::helper('sveacheckout')->__('Plain Increment ID'), + 'value' => 'plain-increment-id', + ] + ]; + } +} diff --git a/app/code/community/Svea/Checkout/controllers/ValidationController.php b/app/code/community/Svea/Checkout/controllers/ValidationController.php index 0804d4d..43bcc27 100755 --- a/app/code/community/Svea/Checkout/controllers/ValidationController.php +++ b/app/code/community/Svea/Checkout/controllers/ValidationController.php @@ -152,16 +152,24 @@ protected function reportAndReturn($httpStatus, $logMessage, $order = false) protected function _makeSveaOrderId($orderId) { - $incrementId = Mage::getResourceModel('sales/order') - ->getIncrementId($orderId); + $reference = $orderId; + $useForReference = Mage::getStoreConfig('payment/sveacheckout_dev_settings/reference'); + if (in_array($useForReference, ['plain-increment-id', 'suffixed-increment-id'])) { + $reference = Mage::getResourceModel('sales/order') + ->getIncrementId($orderId); + } + if (in_array($useForReference, ['plain-increment-id', 'plain-order-id'])) { + + return $reference; + } //To avoid order already being created, if you for example have //stageEnv/devEnv and ProductionEnv with quote id in same range. $allowedLength = 32; $separator = '_'; - $lengthOfHash = $allowedLength - (strlen((string)$incrementId) + strlen($separator)); + $lengthOfHash = $allowedLength - (strlen((string)$reference) + strlen($separator)); $hashedBaseUrl = sha1(Mage::getBaseUrl()); - $clientId = $incrementId . $separator . mb_substr($hashedBaseUrl, 0, $lengthOfHash); + $clientId = $reference . $separator . mb_substr($hashedBaseUrl, 0, $lengthOfHash); return $clientId; } diff --git a/app/code/community/Svea/Checkout/etc/config.xml b/app/code/community/Svea/Checkout/etc/config.xml index 0711997..a7b9001 100644 --- a/app/code/community/Svea/Checkout/etc/config.xml +++ b/app/code/community/Svea/Checkout/etc/config.xml @@ -103,6 +103,9 @@ + + suffixed-increment-id + diff --git a/app/code/community/Svea/Checkout/etc/system.xml b/app/code/community/Svea/Checkout/etc/system.xml index 43d21f0..5e860c3 100644 --- a/app/code/community/Svea/Checkout/etc/system.xml +++ b/app/code/community/Svea/Checkout/etc/system.xml @@ -76,7 +76,7 @@ Status to used after order has been acknowledge by Svea. ]]> select - adminhtml/system_config_source_order_status_new + adminhtml/system_config_source_order_status_newprocessing 50 1 1 @@ -236,6 +236,20 @@ 1 1 + + + + do not use plain id's on a stage or dev environment
+ if the range can overlap with another environment. + ]]>
+ select + sveacheckout/system_source_svea_reference + 93 + 1 + 1 + 1 +