Skip to content

Commit

Permalink
Merge pull request #31 from paynl/feature/PLUG-926
Browse files Browse the repository at this point in the history
PLUG-926: Add option to SprayPay to use billing address.
  • Loading branch information
woutse authored Apr 29, 2022
2 parents 520f301 + 9320cae commit 1009fa4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
20 changes: 18 additions & 2 deletions Model/Paymentmethod/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Magento\Sales\Model\OrderRepository;
use Paynl\Payment\Model\Config;
use Paynl\Transaction;
use Magento\InventoryInStorePickupShippingApi\Model\Carrier\InStorePickup;

abstract class PaymentMethod extends AbstractMethod
{
Expand Down Expand Up @@ -132,7 +133,7 @@ public function showPaymentOptions()
{
return false;
}

public function hidePaymentOptions()
{
return 0;
Expand Down Expand Up @@ -168,6 +169,14 @@ public function getCustomerGroup()
return $this->_scopeConfig->getValue('payment/' . $this->_code . '/showforgroup', 'store');
}

/**
* @return bool
*/
public function useBillingAddressInstorePickup()
{
return $this->_scopeConfig->getValue('payment/' . $this->_code . '/useBillingAddressInstorePickup', 'store') == 1;
}

public function isCurrentIpValid()
{
return true;
Expand Down Expand Up @@ -393,9 +402,16 @@ protected function doStartTransaction(Order $order)
}

$arrShippingAddress = $order->getShippingAddress();
if ($arrShippingAddress) {
if (!empty($arrShippingAddress)) {
$arrShippingAddress = $arrShippingAddress->toArray();

if ($this->useBillingAddressInstorePickup() && $order->getShippingMethod() === InStorePickup::DELIVERY_METHOD) {
$arrBillingAddress = $order->getBillingAddress();
if (!empty($arrBillingAddress)) {
$arrShippingAddress = $arrBillingAddress->toArray();
}
}

$shippingAddress = [
'initials' => $arrShippingAddress['firstname'],
'lastName' => $arrShippingAddress['lastname']
Expand Down
9 changes: 9 additions & 0 deletions etc/adminhtml/paymentmethods/spraypay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@
<config_path>payment/paynl_payment_spraypay/showforgroup</config_path>
<comment><![CDATA[Show payment method only to specific customer groups.]]></comment>
</field>
<field id="forcebilling" translate="label" type="select" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Force Billing Address for Instore Pickups</label>
<depends>
<field id="active">1</field>
</depends>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/paynl_payment_spraypay/useBillingAddressInstorePickup</config_path>
<comment><![CDATA[Use the Billing address as Shipping address for instore pickups.]]></comment>
</field>
<group id="advanced" translate="label" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Advanced</label>
<field id="payment_option_id" translate="label comment" type="text" sortOrder="10" showInDefault="1"
Expand Down
6 changes: 4 additions & 2 deletions view/frontend/web/js/view/payment/method-renderer/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ define(
return '';
},
getCompany: function () {
if (typeof quote.billingAddress._latestValue.company !== 'undefined' && quote.billingAddress._latestValue.company !== null) {
return quote.billingAddress._latestValue.company;
if (quote.billingAddress.hasOwnProperty('_latestValue') && typeof quote.billingAddress._latestValue !== 'undefined' && quote.billingAddress._latestValue !== null) {
if (quote.billingAddress._latestValue.hasOwnProperty('company') && typeof quote.billingAddress._latestValue.company !== 'undefined' && quote.billingAddress._latestValue.company !== null) {
return quote.billingAddress._latestValue.company;
}
}
return '';
},
Expand Down

0 comments on commit 1009fa4

Please sign in to comment.