Skip to content

Commit

Permalink
[EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
 - merged latest code from mainline branch
  • Loading branch information
magento-engcom-team authored Dec 21, 2017
2 parents cc7bda0 + b0babda commit 4dcb3b4
Show file tree
Hide file tree
Showing 37 changed files with 24,372 additions and 23,223 deletions.
11 changes: 8 additions & 3 deletions app/code/Magento/Catalog/Block/Product/ImageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Block\Product;

use Magento\Catalog\Helper\ImageFactory as HelperFactory;
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;

class ImageBuilder
{
Expand Down Expand Up @@ -129,7 +130,11 @@ public function create()
? 'Magento_Catalog::product/image.phtml'
: 'Magento_Catalog::product/image_with_borders.phtml';

$imagesize = $helper->getResizedImageInfo();
try {
$imagesize = $helper->getResizedImageInfo();
} catch (NotLoadInfoImageException $exception) {
$imagesize = [$helper->getWidth(), $helper->getHeight()];
}

$data = [
'data' => [
Expand All @@ -140,8 +145,8 @@ public function create()
'label' => $helper->getLabel(),
'ratio' => $this->getRatio($helper),
'custom_attributes' => $this->getCustomAttributes(),
'resized_image_width' => !empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth(),
'resized_image_height' => !empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight(),
'resized_image_width' => $imagesize[0],
'resized_image_height' => $imagesize[1],
],
];

Expand Down
22 changes: 16 additions & 6 deletions app/code/Magento/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Image as MagentoImage;
Expand Down Expand Up @@ -877,17 +878,26 @@ protected function _fileExists($filename)

/**
* Return resized product image information
*
* @return array
* @throws NotLoadInfoImageException
*/
public function getResizedImageInfo()
{
if ($this->isBaseFilePlaceholder() == true) {
$image = $this->imageAsset->getSourceFile();
} else {
$image = $this->imageAsset->getPath();
try {
if ($this->isBaseFilePlaceholder() == true) {
$image = $this->imageAsset->getSourceFile();
} else {
$image = $this->imageAsset->getPath();
}

$imageProperties = getimagesize($image);

return $imageProperties;
} finally {
if (empty($imageProperties)) {
throw new NotLoadInfoImageException(__('Can\'t get information about the picture: %1', $image));
}
}
return getimagesize($image);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Product\Image;

class NotLoadInfoImageException extends \Exception
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Catalog\Api\Data\ProductRender\ImageInterfaceFactory;
use Magento\Catalog\Api\Data\ProductRenderInterface;
use Magento\Catalog\Helper\ImageFactory;
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorInterface;
use Magento\Framework\App\State;
use Magento\Framework\View\DesignInterface;
Expand Down Expand Up @@ -102,7 +103,12 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ
[$this, "emulateImageCreating"],
[$product, $imageCode, (int) $productRender->getStoreId(), $image]
);
$resizedInfo = $helper->getResizedImageInfo();

try {
$resizedInfo = $helper->getResizedImageInfo();
} catch (NotLoadInfoImageException $exception) {
$resizedInfo = [$helper->getWidth(), $helper->getHeight()];
}

$image->setCode($imageCode);
$image->setHeight($helper->getHeight());
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Checkout/Model/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

/**
* Shopping cart model
*
* @api
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @deprecated 100.1.0
* @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead
*/
class Cart extends DataObject implements CartInterface
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/Model/Cart/CartInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @api
* @author Magento Core Team <[email protected]>
* @deprecated 100.1.0
* @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead
*/
interface CartInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Config\App\Config\Source;

use Magento\Framework\App\Config\ConfigSourceInterface;
Expand Down Expand Up @@ -88,12 +89,12 @@ private function loadConfig()
}
}

foreach ($config as $scope => &$item) {
foreach ($config as $scope => $item) {
if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
$item = $this->converter->convert($item);
$config[$scope] = $this->converter->convert($item);
} else {
foreach ($item as &$scopeItems) {
$scopeItems = $this->converter->convert($scopeItems);
foreach ($item as $scopeCode => $scopeItems) {
$config[$scope][$scopeCode] = $this->converter->convert($scopeItems);
}
}
}
Expand Down
17 changes: 12 additions & 5 deletions app/code/Magento/Webapi/Controller/Rest/InputParamsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

namespace Magento\Webapi\Controller\Rest;

use Magento\Framework\Webapi\ServiceInputProcessor;
use Magento\Framework\Webapi\Rest\Request as RestRequest;
use Magento\Webapi\Controller\Rest\Router;
use Magento\Framework\Webapi\ServiceInputProcessor;
use Magento\Webapi\Controller\Rest\Router\Route;
use Magento\Webapi\Model\UrlDecoder;

/**
* This class is responsible for retrieving resolved input data
Expand Down Expand Up @@ -47,26 +47,32 @@ class InputParamsResolver
private $requestValidator;

/**
* Initialize dependencies
*
* @var UrlDecoder
*/
private $urlDecoder;

/**
* @param RestRequest $request
* @param ParamsOverrider $paramsOverrider
* @param ServiceInputProcessor $serviceInputProcessor
* @param Router $router
* @param RequestValidator $requestValidator
* @param UrlDecoder $urlDecoder
*/
public function __construct(
RestRequest $request,
ParamsOverrider $paramsOverrider,
ServiceInputProcessor $serviceInputProcessor,
Router $router,
RequestValidator $requestValidator
RequestValidator $requestValidator,
UrlDecoder $urlDecoder = null
) {
$this->request = $request;
$this->paramsOverrider = $paramsOverrider;
$this->serviceInputProcessor = $serviceInputProcessor;
$this->router = $router;
$this->requestValidator = $requestValidator;
$this->urlDecoder = $urlDecoder ?: \Magento\Framework\App\ObjectManager::getInstance()->get(UrlDecoder::class);
}

/**
Expand Down Expand Up @@ -97,6 +103,7 @@ public function resolve()
$inputData = $this->request->getRequestData();
}

$inputData = $this->urlDecoder->decodeParams($inputData);
$inputData = $this->paramsOverrider->override($inputData, $route->getParameters());
$inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData);
return $inputParams;
Expand Down
14 changes: 11 additions & 3 deletions app/code/Magento/Webapi/Controller/Soap/Request/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Magento\Webapi\Model\Soap\Config as SoapConfig;
use Magento\Framework\Reflection\MethodsMap;
use Magento\Webapi\Model\ServiceMetadata;
use Magento\Webapi\Model\UrlDecoder;

/**
* Handler of requests to SOAP server.
Expand Down Expand Up @@ -70,8 +71,11 @@ class Handler
protected $methodsMapProcessor;

/**
* Initialize dependencies.
*
* @var UrlDecoder
*/
private $urlDecoder;

/**
* @param SoapRequest $request
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param SoapConfig $apiConfig
Expand All @@ -80,6 +84,7 @@ class Handler
* @param ServiceInputProcessor $serviceInputProcessor
* @param DataObjectProcessor $dataObjectProcessor
* @param MethodsMap $methodsMapProcessor
* @param UrlDecoder $urlDecoder
*/
public function __construct(
SoapRequest $request,
Expand All @@ -89,7 +94,8 @@ public function __construct(
SimpleDataObjectConverter $dataObjectConverter,
ServiceInputProcessor $serviceInputProcessor,
DataObjectProcessor $dataObjectProcessor,
MethodsMap $methodsMapProcessor
MethodsMap $methodsMapProcessor,
UrlDecoder $urlDecoder = null
) {
$this->_request = $request;
$this->_objectManager = $objectManager;
Expand All @@ -99,6 +105,7 @@ public function __construct(
$this->serviceInputProcessor = $serviceInputProcessor;
$this->_dataObjectProcessor = $dataObjectProcessor;
$this->methodsMapProcessor = $methodsMapProcessor;
$this->urlDecoder = $urlDecoder ?: \Magento\Framework\App\ObjectManager::getInstance()->get(UrlDecoder::class);
}

/**
Expand Down Expand Up @@ -150,6 +157,7 @@ protected function _prepareRequestData($serviceClass, $serviceMethod, $arguments
/** SoapServer wraps parameters into array. Thus this wrapping should be removed to get access to parameters. */
$arguments = reset($arguments);
$arguments = $this->_dataObjectConverter->convertStdObjectToArray($arguments, true);
$arguments = $this->urlDecoder->decodeParams($arguments);
return $this->serviceInputProcessor->process($serviceClass, $serviceMethod, $arguments);
}

Expand Down
35 changes: 35 additions & 0 deletions app/code/Magento/Webapi/Model/UrlDecoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Webapi\Model;

/**
* Url decoder.
*/
class UrlDecoder
{
/**
* Decode request params.
*
* @param array $params
*
* @return array
*/
public function decodeParams(array $params)
{
foreach ($params as &$param) {
if (is_array($param)) {
$param = $this->decodeParams($param);
} else {
if ($param !== null && is_string($param)) {
$param = rawurldecode($param);
}
}
}

return $params;
}
}
11 changes: 8 additions & 3 deletions app/code/Magento/Wishlist/CustomerData/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Wishlist\CustomerData;

use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Customer\CustomerData\SectionSourceInterface;

/**
Expand Down Expand Up @@ -154,15 +155,19 @@ protected function getImageData($product)
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';

$imagesize = $helper->getResizedImageInfo();
try {
$imagesize = $helper->getResizedImageInfo();
} catch (NotLoadInfoImageException $exception) {
$imagesize = [$helper->getWidth(), $helper->getHeight()];
}

$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
: $imagesize[0];

$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
: $imagesize[1];

return [
'template' => $template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
ProductInterface::TYPE_ID => 'simple',
ProductInterface::PRICE => 10
],
[
ProductInterface::SKU => [
'rest' => 'sku%252fwith%252fslashes',
'soap' => 'sku%2fwith%2fslashes'
],
ProductInterface::NAME => 'Simple Product with Sku with Slashes',
ProductInterface::TYPE_ID => 'simple',
ProductInterface::PRICE => 10
],
];

/**
Expand Down Expand Up @@ -135,6 +144,20 @@ public function productCreationProvider()
];
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_sku_with_slash.php
*/
public function testGetBySkuWithSlash()
{
$productData = $this->productData[2];
$response = $this->getProduct($productData[ProductInterface::SKU][TESTS_WEB_API_ADAPTER]);
$productData[ProductInterface::SKU] = rawurldecode($productData[ProductInterface::SKU]['soap']);
foreach ([ProductInterface::SKU, ProductInterface::NAME, ProductInterface::PRICE] as $key) {
$this->assertEquals($productData[$key], $response[$key]);
}
$this->assertEquals([1], $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]["website_ids"]);
}

/**
* Test removing association between product and website 1
* @magentoApiDataFixture Magento/Catalog/_files/product_with_two_websites.php
Expand Down
Loading

0 comments on commit 4dcb3b4

Please sign in to comment.