Skip to content

Commit 730dbce

Browse files
authored
Merge pull request #4636 from magento-honey-badgers/hb-combined-pr
[honey] MC-19115: Admin Analytics tracking should be enabled by default
2 parents 981ec8e + f71a4bd commit 730dbce

File tree

5 files changed

+91
-6
lines changed

5 files changed

+91
-6
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
9+
<default>
10+
<admin>
11+
<usage>
12+
<enabled>
13+
1
14+
</enabled>
15+
</usage>
16+
</admin>
17+
</default>
18+
</config>

app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ public function execute(Quote $cart, int $cartItemId, float $quantity, array $cu
9393
)
9494
);
9595
}
96-
97-
$this->quoteRepository->save($cart);
9896
}
9997

10098
/**
@@ -105,7 +103,7 @@ public function execute(Quote $cart, int $cartItemId, float $quantity, array $cu
105103
* @param float $quantity
106104
* @throws GraphQlNoSuchEntityException
107105
* @throws NoSuchEntityException
108-
* @throws GraphQlNoSuchEntityException
106+
* @throws GraphQlInputException
109107
*/
110108
private function updateItemQuantity(int $itemId, Quote $cart, float $quantity)
111109
{

app/code/Magento/QuoteGraphQl/Model/Resolver/UpdateCartItems.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\GraphQl\Query\ResolverInterface;
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1717
use Magento\Quote\Api\CartItemRepositoryInterface;
18+
use Magento\Quote\Api\CartRepositoryInterface;
1819
use Magento\Quote\Model\Quote;
1920
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
2021
use Magento\QuoteGraphQl\Model\Cart\UpdateCartItem;
@@ -39,19 +40,27 @@ class UpdateCartItems implements ResolverInterface
3940
*/
4041
private $cartItemRepository;
4142

43+
/**
44+
* @var CartRepositoryInterface
45+
*/
46+
private $cartRepository;
47+
4248
/**
4349
* @param GetCartForUser $getCartForUser
4450
* @param CartItemRepositoryInterface $cartItemRepository
4551
* @param UpdateCartItem $updateCartItem
52+
* @param CartRepositoryInterface $cartRepository
4653
*/
4754
public function __construct(
4855
GetCartForUser $getCartForUser,
4956
CartItemRepositoryInterface $cartItemRepository,
50-
UpdateCartItem $updateCartItem
57+
UpdateCartItem $updateCartItem,
58+
CartRepositoryInterface $cartRepository
5159
) {
5260
$this->getCartForUser = $getCartForUser;
5361
$this->cartItemRepository = $cartItemRepository;
5462
$this->updateCartItem = $updateCartItem;
63+
$this->cartRepository = $cartRepository;
5564
}
5665

5766
/**
@@ -76,6 +85,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7685

7786
try {
7887
$this->processCartItems($cart, $cartItems);
88+
$this->cartRepository->save($cart);
7989
} catch (NoSuchEntityException $e) {
8090
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
8191
} catch (LocalizedException $e) {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/UpdateCartItemsTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ public function testUpdateCartItemQuantity()
7070

7171
$this->assertEquals($itemId, $item['id']);
7272
$this->assertEquals($quantity, $item['quantity']);
73+
74+
//Check that update is correctly reflected in cart
75+
$cartQuery = $this->getCartQuery($maskedQuoteId);
76+
$response = $this->graphQlQuery($cartQuery);
77+
78+
$this->assertArrayHasKey('cart', $response);
79+
80+
$responseCart = $response['cart'];
81+
$item = current($responseCart['items']);
82+
83+
$this->assertEquals($quantity, $item['quantity']);
7384
}
7485

7586
/**
@@ -91,6 +102,15 @@ public function testRemoveCartItemIfQuantityIsZero()
91102

92103
$responseCart = $response['updateCartItems']['cart'];
93104
$this->assertCount(0, $responseCart['items']);
105+
106+
//Check that update is correctly reflected in cart
107+
$cartQuery = $this->getCartQuery($maskedQuoteId);
108+
$response = $this->graphQlQuery($cartQuery);
109+
110+
$this->assertArrayHasKey('cart', $response);
111+
112+
$responseCart = $response['cart'];
113+
$this->assertCount(0, $responseCart['items']);
94114
}
95115

96116
/**
@@ -268,6 +288,26 @@ private function getQuery(string $maskedQuoteId, int $itemId, float $quantity):
268288
}
269289
}
270290
}
291+
QUERY;
292+
}
293+
294+
/**
295+
* @param string $maskedQuoteId
296+
* @return string
297+
*/
298+
private function getCartQuery(string $maskedQuoteId)
299+
{
300+
return <<<QUERY
301+
query {
302+
cart(cart_id: "{$maskedQuoteId}"){
303+
items{
304+
product{
305+
name
306+
}
307+
quantity
308+
}
309+
}
310+
}
271311
QUERY;
272312
}
273313
}

lib/internal/Magento/Framework/App/ProductMetadata.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
/**
1616
* Class ProductMetadata
17+
*
1718
* @package Magento\Framework\App
1819
*/
1920
class ProductMetadata implements ProductMetadataInterface
@@ -28,6 +29,11 @@ class ProductMetadata implements ProductMetadataInterface
2829
*/
2930
const PRODUCT_NAME = 'Magento';
3031

32+
/**
33+
* Magento version cache key
34+
*/
35+
const VERSION_CACHE_KEY = 'mage-version';
36+
3137
/**
3238
* Product version
3339
*
@@ -47,11 +53,21 @@ class ProductMetadata implements ProductMetadataInterface
4753
private $composerInformation;
4854

4955
/**
56+
* @var CacheInterface
57+
*/
58+
private $cache;
59+
60+
/**
61+
* ProductMetadata constructor.
5062
* @param ComposerJsonFinder $composerJsonFinder
63+
* @param \Magento\Framework\App\CacheInterface $cache
5164
*/
52-
public function __construct(ComposerJsonFinder $composerJsonFinder)
53-
{
65+
public function __construct(
66+
ComposerJsonFinder $composerJsonFinder,
67+
CacheInterface $cache = null
68+
) {
5469
$this->composerJsonFinder = $composerJsonFinder;
70+
$this->cache = $cache ?? ObjectManager::getInstance()->get(CacheInterface::class);
5571
}
5672

5773
/**
@@ -61,13 +77,16 @@ public function __construct(ComposerJsonFinder $composerJsonFinder)
6177
*/
6278
public function getVersion()
6379
{
80+
$versionFromCache = $this->cache->load(self::VERSION_CACHE_KEY);
81+
$this->version = $this->version ?: $versionFromCache;
6482
if (!$this->version) {
6583
if (!($this->version = $this->getSystemPackageVersion())) {
6684
if ($this->getComposerInformation()->isMagentoRoot()) {
6785
$this->version = $this->getComposerInformation()->getRootPackage()->getPrettyVersion();
6886
} else {
6987
$this->version = 'UNKNOWN';
7088
}
89+
$this->cache->save($this->version, self::VERSION_CACHE_KEY, [Config::CACHE_TAG]);
7190
}
7291
}
7392
return $this->version;

0 commit comments

Comments
 (0)