Skip to content

Commit

Permalink
Merge pull request #21 from vippsas/publication-1.0.14
Browse files Browse the repository at this point in the history
VIPPS-175: Publication v.1.0.14
  • Loading branch information
voleye authored Dec 12, 2018
2 parents 06c171e + 82c1dba commit 3476a97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
1 change: 1 addition & 0 deletions Controller/Payment/ShippingDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function execute()
$result->setHttpResponseCode(ZendResponse::STATUS_CODE_200);
$result->setData($responseData);
} catch (LocalizedException $e) {
$this->logger->critical($e->getMessage());
$result->setHttpResponseCode(ZendResponse::STATUS_CODE_500);
$result->setData([
'status' => ZendResponse::STATUS_CODE_500,
Expand Down
37 changes: 9 additions & 28 deletions Model/Quote/AddressUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use \Magento\Braintree\Model\Paypal\Helper\AbstractHelper;

use Magento\Quote\{
Api\CartRepositoryInterface, Model\Quote, Model\Quote\Address
Model\Quote, Model\Quote\Address
};

use Vipps\Payment\Gateway\Transaction\ShippingDetails;
Expand All @@ -30,48 +30,27 @@
*/
class AddressUpdater extends AbstractHelper
{
/**
* @var CartRepositoryInterface
*/
private $cartRepository;

/**
* AddressUpdater constructor.
* @param CartRepositoryInterface $cartRepository
*/
public function __construct(CartRepositoryInterface $cartRepository)
{
$this->cartRepository = $cartRepository;
}

/**
* Update quote addresses from source address.
*
* @param Quote $quote
* @param Address $sourceAddress
* @throws \Exception
*/
public function fromSourceAddress(Quote $quote, Address $sourceAddress)
{
$quote->setMayEditShippingAddress(false);

$this->updateQuoteAddresses($quote, $sourceAddress);
$this->disabledQuoteAddressValidation($quote);

/**
* Unset shipping assignment to prevent from saving / applying outdated data
* @see \Magento\Quote\Model\QuoteRepository\SaveHandler::processShippingAssignment
*/
if ($quote->getExtensionAttributes()) {
$quote->getExtensionAttributes()->setShippingAssignments(null);
}
$this->cartRepository->save($quote);
$this->updateQuoteAddresses($quote, $sourceAddress);
}

/**
* Update quote addresses from source address.
*
* @param Quote $quote
* @param Address $sourceAddress
* @throws \Exception
*/
private function updateQuoteAddresses(Quote $quote, Address $sourceAddress)
{
Expand All @@ -81,15 +60,16 @@ private function updateQuoteAddresses(Quote $quote, Address $sourceAddress)
}

$billingAddress = $quote->getBillingAddress();
$this->updateAddress($billingAddress, $sourceAddress);
$billingAddress->setSameAsBilling(false);
$this->updateAddress($billingAddress, $sourceAddress);
}

/**
* Update destination address from source.
*
* @param Address $destAddress
* @param Address $sourceAddress
* @throws \Exception
*/
private function updateAddress(Address $destAddress, Address $sourceAddress)
{
Expand All @@ -100,6 +80,7 @@ private function updateAddress(Address $destAddress, Address $sourceAddress)
->setPostcode($sourceAddress->getPostcode())
->setSaveInAddressBook(false)
->setSameAsBilling(true)
->setCustomerAddressId(null);
->setCustomerAddressId(null)
->save();
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "magento2-module",
"description": "Vipps Payment Method",
"license": "proprietary",
"version": "1.0.13",
"version": "1.0.14",
"require": {
"magento/framework": "101.0.*",
"magento/module-sales": "101.0.*",
Expand Down

0 comments on commit 3476a97

Please sign in to comment.