Skip to content

Commit

Permalink
let store choose reference and status more freely
Browse files Browse the repository at this point in the history
  • Loading branch information
iesus committed Mar 21, 2018
1 parent d786ced commit c03c3f9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
10 changes: 8 additions & 2 deletions app/code/community/Svea/Checkout/Model/Payment/Acknowledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Source model to get an array of supported language settings.
*
* @package Svea_Checkout
* @module Webbhuset
* @author Webbhuset <[email protected]>
*/
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',
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions app/code/community/Svea/Checkout/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
<order_status><![CDATA[sveacheckout_pending]]></order_status>
<order_status_before_acknowledge><![CDATA[sveacheckout_acknowledged]]></order_status_before_acknowledge>
</sveacheckout>
<sveacheckout_dev_settings>
<reference>suffixed-increment-id</reference>
</sveacheckout_dev_settings>
</payment>
</default>
<sales>
Expand Down
16 changes: 15 additions & 1 deletion app/code/community/Svea/Checkout/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
Status to used <u>after</u> order has been acknowledge by Svea.
]]></comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status_new</source_model>
<source_model>adminhtml/system_config_source_order_status_newprocessing</source_model>
<sort_order>50</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand Down Expand Up @@ -236,6 +236,20 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</push_uri>
<reference translate="label comment" module="sveacheckout">
<label>Reference ID</label>
<comment><![CDATA[
Suffix is a duplicate id countermeasure <br/>
<strong>do not</strong> use plain id's on a stage or dev environment<br/>
if the range can overlap with another environment.
]]></comment>
<frontend_type>select</frontend_type>
<source_model>sveacheckout/system_source_svea_reference</source_model>
<sort_order>93</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</reference>
</fields>
</sveacheckout_dev_settings>
</fields>
Expand Down

0 comments on commit c03c3f9

Please sign in to comment.