Skip to content

Commit

Permalink
Merge branch '2.4-develop' into mftf/module-cms-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Feb 27, 2020
2 parents 79797a7 + 9f093a3 commit 7c4b59b
Show file tree
Hide file tree
Showing 60 changed files with 2,616 additions and 557 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/Catalog/Block/Product/ImageFactory.php
Expand Up @@ -123,7 +123,7 @@ private function getLabel(Product $product, string $imageType): string
if (empty($label)) {
$label = $product->getName();
}
return (string) $label;
return (string)$label;
}

/**
Expand Down Expand Up @@ -161,15 +161,15 @@ public function create(Product $product, string $imageId, array $attributes = nu
}

$attributes = $attributes === null ? [] : $attributes;

$data = [
'data' => [
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
'image_url' => $imageAsset->getUrl(),
'width' => $imageMiscParams['image_width'],
'height' => $imageMiscParams['image_height'],
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
'ratio' => $this->getRatio($imageMiscParams['image_width'], $imageMiscParams['image_height']),
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
'custom_attributes' => $this->getStringCustomAttributes($attributes),
'class' => $this->getClass($attributes),
'product_id' => $product->getId()
Expand Down
24 changes: 8 additions & 16 deletions app/code/Magento/Catalog/Model/Product.php
Expand Up @@ -10,6 +10,7 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool;
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\Catalog\Model\FilterProductCustomAttribute;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
Expand Down Expand Up @@ -108,7 +109,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
/**
* Product object customization (not stored in DB)
*
* @var array
* @var OptionInterface[]
*/
protected $_customOptions = [];

Expand Down Expand Up @@ -2062,7 +2063,7 @@ public function addCustomOption($code, $value, $product = null)
/**
* Sets custom options for the product
*
* @param array $options Array of options
* @param OptionInterface[] $options Array of options
* @return void
*/
public function setCustomOptions(array $options)
Expand All @@ -2073,7 +2074,7 @@ public function setCustomOptions(array $options)
/**
* Get all custom options of the product
*
* @return array
* @return OptionInterface[]
*/
public function getCustomOptions()
{
Expand All @@ -2084,14 +2085,11 @@ public function getCustomOptions()
* Get product custom option info
*
* @param string $code
* @return array
* @return OptionInterface|null
*/
public function getCustomOption($code)
{
if (isset($this->_customOptions[$code])) {
return $this->_customOptions[$code];
}
return null;
return $this->_customOptions[$code] ?? null;
}

/**
Expand All @@ -2101,11 +2099,7 @@ public function getCustomOption($code)
*/
public function hasCustomOptions()
{
if (count($this->_customOptions)) {
return true;
} else {
return false;
}
return (bool)count($this->_customOptions);
}

/**
Expand Down Expand Up @@ -2405,16 +2399,14 @@ public function reloadPriceInfo()
}
}

// phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
/**
* Return Data Object data in array format.
*
* @return array
* @todo refactor with converter for AbstractExtensibleModel
*/
public function __toArray()
public function __toArray() //phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
{
// phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
$data = $this->_data;
$hasToArray = function ($model) {
return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);
Expand Down
56 changes: 25 additions & 31 deletions app/code/Magento/Catalog/Model/Product/Type.php
Expand Up @@ -6,43 +6,37 @@
namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Type\Pool;
use Magento\Catalog\Model\Product\Type\Price;
use Magento\Catalog\Model\Product\Type\Price\Factory as PriceFactory;
use Magento\Catalog\Model\Product\Type\Simple;
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\Pricing\PriceInfo\Factory as PriceInfoFactory;

/**
* Product type model
*
*
* @api
* @since 100.0.2
*/
class Type implements OptionSourceInterface
{
/**#@+
* Available product types
*/
const TYPE_SIMPLE = 'simple';

const TYPE_BUNDLE = 'bundle';

const TYPE_VIRTUAL = 'virtual';
/**#@-*/

/**
* Default product type
*/
const DEFAULT_TYPE = 'simple';

/**
* Default product type model
*/
const DEFAULT_TYPE_MODEL = \Magento\Catalog\Model\Product\Type\Simple::class;
const DEFAULT_TYPE_MODEL = Simple::class;

/**
* Default price model
*/
const DEFAULT_PRICE_MODEL = \Magento\Catalog\Model\Product\Type\Price::class;
const DEFAULT_PRICE_MODEL = Price::class;

/**
* @var \Magento\Catalog\Model\ProductTypes\ConfigInterface
* @var ConfigInterface
*/
protected $_config;

Expand Down Expand Up @@ -77,35 +71,35 @@ class Type implements OptionSourceInterface
/**
* Product type factory
*
* @var \Magento\Catalog\Model\Product\Type\Pool
* @var Pool
*/
protected $_productTypePool;

/**
* Price model factory
*
* @var \Magento\Catalog\Model\Product\Type\Price\Factory
* @var PriceFactory
*/
protected $_priceFactory;

/**
* @var \Magento\Framework\Pricing\PriceInfo\Factory
* @var PriceInfoFactory
*/
protected $_priceInfoFactory;

/**
* Construct
*
* @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $config
* @param \Magento\Catalog\Model\Product\Type\Pool $productTypePool
* @param \Magento\Catalog\Model\Product\Type\Price\Factory $priceFactory
* @param \Magento\Framework\Pricing\PriceInfo\Factory $priceInfoFactory
* @param ConfigInterface $config
* @param Pool $productTypePool
* @param PriceFactory $priceFactory
* @param PriceInfoFactory $priceInfoFactory
*/
public function __construct(
\Magento\Catalog\Model\ProductTypes\ConfigInterface $config,
\Magento\Catalog\Model\Product\Type\Pool $productTypePool,
\Magento\Catalog\Model\Product\Type\Price\Factory $priceFactory,
\Magento\Framework\Pricing\PriceInfo\Factory $priceInfoFactory
ConfigInterface $config,
Pool $productTypePool,
PriceFactory $priceFactory,
PriceInfoFactory $priceInfoFactory
) {
$this->_config = $config;
$this->_productTypePool = $productTypePool;
Expand All @@ -116,8 +110,8 @@ public function __construct(
/**
* Factory to product singleton product type instances
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product\Type\AbstractType
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return \Magento\Catalog\Model\Product\Type\AbstractType
*/
public function factory($product)
{
Expand All @@ -139,8 +133,8 @@ public function factory($product)
/**
* Product type price model factory
*
* @param string $productType
* @return \Magento\Catalog\Model\Product\Type\Price
* @param string $productType
* @return \Magento\Catalog\Model\Product\Type\Price
*/
public function priceFactory($productType)
{
Expand Down
11 changes: 11 additions & 0 deletions app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml
Expand Up @@ -212,6 +212,17 @@
<data key="quantity">1001</data>
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
</entity>
<entity name="SimpleProductDisabledStockQuantityZero" type="product">
<data key="sku" unique="suffix">testSku</data>
<data key="type_id">simple</data>
<data key="attribute_set_id">4</data>
<data key="name" unique="suffix">Simple Product Disabled Quantity Zero</data>
<data key="price">123.00</data>
<data key="visibility">4</data>
<data key="status">2</data>
<data key="quantity">0</data>
<requiredEntity type="product_extension_attribute">EavStock0</requiredEntity>
</entity>
<entity name="SimpleProductNotVisibleIndividually" type="product">
<data key="name" unique="suffix">Simple Product Not Visible Individually</data>
<data key="sku" unique="suffix">simple_product_not_visible_individually</data>
Expand Down
Expand Up @@ -95,6 +95,7 @@ public function createDataProvider(): array
return [
$this->getTestDataWithoutAttributes(),
$this->getTestDataWithAttributes(),
$this->getTestDataWithoutDimensions()
];
}

Expand Down Expand Up @@ -209,4 +210,21 @@ private function getTestDataWithAttributes(): array
],
];
}

/**
* @return array
*/
private function getTestDataWithoutDimensions(): array
{
$data = $this->getTestDataWithoutAttributes();

$data['data']['imageParamsBuilder']['image_width'] = null;
$data['data']['imageParamsBuilder']['image_height'] = null;

$data['expected']['data']['width'] = null;
$data['expected']['data']['height'] = null;
$data['expected']['data']['ratio'] = 1.0;

return $data;
}
}

0 comments on commit 7c4b59b

Please sign in to comment.