Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #26083 - problem with unsAdditionalInformation in \Magento\Payment\Model\Info #26084

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/code/Magento/Payment/Model/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Info extends AbstractExtensibleModel implements InfoInterface
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
Expand Down Expand Up @@ -188,6 +188,7 @@ public function getAdditionalInformation($key = null)
*/
public function unsAdditionalInformation($key = null)
{
$this->_initAdditionalInformation();
if ($key && isset($this->_additionalInformation[$key])) {
unset($this->_additionalInformation[$key]);
return $this->setData('additional_information', $this->_additionalInformation);
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Sales/Model/Order/Payment/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public function getAdditionalInformation($key = null)
*/
public function unsAdditionalInformation($key = null)
{
$this->initAdditionalInformation();
if ($key && isset($this->additionalInformation[$key])) {
unset($this->additionalInformation[$key]);
return $this->setData('additional_information', $this->additionalInformation);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Payment\Model;

use Magento\Sales\Model\Order;
use Magento\Quote\Model\Quote;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;

/**
* @magentoAppArea adminhtml
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PaymentInfoTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
protected $_objectManager;

/**
* @var Order
*/
protected $_order;

/** @var Quote */
protected $_quote;

protected function setUp()
{
$this->_objectManager = Bootstrap::getObjectManager();
$this->_order = $this->_objectManager->create(
Order::class
);
$this->_quote = $this->_objectManager->create(
Quote::class
);
}

/**
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Payment/_files/payment_info.php
*/
public function testUnsetPaymentInformation()
{
$order = $this->_order->loadByIncrementId('100000001');
/** @var \Magento\Sales\Model\Order\Payment $paymentOrder */
$paymentOrder = $order->getPayment();
$paymentOrder->unsAdditionalInformation('testing');

$quote = $this->_quote->load('reserved_order_id', 'reserved_order_id');
/** @var \Magento\Quote\Model\Quote\Payment $paymentQuote */
$paymentQuote = $quote->getPayment();
$paymentQuote->unsAdditionalInformation('testing');

$this->assertFalse($paymentOrder->hasAdditionalInformation('testing'));
$this->assertFalse($paymentQuote->hasAdditionalInformation('testing'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Quote\Api\CartRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Sales\Model\Order\Address;
use Magento\Sales\Model\Order\Payment;
use Magento\Paypal\Model\Config;
use Magento\Sales\Model\Order;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Payment as PaymentQuote;

/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = Bootstrap::getObjectManager();

$addressData = [
'firstname' => 'guest',
'lastname' => 'guest',
'email' => 'customer@example.com',
'street' => 'street',
'city' => 'Los Angeles',
'region' => 'CA',
'postcode' => '1',
'country_id' => 'US',
'telephone' => '1'
];
$billingAddress = $objectManager->create(
Address::class,
['data' => $addressData]
);
$billingAddress->setAddressType('billing');
$shippingAddress = clone $billingAddress;
$shippingAddress->setId(null)->setAddressType('shipping');

/** @var Payment $paymentOrder */
$paymentOrder = $objectManager->create(
Payment::class
);

$paymentOrder->setMethod(Config::METHOD_WPP_EXPRESS);
$paymentOrder->setAdditionalInformation('testing', 'testing additional data');

$amount = 100;

/** @var Order $order */
$order = $objectManager->create(Order::class);
$order->setCustomerEmail('co@co.co')
->setIncrementId('100000001')
->setSubtotal($amount)
->setBaseSubtotal($amount)
->setBaseGrandTotal($amount)
->setGrandTotal($amount)
->setBaseCurrencyCode('USD')
->setCustomerIsGuest(true)
->setStoreId(1)
->setEmailSent(true)
->setBillingAddress($billingAddress)
->setShippingAddress($shippingAddress)
->setPayment($paymentOrder);
$order->save();



/** @var Quote $quote */
$quote = $objectManager->create(Quote::class);
$quote->setStoreId(1)
->setIsActive(true)
->setIsMultiShipping(false)
->setReservedOrderId('reserved_order_id');

$quote->getPayment()
->setMethod(Config::METHOD_WPP_EXPRESS)
->setAdditionalInformation('testing', 'testing additional data');

$quote->collectTotals();


/** @var CartRepositoryInterface $repository */
$repository = $objectManager->get(CartRepositoryInterface::class);
$repository->save($quote);