Skip to content

Commit eb86288

Browse files
authored
Merge pull request #2163 from magento-pangolin/MSI-1616
Msi 1616
2 parents 9ba6c60 + beac68e commit eb86288

File tree

62 files changed

+1395
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1395
-36
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Currency.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function render(\Magento\Framework\DataObject $row)
8282
{
8383
if ($data = (string)$this->_getValue($row)) {
8484
$currency_code = $this->_getCurrencyCode($row);
85-
$data = floatval($data) * $this->_getRate($row);
85+
$data = (float)$data * $this->_getRate($row);
8686
$sign = (bool)(int)$this->getColumn()->getShowNumberSign() && $data > 0 ? '+' : '';
8787
$data = sprintf("%f", $data);
8888
$data = $this->_localeCurrency->getCurrency($currency_code)->toCurrency($data);
@@ -118,10 +118,10 @@ protected function _getCurrencyCode($row)
118118
protected function _getRate($row)
119119
{
120120
if ($rate = $this->getColumn()->getRate()) {
121-
return floatval($rate);
121+
return (float)$rate;
122122
}
123123
if ($rate = $row->getData($this->getColumn()->getRateField())) {
124-
return floatval($rate);
124+
return (float)$rate;
125125
}
126126
return $this->_defaultBaseCurrency->getRate($this->_getCurrencyCode($row));
127127
}

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Price.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function render(\Magento\Framework\DataObject $row)
6060
return $data;
6161
}
6262

63-
$data = floatval($data) * $this->_getRate($row);
63+
$data = (float)$data * $this->_getRate($row);
6464
$data = sprintf("%f", $data);
6565
$data = $this->_localeCurrency->getCurrency($currencyCode)->toCurrency($data);
6666
return $data;
@@ -94,10 +94,10 @@ protected function _getCurrencyCode($row)
9494
protected function _getRate($row)
9595
{
9696
if ($rate = $this->getColumn()->getRate()) {
97-
return floatval($rate);
97+
return (float)$rate;
9898
}
9999
if ($rate = $row->getData($this->getColumn()->getRateField())) {
100-
return floatval($rate);
100+
return (float)$rate;
101101
}
102102
return 1;
103103
}

app/code/Magento/Bundle/Pricing/Price/BundleSelectionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function create(
5454
) {
5555
$arguments['bundleProduct'] = $bundleProduct;
5656
$arguments['saleableItem'] = $selection;
57-
$arguments['quantity'] = $quantity ? floatval($quantity) : 1.;
57+
$arguments['quantity'] = $quantity ? (float)$quantity : 1.;
5858

5959
return $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
6060
}

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ public function getForceChildItemQtyChanges($product)
935935
*/
936936
public function prepareQuoteItemQty($qty, $product)
937937
{
938-
return floatval($qty);
938+
return (float)$qty;
939939
}
940940

941941
/**

app/code/Magento/Catalog/Model/ProductLink/Repository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Api\Data\ProductLinkExtensionFactory;
1111
use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks as LinksInitializer;
1212
use Magento\Catalog\Model\Product\LinkTypeProvider;
13+
use Magento\Framework\Api\SimpleDataObjectConverter;
1314
use Magento\Framework\Exception\CouldNotSaveException;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516
use Magento\Framework\EntityManager\MetadataPool;
@@ -170,7 +171,7 @@ public function getList(\Magento\Catalog\Api\Data\ProductInterface $product)
170171
foreach ($item['custom_attributes'] as $option) {
171172
$name = $option['attribute_code'];
172173
$value = $option['value'];
173-
$setterName = 'set'.ucfirst($name);
174+
$setterName = 'set' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($name);
174175
// Check if setter exists
175176
if (method_exists($productLinkExtension, $setterName)) {
176177
call_user_func([$productLinkExtension, $setterName], $value);

app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Price.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function getCount($range)
112112
/**
113113
* Check and set correct variable values to prevent SQL-injections
114114
*/
115-
$range = floatval($range);
115+
$range = (float)$range;
116116
if ($range == 0) {
117117
$range = 1;
118118
}

app/code/Magento/Catalog/Pricing/Price/RegularPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getValue()
2929
if ($this->value === null) {
3030
$price = $this->product->getPrice();
3131
$priceInCurrentCurrency = $this->priceCurrency->convertAndRound($price);
32-
$this->value = $priceInCurrentCurrency ? floatval($priceInCurrentCurrency) : 0;
32+
$this->value = $priceInCurrentCurrency ? (float)$priceInCurrentCurrency : 0;
3333
}
3434
return $this->value;
3535
}

app/code/Magento/Catalog/Pricing/Price/TierPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct(
8080
GroupManagementInterface $groupManagement,
8181
CustomerGroupRetrieverInterface $customerGroupRetriever = null
8282
) {
83-
$quantity = floatval($quantity) ? $quantity : 1;
83+
$quantity = (float)$quantity ? $quantity : 1;
8484
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
8585
$this->customerSession = $customerSession;
8686
$this->groupManagement = $groupManagement;

app/code/Magento/Catalog/Test/Mftf/Test/AdminApplyTierPriceToProductTest.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9-
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
109
<test name="AdminApplyTierPriceToProductTest">
1110
<annotations>
1211
<features value="Catalog"/>
@@ -16,6 +15,7 @@
1615
<severity value="CRITICAL"/>
1716
<testCaseId value="MAGETWO-68921"/>
1817
<group value="product"/>
18+
<group value="alex"/>
1919
</annotations>
2020
<before>
2121
<createData entity="Simple_US_Customer" stepKey="createSimpleUSCustomer">
@@ -236,9 +236,10 @@
236236
<scrollToTopOfPage stepKey="scrollToTopOfPage5"/>
237237
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton5"/>
238238
<waitForElement selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceDeleteButton}}" stepKey="waitForcustomerGroupPriceDeleteButton"/>
239-
<click selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceDeleteButton}}" stepKey="deleteFirstRowOfCustomerGroupPrice"/>
240-
<click selector="{{AdminProductFormAdvancedPricingSection.customerGroupPriceDeleteButton}}" stepKey="deleteSecondRowOfCustomerGroupPrice"/>
241-
<click selector="{{AdminProductFormAdvancedPricingSection.doneButton}}" stepKey="clickDoneButton5"/>
239+
<scrollTo selector="(//*[contains(@class, 'product_form_product_form_advanced_pricing_modal')]//tr//button[@data-action='remove_row'])[1]" x="30" y="0" stepKey="scrollToDeleteFirstRowOfCustomerGroupPrice" />
240+
<click selector="(//tr//button[@data-action='remove_row'])[1]" userInput=".product_form_product_form_advanced_pricing_modal" stepKey="deleteFirstRowOfCustomerGroupPrice"/>
241+
<click selector="(//tr//button[@data-action='remove_row'])[2]" userInput=".product_form_product_form_advanced_pricing_modal" stepKey="deleteSecondRowOfCustomerGroupPrice"/>
242+
<click selector="{{AdminProductFormAdvancedPricingSection.doneButton}}" userInput=".product_form_product_form_advanced_pricing_modal" stepKey="clickDoneButton5"/>
242243
<actionGroup ref="saveProductForm" stepKey="saveProduct5"/>
243244
<scrollToTopOfPage stepKey="scrollToTopOfPage6"/>
244245
<click selector="{{AdminProductFormSection.advancedPricingLink}}" stepKey="clickOnAdvancedPricingButton6"/>

app/code/Magento/Catalog/Test/Unit/Model/Layer/Filter/DataProvider/PriceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function testGetMaxPrice()
152152
$this->productCollection->expects($this->once())
153153
->method('getMaxPrice')
154154
->will($this->returnValue($maxPrice));
155-
$this->assertSame(floatval($maxPrice), $this->target->getMaxPrice());
155+
$this->assertSame((float)$maxPrice, $this->target->getMaxPrice());
156156
}
157157

158158
/**

app/code/Magento/CatalogInventory/Model/Stock/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function getStockStatusChangedAuto()
206206
*/
207207
public function getQty()
208208
{
209-
return null === $this->_getData(static::QTY) ? null : floatval($this->_getData(static::QTY));
209+
return null === $this->_getData(static::QTY) ? null : (float)$this->_getData(static::QTY);
210210
}
211211

212212
/**
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventoryGraphQl\Model\Resolver;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\CatalogInventory\Api\StockRegistryInterface;
12+
use Magento\CatalogInventory\Model\Configuration;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Framework\GraphQl\Config\Element\Field;
16+
use Magento\Framework\GraphQl\Query\Resolver\Value;
17+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
18+
use Magento\Framework\GraphQl\Query\ResolverInterface;
19+
use Magento\Store\Model\ScopeInterface;
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
class OnlyXLeftInStockResolver implements ResolverInterface
25+
{
26+
/**
27+
* @var ValueFactory
28+
*/
29+
private $valueFactory;
30+
31+
/**
32+
* @var ScopeConfigInterface
33+
*/
34+
private $scopeConfig;
35+
36+
/**
37+
* @var StockRegistryInterface
38+
*/
39+
private $stockRegistry;
40+
41+
/**
42+
* @param ValueFactory $valueFactory
43+
* @param ScopeConfigInterface $scopeConfig
44+
* @param StockRegistryInterface $stockRegistry
45+
*/
46+
public function __construct(
47+
ValueFactory $valueFactory,
48+
ScopeConfigInterface $scopeConfig,
49+
StockRegistryInterface $stockRegistry
50+
) {
51+
$this->valueFactory = $valueFactory;
52+
$this->scopeConfig = $scopeConfig;
53+
$this->stockRegistry = $stockRegistry;
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
*/
59+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): Value
60+
{
61+
if (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) {
62+
$result = function () {
63+
return null;
64+
};
65+
66+
return $this->valueFactory->create($result);
67+
}
68+
69+
/* @var $product ProductInterface */
70+
$product = $value['model'];
71+
$onlyXLeftQty = $this->getOnlyXLeftQty($product);
72+
73+
$result = function () use ($onlyXLeftQty) {
74+
return $onlyXLeftQty;
75+
};
76+
77+
return $this->valueFactory->create($result);
78+
}
79+
80+
/**
81+
* Get product qty left when "Catalog > Inventory > Stock Options > Only X left Threshold" is greater than 0
82+
*
83+
* @param ProductInterface $product
84+
*
85+
* @return null|float
86+
*/
87+
private function getOnlyXLeftQty(ProductInterface $product): ?float
88+
{
89+
$thresholdQty = (float)$this->scopeConfig->getValue(
90+
Configuration::XML_PATH_STOCK_THRESHOLD_QTY,
91+
ScopeInterface::SCOPE_STORE
92+
);
93+
if ($thresholdQty === 0) {
94+
return null;
95+
}
96+
97+
$stockItem = $this->stockRegistry->getStockItem($product->getId());
98+
99+
$stockCurrentQty = $this->stockRegistry->getStockStatus(
100+
$product->getId(),
101+
$product->getStore()->getWebsiteId()
102+
)->getQty();
103+
104+
$stockLeft = $stockCurrentQty - $stockItem->getMinQty();
105+
106+
$thresholdQty = (float)$this->scopeConfig->getValue(
107+
Configuration::XML_PATH_STOCK_THRESHOLD_QTY,
108+
ScopeInterface::SCOPE_STORE
109+
);
110+
111+
if ($stockCurrentQty > 0 && $stockLeft <= $thresholdQty) {
112+
return $stockLeft;
113+
}
114+
115+
return null;
116+
}
117+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventoryGraphQl\Model\Resolver;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\CatalogInventory\Api\Data\StockStatusInterface;
12+
use Magento\CatalogInventory\Api\StockStatusRepositoryInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\Framework\GraphQl\Config\Element\Field;
15+
use Magento\Framework\GraphQl\Query\Resolver\Value;
16+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
17+
use Magento\Framework\GraphQl\Query\ResolverInterface;
18+
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
class StockStatusProvider implements ResolverInterface
23+
{
24+
/**
25+
* @var ValueFactory
26+
*/
27+
private $valueFactory;
28+
29+
/**
30+
* @var StockStatusRepositoryInterface
31+
*/
32+
private $stockStatusRepository;
33+
34+
/**
35+
* @param ValueFactory $valueFactory
36+
* @param StockStatusRepositoryInterface $stockStatusRepository
37+
*/
38+
public function __construct(ValueFactory $valueFactory, StockStatusRepositoryInterface $stockStatusRepository)
39+
{
40+
$this->valueFactory = $valueFactory;
41+
$this->stockStatusRepository = $stockStatusRepository;
42+
}
43+
44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): Value
48+
{
49+
if (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) {
50+
$result = function () {
51+
return null;
52+
};
53+
54+
return $this->valueFactory->create($result);
55+
}
56+
57+
/* @var $product ProductInterface */
58+
$product = $value['model'];
59+
60+
$stockStatus = $this->stockStatusRepository->get($product->getId());
61+
$productStockStatus = (int)$stockStatus->getStockStatus();
62+
63+
$result = function () use ($productStockStatus) {
64+
return $productStockStatus === StockStatusInterface::STATUS_IN_STOCK ? 'IN_STOCK' : 'OUT_OF_STOCK';
65+
};
66+
67+
return $this->valueFactory->create($result);
68+
}
69+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CatalogInventoryGraphQl
2+
3+
**CatalogInventoryGraphQl** provides type information for the GraphQl module
4+
to generate inventory stock fields for product information endpoints.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "magento/module-catalog-inventory-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.1.3||~7.2.0",
7+
"magento/framework": "*",
8+
"magento/module-store": "*",
9+
"magento/module-catalog": "*",
10+
"magento/module-catalog-inventory": "*"
11+
},
12+
"license": [
13+
"OSL-3.0",
14+
"AFL-3.0"
15+
],
16+
"autoload": {
17+
"files": [
18+
"registration.php"
19+
],
20+
"psr-4": {
21+
"Magento\\CatalogInventoryGraphQl\\": ""
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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:framework:Module/etc/module.xsd">
9+
<module name="Magento_CatalogInventoryGraphQl">
10+
<sequence>
11+
<module name="Magento_Store"/>
12+
<module name="Magento_Catalog"/>
13+
<module name="Magento_CatalogInventory"/>
14+
</sequence>
15+
</module>
16+
</config>

0 commit comments

Comments
 (0)