Skip to content

Commit

Permalink
Merge pull request #6840 from magento-tsg/2.4-develop-pr145
Browse files Browse the repository at this point in the history
[Arrows] Fixes for 2.4 (pr145) (2.4-develop)
  • Loading branch information
sivaschenko authored May 9, 2021
2 parents 2ffcb6f + 8e19d9e commit 3fffab8
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 18 deletions.
8 changes: 6 additions & 2 deletions app/code/Magento/Customer/Api/Data/CustomerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
namespace Magento\Customer\Api\Data;

/**
* Customer interface.
* Customer entity interface for API handling.
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -161,7 +162,10 @@ public function setCreatedIn($createdIn);
/**
* Get date of birth
*
* @return string|null
* @return string|null In keeping with current security and privacy best practices, be sure you are aware of any
* potential legal and security risks associated with the storage of customers’ full date of birth
* (month, day, year) along with other personal identifiers (e.g., full name) before collecting or processing
* such data.
*/
public function getDob();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@ protected function getProductInfo(\Magento\Framework\DataObject $buyRequest, $pr
if ($isStrictProcessMode && !$subProduct->getQty() && $subProduct->isSalable()) {
return __('Please specify the quantity of product(s).')->render();
}
$productsInfo[$subProduct->getId()] = $subProduct->isSalable() ? (float)$subProduct->getQty() : 0;
if (isset($buyRequest['qty']) && !isset($buyRequest['super_group'])) {
$subProductQty = (float)$subProduct->getQty() * (float)$buyRequest['qty'];
$productsInfo[$subProduct->getId()] = $subProduct->isSalable() ? $subProductQty : 0;
} else {
$productsInfo[$subProduct->getId()] = $subProduct->isSalable() ? (float)$subProduct->getQty() : 0;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Sales/Api/Data/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,10 @@ public function setCreatedAt($createdAt);
/**
* Gets the customer date-of-birth (DOB) for the order.
*
* @return string|null Customer date-of-birth (DOB).
* @return string|null In keeping with current security and privacy best practices, be sure you are aware of any
* potential legal and security risks associated with the storage of customers’ full date of birth
* (month, day, year) along with other personal identifiers (e.g., full name) before collecting or processing
* such data.
*/
public function getCustomerDob();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\Framework\Webapi\Rest\Request;
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\QuoteIdMask;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\WebapiAbstract;
Expand All @@ -29,6 +31,11 @@ class CartAddingItemsTest extends WebapiAbstract
*/
private $productResource;

/**
* @var array
*/
private $createdQuotes = [];

/**
* @inheritDoc
*/
Expand All @@ -38,6 +45,71 @@ protected function setUp(): void
$this->productResource = $this->objectManager->get(ProductResource::class);
}

protected function tearDown(): void
{
/** @var Quote $quote */
$quote = $this->objectManager->create(Quote::class);
foreach ($this->createdQuotes as $quoteId) {
$quote->load($quoteId);
$quote->delete();
}
}

/**
* Test qty for cart after adding grouped product qty specified only for goruped product.
*
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped_with_simple.php
* @magentoApiDataFixture Magento/Customer/_files/customer_one_address.php
* @return void
*/
public function testAddToCartGroupedWithParentQuantity(): void
{
$this->_markTestAsRestOnly();

// Get customer ID token
/** @var CustomerTokenServiceInterface $customerTokenService */
$customerTokenService = $this->objectManager->create(CustomerTokenServiceInterface::class);
$token = $customerTokenService->createCustomerAccessToken(
'[email protected]',
'password'
);

// Creating empty cart for registered customer.
$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/carts/mine',
'httpMethod' => Request::HTTP_METHOD_POST,
'token' => $token
]
];

$quoteId = $this->_webApiCall($serviceInfo, ['customerId' => 999]); // customerId 999 will get overridden
$this->assertGreaterThan(0, $quoteId);

/** @var CartRepositoryInterface $cartRepository */
$cartRepository = $this->objectManager->get(CartRepositoryInterface::class);
$quote = $cartRepository->get($quoteId);

$quoteItems = $quote->getItemsCollection();
foreach ($quoteItems as $item) {
$quote->removeItem($item->getId())->save();
}

$requestData = [
'cartItem' => [
'quote_id' => $quoteId,
'sku' => 'grouped',
'qty' => 7
]
];
$this->_webApiCall($this->getServiceInfoAddToCart($token), $requestData);

foreach ($quote->getAllItems() as $item) {
$this->assertEquals(7, $item->getQty());
}
$this->createdQuotes[] = $quoteId;
}

/**
* Test price for cart after adding product to.
*
Expand Down Expand Up @@ -94,10 +166,11 @@ public function testPriceForCreatingQuoteFromEmptyCart()
$paymentInfo = $this->_webApiCall($serviceInfoForGettingPaymentInfo);
$this->assertEquals($paymentInfo['totals']['grand_total'], 10);

/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
$quote->load($quoteId);
$quote->delete();
$this->createdQuotes[] = $quoteId;
// /** @var \Magento\Quote\Model\Quote $quote */
// $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
// $quote->load($quoteId);
// $quote->delete();
}

/**
Expand Down Expand Up @@ -163,6 +236,7 @@ public function testAddToCartGroupedCustomQuantity(): void
foreach ($quote->getAllItems() as $item) {
$this->assertEquals($qtyData[$item->getProductId()], $item->getQty());
}
$this->createdQuotes[] = $quoteId;
}

/**
Expand Down Expand Up @@ -210,6 +284,8 @@ public function testAddToCartGroupedCustomQuantityNotAllParamsSpecified(): void
]
];

$this->createdQuotes[] = $quoteId;

$this->expectException(\Exception::class);
$this->expectExceptionMessage('Please specify id and qty for grouped options.');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@
$registry->register('isSecureArea', true);
/** @var CustomerRepositoryInterface $customerRepo */
$customerRepo = $objectManager->get(CustomerRepositoryInterface::class);
try {
$customer = $customerRepo->get('[email protected]');
/** @var AddressRepositoryInterface $addressRepo */
$addressRepo = $objectManager->get(AddressRepositoryInterface::class);
foreach ($customer->getAddresses() as $address) {
$addressRepo->delete($address);
$customersEmails = [
'[email protected]',
'[email protected]',
];
$addressRepo = $objectManager->get(AddressRepositoryInterface::class);
foreach ($customersEmails as $customerEmail) {
try {
$customer = $customerRepo->get($customerEmail);
foreach ($customer->getAddresses() as $address) {
$addressRepo->delete($address);
}
$customerRepo->delete($customer);
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
} catch (NoSuchEntityException $exception) {
//Already deleted
}
$customerRepo->delete($customer);
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
} catch (NoSuchEntityException $exception) {
//Already deleted
}
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
5 changes: 5 additions & 0 deletions lib/web/mage/adminhtml/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ define([
} else {
if (target) {
target.show();
headElement = jQuery('.field-' + idTo).add('.field-chooser' + idTo);
headElement.show();
}

if (isAnInputOrSelect && !isInheritCheckboxChecked) {
Expand Down Expand Up @@ -580,6 +582,9 @@ define([

if (headElement.length > 0) {
headElement.hide();
} else {
headElement = jQuery('.field-' + idTo).add('.field-chooser' + idTo);
headElement.hide();
}

if (target) {
Expand Down

0 comments on commit 3fffab8

Please sign in to comment.