Skip to content

Commit

Permalink
Merge pull request #5 from magento/2.2-develop
Browse files Browse the repository at this point in the history
2.2 develop-update branch
  • Loading branch information
speedy008 authored Nov 21, 2018
2 parents 7c013a1 + b1e26d5 commit 584242c
Show file tree
Hide file tree
Showing 128 changed files with 3,159 additions and 1,422 deletions.
7 changes: 6 additions & 1 deletion app/code/Magento/Analytics/Model/Cryptographer.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ private function getInitializationVector()
*/
private function validateCipherMethod($cipherMethod)
{
$methods = openssl_get_cipher_methods();
$methods = array_map(
'strtolower',
openssl_get_cipher_methods()
);
$cipherMethod = strtolower($cipherMethod);

return (false !== array_search($cipherMethod, $methods));
}
}
7 changes: 5 additions & 2 deletions app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,11 @@ public function getSku($product)
$selectionIds = $this->serializer->unserialize($customOption->getValue());
if (!empty($selectionIds)) {
$selections = $this->getSelectionsByIds($selectionIds, $product);
foreach ($selections->getItems() as $selection) {
$skuParts[] = $selection->getSku();
foreach ($selectionIds as $selectionId) {
$entity = $selections->getItemByColumnValue('selection_id', $selectionId);
if (isset($entity) && $entity->getEntityId()) {
$skuParts[] = $entity->getSku();
}
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ public function testGetSkuWithoutType()
->disableOriginalConstructor()
->getMock();
$selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
->setMethods(['getSku', '__wakeup'])
->setMethods(['getSku', 'getEntityId', '__wakeup'])
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -1623,9 +1623,12 @@ public function testGetSkuWithoutType()
->will($this->returnValue($serializeIds));
$selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6);
$selectionMock->expects(($this->any()))
->method('getItems')
->will($this->returnValue([$selectionItemMock]));
$selectionItemMock->expects($this->any())
->method('getItemByColumnValue')
->will($this->returnValue($selectionItemMock));
$selectionItemMock->expects($this->at(0))
->method('getEntityId')
->will($this->returnValue(1));
$selectionItemMock->expects($this->once())
->method('getSku')
->will($this->returnValue($itemSku));

Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@
</argument>
</arguments>
</type>
<type name="Magento\Sales\Model\Order\ProductOption">
<arguments>
<argument name="processorPool" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
</argument>
</arguments>
</type>
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
<arguments>
<argument name="excludeAdjustments" xsi:type="array">
Expand Down
22 changes: 7 additions & 15 deletions app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,19 @@ private function getCategoryLinksPositions($entity)
*/
private function mergeCategoryLinks($newCategoryPositions, $oldCategoryPositions)
{
$result = [];
if (empty($newCategoryPositions)) {
return $result;
return [];
}

$categoryPositions = array_combine(array_column($oldCategoryPositions, 'category_id'), $oldCategoryPositions);
foreach ($newCategoryPositions as $newCategoryPosition) {
$key = array_search(
$newCategoryPosition['category_id'],
array_column($oldCategoryPositions, 'category_id')
);

if ($key === false) {
$result[] = $newCategoryPosition;
} elseif (isset($oldCategoryPositions[$key])
&& $oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']
) {
$result[] = $newCategoryPositions[$key];
unset($oldCategoryPositions[$key]);
$categoryId = $newCategoryPosition['category_id'];
if (!isset($categoryPositions[$categoryId])) {
$categoryPositions[$categoryId] = ['category_id' => $categoryId];
}
$categoryPositions[$categoryId]['position'] = $newCategoryPosition['position'];
}
$result = array_merge($result, $oldCategoryPositions);
$result = array_values($categoryPositions);

return $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ abstract class AbstractAction
*/
private $queryGenerator;

/**
* Current store id.
* @var int
*/
private $currentStoreId = 0;

/**
* @param ResourceConnection $resource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand Down Expand Up @@ -167,6 +173,7 @@ protected function reindex()
{
foreach ($this->storeManager->getStores() as $store) {
if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
$this->currentStoreId = $store->getId();
$this->reindexRootCategory($store);
$this->reindexAnchorCategories($store);
$this->reindexNonAnchorCategories($store);
Expand Down Expand Up @@ -594,7 +601,7 @@ protected function getTemporaryTreeIndexTableName()
if (empty($this->tempTreeIndexTableName)) {
$this->tempTreeIndexTableName = $this->connection->getTableName('temp_catalog_category_tree_index')
. '_'
. substr(md5(time() . random_int(0, 999999999)), 0, 8);
. substr(sha1(time() . random_int(0, 999999999)), 0, 8);
}

return $this->tempTreeIndexTableName;
Expand Down Expand Up @@ -649,30 +656,47 @@ protected function makeTempCategoryTreeIndex()
}

/**
* Populate the temporary category tree index table
* Populate the temporary category tree index table.
*
* @param string $temporaryName
* @return void
* @since 101.0.0
*/
protected function fillTempCategoryTreeIndex($temporaryName)
{
$offset = 0;
$limit = 500;

$categoryTable = $this->getTable('catalog_category_entity');

$categoriesSelect = $this->connection->select()
->from(
['c' => $categoryTable],
['entity_id', 'path']
)->limit($limit, $offset);

$categories = $this->connection->fetchAll($categoriesSelect);
$isActiveAttributeId = $this->config->getAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'is_active'
)->getId();
$categoryMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class);
$categoryLinkField = $categoryMetadata->getLinkField();
$selects = $this->prepareSelectsByRange(
$this->connection->select()
->from(
['c' => $this->getTable('catalog_category_entity')],
['entity_id', 'path']
)->joinInner(
['ccacd' => $this->getTable('catalog_category_entity_int')],
'ccacd.' . $categoryLinkField . ' = c.' . $categoryLinkField
. ' AND ccacd.store_id = 0' . ' AND ccacd.attribute_id = ' . $isActiveAttributeId,
[]
)->joinLeft(
['ccacs' => $this->getTable('catalog_category_entity_int')],
'ccacs.' . $categoryLinkField . ' = c.' . $categoryLinkField
. ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = '
. $this->currentStoreId,
[]
)->where(
$this->connection->getIfNullSql('ccacs.value', 'ccacd.value') . ' = ?',
1
),
'entity_id'
);

while ($categories) {
foreach ($selects as $select) {
$values = [];

foreach ($categories as $category) {
foreach ($this->connection->fetchAll($select) as $category) {
foreach (explode('/', $category['path']) as $parentId) {
if ($parentId !== $category['entity_id']) {
$values[] = [$parentId, $category['entity_id']];
Expand All @@ -683,15 +707,6 @@ protected function fillTempCategoryTreeIndex($temporaryName)
if (count($values) > 0) {
$this->connection->insertArray($temporaryName, ['parent_id', 'child_id'], $values);
}

$offset += $limit;
$categoriesSelect = $this->connection->select()
->from(
['c' => $categoryTable],
['entity_id', 'path']
)->limit($limit, $offset);

$categories = $this->connection->fetchAll($categoriesSelect);
}
}

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

use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice;

/**
* Tier price data abstract handler.
*/
abstract class AbstractHandler implements ExtensionInterface
{
/**
* @var \Magento\Customer\Api\GroupManagementInterface
*/
protected $groupManagement;

/**
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
*/
public function __construct(
GroupManagementInterface $groupManagement
) {
$this->groupManagement = $groupManagement;
}

/**
* Get additional tier price fields.
*
* @return array
*/
protected function getAdditionalFields(array $objectArray): array
{
$percentageValue = $this->getPercentage($objectArray);

return [
'value' => $percentageValue ? null : $objectArray['price'],
'percentage_value' => $percentageValue ?: null,
];
}

/**
* Check whether price has percentage value.
*
* @param array $priceRow
* @return integer|null
*/
protected function getPercentage(array $priceRow)
{
return isset($priceRow['percentage_value']) && is_numeric($priceRow['percentage_value'])
? (int)$priceRow['percentage_value']
: null;
}

/**
* Prepare tier price data by provided price row data.
*
* @param array $data
* @return array
*/
protected function prepareTierPrice(array $data): array
{
$useForAllGroups = (int)$data['cust_group'] === $this->groupManagement->getAllCustomersGroup()->getId();
$customerGroupId = $useForAllGroups ? 0 : $data['cust_group'];
$tierPrice = array_merge(
$this->getAdditionalFields($data),
[
'website_id' => $data['website_id'],
'all_groups' => (int)$useForAllGroups,
'customer_group_id' => $customerGroupId,
'value' => $data['price'] ?? null,
'qty' => $this->parseQty($data['price_qty']),
]
);

return $tierPrice;
}

/**
* Parse quantity value into float.
*
* @param mixed $value
* @return float|int
*/
protected function parseQty($value)
{
return $value * 1;
}
}
Loading

0 comments on commit 584242c

Please sign in to comment.