Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.3-develop' into graphQl-44-pro…
Browse files Browse the repository at this point in the history
…duct-textarea-field-format
  • Loading branch information
Valeriy Nayda committed Nov 9, 2018
2 parents 25fd467 + 6481cec commit 607729e
Show file tree
Hide file tree
Showing 84 changed files with 1,238 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public function testGetAllWebsitesValue()
$this->webSiteModel->expects($this->once())->method('getBaseCurrency')->willReturn($currency);

$expectedResult = AdvancedPricing::VALUE_ALL_WEBSITES . ' [' . $currencyCode . ']';
$this->websiteString = $this->getMockBuilder(
$websiteString = $this->getMockBuilder(
\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing\Validator\Website::class
)
->setMethods(['_clearMessages', '_addMessages'])
->setConstructorArgs([$this->storeResolver, $this->webSiteModel])
->getMock();
$result = $this->websiteString->getAllWebsitesValue();
$result = $websiteString->getAllWebsitesValue();

$this->assertEquals($expectedResult, $result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-63898"/>
<group value="analytics"/>
<skip>
<issueId value="MAGETWO-96223"/>
</skip>
</annotations>

<actionGroup ref="LoginActionGroup" stepKey="loginAsAdmin"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ public function __construct(
*/
public function getAddToWishlistParams($product)
{
$continueUrl = $this->urlEncoder->encode($this->getUrl('customer/account'));
$urlParamName = Action::PARAM_NAME_URL_ENCODED;

$continueUrlParams = [$urlParamName => $continueUrl];

return $this->_wishlistHelper->getAddParams($product, $continueUrlParams);
return $this->_wishlistHelper->getAddParams($product);
}

/**
Expand Down
18 changes: 15 additions & 3 deletions app/code/Magento/Catalog/Model/Design.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Model;

use \Magento\Framework\TranslateInterface;

/**
* Catalog Custom Category design Model
*
Expand All @@ -31,14 +33,20 @@ class Design extends \Magento\Framework\Model\AbstractModel
*/
protected $_localeDate;

/**
* @var TranslateInterface
*/
private $translator;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Framework\View\DesignInterface $design
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
* @param TranslateInterface|null $translator
*/
public function __construct(
\Magento\Framework\Model\Context $context,
Expand All @@ -47,10 +55,13 @@ public function __construct(
\Magento\Framework\View\DesignInterface $design,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
TranslateInterface $translator = null
) {
$this->_localeDate = $localeDate;
$this->_design = $design;
$this->translator = $translator ?:
\Magento\Framework\App\ObjectManager::getInstance()->get(TranslateInterface::class);
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

Expand All @@ -63,6 +74,7 @@ public function __construct(
public function applyCustomDesign($design)
{
$this->_design->setDesignTheme($design);
$this->translator->loadData(null, true);
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ Products,Products
"This attribute set no longer exists.","This attribute set no longer exists."
"You saved the attribute set.","You saved the attribute set."
"Something went wrong while saving the attribute set.","Something went wrong while saving the attribute set."
"You added product %1 to the comparison list.","You added product %1 to the comparison list."
"You cleared the comparison list.","You cleared the comparison list."
"Something went wrong clearing the comparison list.","Something went wrong clearing the comparison list."
"You removed product %1 from the comparison list.","You removed product %1 from the comparison list."
Expand Down Expand Up @@ -808,4 +807,5 @@ Details,Details
"Product Name or SKU", "Product Name or SKU"
"Start typing to find products", "Start typing to find products"
"Product with ID: (%1) doesn't exist", "Product with ID: (%1) doesn't exist"
"Category with ID: (%1) doesn't exist", "Category with ID: (%1) doesn't exist"
"Category with ID: (%1) doesn't exist", "Category with ID: (%1) doesn't exist"
"You added product %1 to the <a href=""%2"">comparison list</a>.","You added product %1 to the <a href=""%2"">comparison list</a>."
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Product;

use Magento\Catalog\Model\Product;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Returns product's image data
*/
class ProductImage implements ResolverInterface
{
/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
): array {
if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}

/** @var Product $product */
$product = $value['model'];
$imageType = $field->getName();

return [
'model' => $product,
'image_type' => $imageType,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductImage;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product as ProductResourceModel;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Store\Model\StoreManagerInterface;

/**
* Returns product's image label
*/
class Label implements ResolverInterface
{
/**
* @var ProductResourceModel
*/
private $productResource;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param ProductResourceModel $productResource
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ProductResourceModel $productResource,
StoreManagerInterface $storeManager
) {
$this->productResource = $productResource;
$this->storeManager = $storeManager;
}

/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
if (!isset($value['image_type'])) {
throw new LocalizedException(__('"image_type" value should be specified'));
}

if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}

/** @var Product $product */
$product = $value['model'];
$imageType = $value['image_type'];
$imagePath = $product->getData($imageType);
$productId = (int)$product->getEntityId();

// null if image is not set
if (null === $imagePath) {
return $this->getAttributeValue($productId, 'name');
}

$imageLabel = $this->getAttributeValue($productId, $imageType . '_label');
if (null === $imageLabel) {
$imageLabel = $this->getAttributeValue($productId, 'name');
}

return $imageLabel;
}

/**
* Get attribute value
*
* @param int $productId
* @param string $attributeCode
* @return null|string Null if attribute value is not exists
*/
private function getAttributeValue(int $productId, string $attributeCode): ?string
{
$storeId = $this->storeManager->getStore()->getId();

$value = $this->productResource->getAttributeRawValue($productId, $attributeCode, $storeId);
return is_array($value) && empty($value) ? null : $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Product;
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductImage;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\ImageFactory;
Expand All @@ -15,13 +15,11 @@
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Returns product's image. If the image is not set, returns a placeholder
* Returns product's image url
*/
class Image implements ResolverInterface
class Url implements ResolverInterface
{
/**
* Product image factory
*
* @var ImageFactory
*/
private $productImageFactory;
Expand All @@ -44,23 +42,36 @@ public function resolve(
ResolveInfo $info,
array $value = null,
array $args = null
): array {
) {
if (!isset($value['image_type'])) {
throw new LocalizedException(__('"image_type" value should be specified'));
}

if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}

/** @var Product $product */
$product = $value['model'];
$imageType = $field->getName();
$path = $product->getData($imageType);
$imagePath = $product->getData($value['image_type']);

$imageUrl = $this->getImageUrl($value['image_type'], $imagePath);
return $imageUrl;
}

/**
* Get image url
*
* @param string $imageType
* @param string|null $imagePath Null if image is not set
* @return string
*/
private function getImageUrl(string $imageType, ?string $imagePath): string
{
$image = $this->productImageFactory->create();
$image->setDestinationSubdir($imageType)
->setBaseFile($path);
->setBaseFile($imagePath);
$imageUrl = $image->getUrl();

return [
'url' => $imageUrl,
'path' => $path,
];
return $imageUrl;
}
}
15 changes: 6 additions & 9 deletions app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,13 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
meta_title: String @doc(description: "A string that is displayed in the title bar and tab of the browser and in search results lists")
meta_keyword: String @doc(description: "A comma-separated list of keywords that are visible only to search engines")
meta_description: String @doc(description: "A brief overview of the product for search results listings, maximum 255 characters")
image: String @doc(description: "The relative path to the main image on the product page")
small_image: ProductImage @doc(description: "The relative path to the small image, which is used on catalog pages") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Image")
thumbnail: String @doc(description: "The relative path to the product's thumbnail image")
image: ProductImage @doc(description: "The relative path to the main image on the product page") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductImage")
small_image: ProductImage @doc(description: "The relative path to the small image, which is used on catalog pages") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductImage")
thumbnail: ProductImage @doc(description: "The relative path to the product's thumbnail image") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductImage")
new_from_date: String @doc(description: "The beginning date for new product listings, and determines if the product is featured as a new product") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\NewFromTo")
new_to_date: String @doc(description: "The end date for new product listings") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\NewFromTo")
tier_price: Float @doc(description: "The price when tier pricing is in effect and the items purchased threshold has been reached")
options_container: String @doc(description: "If the product has multiple options, determines where they appear on the product page")
image_label: String @doc(description: "The label assigned to a product image")
small_image_label: String @doc(description: "The label assigned to a product's small image")
thumbnail_label: String @doc(description: "The label assigned to a product's thumbnail image")
created_at: String @doc(description: "Timestamp indicating when the product was created")
updated_at: String @doc(description: "Timestamp indicating when the product was updated")
country_of_manufacture: String @doc(description: "The product's country of origin")
Expand Down Expand Up @@ -352,9 +349,9 @@ type CustomizableFileValue @doc(description: "CustomizableFileValue defines the
image_size_y: Int @doc(description: "The maximum height of an image")
}

type ProductImage @doc(description: "Product image information. Contains image relative path and URL") {
url: String
path: String
type ProductImage @doc(description: "Product image information. Contains image relative path, URL and label") {
url: String @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductImage\\Url")
label: String @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductImage\\Label")
}

interface CustomizableOptionInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\CustomizableOptionTypeResolver") @doc(description: "The CustomizableOptionInterface contains basic information about a customizable option. It can be implemented by several types of configurable options.") {
Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/CatalogImportExport/Model/Import/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Uploader extends \Magento\MediaStorage\Model\File\Uploader
* @param \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $validator
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\Filesystem\File\ReadFactory $readFactory
* @param null $filePath
* @param null|string $filePath
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(
Expand All @@ -113,15 +113,15 @@ public function __construct(
\Magento\Framework\Filesystem\File\ReadFactory $readFactory,
$filePath = null
) {
if ($filePath !== null) {
$this->_setUploadFile($filePath);
}
$this->_imageFactory = $imageFactory;
$this->_coreFileStorageDb = $coreFileStorageDb;
$this->_coreFileStorage = $coreFileStorage;
$this->_validator = $validator;
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$this->_readFactory = $readFactory;
if ($filePath !== null) {
$this->_setUploadFile($filePath);
}
}

/**
Expand Down Expand Up @@ -353,7 +353,7 @@ protected function _moveFile($tmpPath, $destPath)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
protected function chmod($file)
{
Expand Down
Loading

0 comments on commit 607729e

Please sign in to comment.