diff --git a/Block/Payment/Checkout/Info.php b/Block/Payment/Checkout/Info.php index f3e8c40..159d92a 100644 --- a/Block/Payment/Checkout/Info.php +++ b/Block/Payment/Checkout/Info.php @@ -36,4 +36,13 @@ public function getSveaCheckoutId() return ""; } } + + public function getSveaCustomerReference() + { + try { + return $this->getInfo()->getAdditionalInformation('svea_customer_reference'); + } catch (\Exception $e) { + return ""; + } + } } diff --git a/Controller/Order/Push.php b/Controller/Order/Push.php index 299e9d2..be39d32 100644 --- a/Controller/Order/Push.php +++ b/Controller/Order/Push.php @@ -178,21 +178,13 @@ protected function createMagentoOrder(GetOrderResponse $sveaOrder, $sveaHash) // here we create the magento order + $quote->getPayment()->setAdditionalInformation('svea_payment_method', $sveaOrder->getPaymentType()); try { // we try to create the order now ;) $order = $this->placeOrder($sveaOrder, $quote); } catch (\Exception $e) { throw $e; } - - // save svea payment info - try { - $order->getPayment()->setAdditionalInformation("svea_payment_method", $sveaOrder->getPaymentType()); - $this->sveaCheckoutContext->getOrderRepository()->save($order); - } catch (\Exception $e) { - // ignore - $this->getSveaCheckout()->getLogger()->error("Svea Push: Could not set svea payment method to order"); - } return $order; } diff --git a/Model/Checkout.php b/Model/Checkout.php index b66801a..37534dc 100644 --- a/Model/Checkout.php +++ b/Model/Checkout.php @@ -128,27 +128,12 @@ public function initCheckout($reloadIfCurrencyChanged = true, $reloadIfCountryCh $selectedShippingMethod = $this->checkAndChangeShippingMethod(); try { - $quote->setTotalsCollectedFlag(false)->collectTotals()->save(); //REQUIRED (maybe shipping amount was changed) + $quote->setTotalsCollectedFlag(false)->collectTotals(); //REQUIRED (maybe shipping amount was changed) + $this->quoteRepository->save($quote); } catch (\Exception $e) { // do nothing } - $billingAddress->save(); - $shippingAddress->save(); - - $this->totalsCollector->collectAddressTotals($quote, $shippingAddress); - $this->totalsCollector->collectQuoteTotals($quote); - - /** - * We need to reset shipping assignments before saving quote - * since they were changes - */ - $repositoryLoadHandler = $this->getRepositoryLoadHandler(); - $repositoryLoadHandler->load($quote); - - $quote->collectTotals(); - $this->quoteRepository->save($quote); - if (($reloadIfCurrencyChanged && $currencyChanged) || ($reloadIfCountryChanged && $countryChanged)) { //not needed $this->throwReloadException('Checkout was reloaded.'); @@ -612,6 +597,10 @@ public function placeOrder(GetOrderResponse $sveaOrder, Quote $quote) //set payment $payment = $quote->getPayment(); + $customerReference = $sveaOrder->getCustomerReference(); + if ($customerReference) { + $payment->setAdditionalInformation('svea_customer_reference', $customerReference); + } //force payment method if (!$payment->getMethod() || $payment->getMethod() != $this->_paymentMethod) { diff --git a/Model/Svea/Data/PresetValues/CustomerDataProvider.php b/Model/Svea/Data/PresetValues/CustomerDataProvider.php index ecc7b66..0b91b61 100644 --- a/Model/Svea/Data/PresetValues/CustomerDataProvider.php +++ b/Model/Svea/Data/PresetValues/CustomerDataProvider.php @@ -3,16 +3,16 @@ namespace Svea\Checkout\Model\Svea\Data\PresetValues; use Magento\Customer\Model\Session; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\DataObject; use Svea\Checkout\Model\Client\DTO\Order\PresetValue; +use Svea\Checkout\Helper\Data as Helper; class CustomerDataProvider implements PresetValuesProviderInterface { /** - * @var ScopeConfigInterface + * @var Helper */ - private $scopeConfig; + private $helper; /** * @var Session @@ -35,18 +35,18 @@ class CustomerDataProvider implements PresetValuesProviderInterface * @param Session $customer * @param DataObject $dataContainer * @param PresetValueFactory $presetValueFactory - * @param ScopeConfigInterface $scopeConfig + * @param Helper $helper */ public function __construct( Session $customer, DataObject $dataContainer, PresetValueFactory $presetValueFactory, - ScopeConfigInterface $scopeConfig + Helper $helper ) { $this->customer = $customer; $this->dataContainer = $dataContainer; $this->presetValueFactory = $presetValueFactory; - $this->scopeConfig = $scopeConfig; + $this->helper = $helper; } /** @@ -113,19 +113,17 @@ public function getPostalCode() : PresetValue */ public function getIsCompany() : PresetValue { - $customerType = $this->scopeConfig->getValue('svea_checkout/settings/default_customer_type'); - $customerTypes = $this->scopeConfig->getValue('svea_checkout/settings/customer_types'); - $customerTypes = explode(',', $customerTypes); + $customerType = $this->helper->getDefaultConsumerType(); + $customerTypes = $this->helper->getConsumerTypes(); $isB2B = $customerType == 'B2B'; - $isB2C = in_array('B2C', $customerTypes); $presetValue = new PresetValue(); $presetValue->setIsCompany($isB2B); $presetValue->setValue($isB2B); $isReadOnly = true; - if (count($customerTypes) > 1) { + if (is_array($customerTypes) && count($customerTypes) > 1) { $isReadOnly = false; } diff --git a/Model/Svea/Data/PresetValues/TestValuesProvider.php b/Model/Svea/Data/PresetValues/TestValuesProvider.php index 8d40cf2..558592a 100644 --- a/Model/Svea/Data/PresetValues/TestValuesProvider.php +++ b/Model/Svea/Data/PresetValues/TestValuesProvider.php @@ -3,20 +3,22 @@ namespace Svea\Checkout\Model\Svea\Data\PresetValues; use Svea\Checkout\Model\Client\DTO\Order\PresetValue; +use Svea\Checkout\Helper\Data as Helper; class TestValuesProvider implements PresetValuesProviderInterface { + /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var Helper */ - private $scopeConfig; + private $helper; /** * TestValuesProvider constructor. */ - public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) + public function __construct(Helper $helper) { - $this->scopeConfig = $scopeConfig; + $this->helper = $helper; } /** @@ -46,19 +48,17 @@ public function getPhoneNumber() : PresetValue */ public function getIsCompany() : PresetValue { - $customerType = $this->scopeConfig->getValue('svea_checkout/settings/default_customer_type'); - $customerTypes = $this->scopeConfig->getValue('svea_checkout/settings/customer_types'); - $customerTypes = explode(',', $customerTypes); + $customerType = $this->helper->getDefaultConsumerType(); + $customerTypes = $this->helper->getConsumerTypes(); $isB2B = $customerType == 'B2B'; - $isB2C = in_array('B2C', $customerTypes); $presetValue = new PresetValue(); $presetValue->setIsCompany($isB2B); $presetValue->setValue($isB2B); $isReadOnly = true; - if (count($customerTypes) > 1) { + if (is_array($customerTypes) && count($customerTypes) > 1) { $isReadOnly = false; } diff --git a/composer.json b/composer.json index c25b0f9..3fd7b26 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "sveawebpay/nwt-magento2-checkout", "description": "Svea Checkout", "type": "magento2-module", - "version": "1.2.13", + "version": "1.2.16", "autoload": { "files": [ "registration.php" diff --git a/view/adminhtml/templates/payment/checkout/info.phtml b/view/adminhtml/templates/payment/checkout/info.phtml index e4f07aa..85e9f3b 100644 --- a/view/adminhtml/templates/payment/checkout/info.phtml +++ b/view/adminhtml/templates/payment/checkout/info.phtml @@ -1,16 +1,27 @@ -
escapeHtml($block->getMethod()->getTitle()); ?>
+
escapeHtml($block->getMethod()->getTitle()); ?>
- - + + - - + + + getSveaCustomerReference()): ?> + + + +
escapeHtml(__('Svea Checkout Order ID')); ?>:escapeHtml($block->getSveaCheckoutId()); ?>escapeHtml(__('Svea Checkout Order ID')); ?>:escapeHtml($block->getSveaCheckoutId()); ?>
escapeHtml(__('Svea Payment Method')); ?>:escapeHtml($block->getSveaPaymentMethod()); ?>escapeHtml(__('Svea Payment Method')); ?>:escapeHtml($block->getSveaPaymentMethod()); ?>
escapeHtml(__('Svea Customer Payment Reference')) ?>:escapeHtml($block->getSveaCustomerReference()) ?> +
\ No newline at end of file