Skip to content

Commit

Permalink
Merge branch '2.2-develop' into 7698
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaKis committed Jan 31, 2018
2 parents bc345f8 + 3572ee9 commit 5eba0f3
Show file tree
Hide file tree
Showing 306 changed files with 7,769 additions and 8,892 deletions.
2 changes: 1 addition & 1 deletion COPYING.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2013-2017 Magento, Inc.
Copyright © 2013-present Magento, Inc.

Each Magento source file included in this distribution is licensed under OSL 3.0 or the Magento Enterprise Edition (MEE) license

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Welcome to Magento 2 installation! We're glad you chose to install Magento 2, a cutting edge, feature-rich eCommerce solution that gets results.

## Magento system requirements
[Magento system requirements](http://devdocs.magento.com/magento-system-requirements.html)
[Magento system requirements](http://devdocs.magento.com/guides/v2.2/install-gde/system-requirements2.html)

## Install Magento
To install Magento, see either:

* [Magento DevBox](https://magento.com/tech-resources/download), the easiest way to get started with Magento.
* [Installation guide](http://devdocs.magento.com/guides/v2.0/install-gde/bk-install-guide.html)
* [Installation guide](http://devdocs.magento.com/guides/v2.2/install-gde/bk-install-guide.html)

<h2>Contributing to the Magento 2 code base</h2>
Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes, optimizations, or just good suggestions.
Expand All @@ -22,8 +22,8 @@ To learn about issues, click [here][2]. To open an issue, click [here][3].

To suggest documentation improvements, click [here][4].

[1]: <http://devdocs.magento.com/guides/v2.0/contributor-guide/contributing.html>
[2]: <http://devdocs.magento.com/guides/v2.0/contributor-guide/contributing.html#report>
[1]: <http://devdocs.magento.com/guides/v2.2/contributor-guide/contributing.html>
[2]: <http://devdocs.magento.com/guides/v2.2/contributor-guide/contributing.html#report>
[3]: <https://github.com/magento/magento2/issues>
[4]: <http://devdocs.magento.com>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,45 @@
*/
namespace Magento\Analytics\Block\Adminhtml\System\Config;

use Magento\Framework\App\ObjectManager;

/**
* Provides label with default Time Zone
*/
class CollectionTimeLabel extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* Add default time zone to comment
* @var \Magento\Framework\Locale\ResolverInterface
*/
private $localeResolver;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param array $data
* @param \Magento\Framework\Locale\ResolverInterface|null $localeResolver
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
array $data = [],
\Magento\Framework\Locale\ResolverInterface $localeResolver = null
) {
$this->localeResolver = $localeResolver ?:
ObjectManager::getInstance()->get(\Magento\Framework\Locale\ResolverInterface::class);
parent::__construct($context, $data);
}

/**
* Add current time zone to comment, properly translated according to locale
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$timeZoneCode = $this->_localeDate->getConfigTimezone();
$getLongTimeZoneName = \IntlTimeZone::createTimeZone($timeZoneCode)->getDisplayName();
$locale = $this->localeResolver->getLocale();
$getLongTimeZoneName = \IntlTimeZone::createTimeZone($timeZoneCode)
->getDisplayName(false, \IntlTimeZone::DISPLAY_LONG, $locale);
$element->setData(
'comment',
sprintf("%s (%s)", $getLongTimeZoneName, $timeZoneCode)
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<label>European Union Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="destinations" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="destinations" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Top destinations</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Backup/Model/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backu

if ($tableStatus->getDataLength() > self::BUFFER_LENGTH) {
if ($tableStatus->getAvgRowLength() < self::BUFFER_LENGTH) {
$limit = floor(self::BUFFER_LENGTH / $tableStatus->getAvgRowLength());
$limit = floor(self::BUFFER_LENGTH / max($tableStatus->getAvgRowLength(), 1));
$multiRowsLength = ceil($tableStatus->getRows() / $limit);
} else {
$limit = 1;
Expand All @@ -173,6 +173,7 @@ public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backu
}
}
$backup->write($this->getResource()->getTableForeignKeysSql());
$backup->write($this->getResource()->getTableTriggersSql());
$backup->write($this->getResource()->getFooter());

$this->getResource()->commitTransaction();
Expand Down
24 changes: 24 additions & 0 deletions app/code/Magento/Backup/Model/ResourceModel/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ public function getTableForeignKeysSql($tableName = null)
return $fkScript;
}

/**
* Return triggers fro table(s)
*
* @param string|null $tableName
* @param bool $addDropIfExists
* @return string
*/
public function getTableTriggersSql($tableName = null, $addDropIfExists = true)
{
$triggerScript = '';
if (!$tableName) {
$tables = $this->getTables();
foreach ($tables as $table) {
$tableTriggerScript = $this->_resourceHelper->getTableTriggersSql($table, $addDropIfExists);
if (!empty($tableTriggerScript)) {
$triggerScript .= "\n" . $tableTriggerScript;
}
}
} else {
$triggerScript = $this->getTableTriggersSql($tableName, $addDropIfExists);
}
return $triggerScript;
}

/**
* Retrieve table status
*
Expand Down
36 changes: 36 additions & 0 deletions app/code/Magento/Backup/Model/ResourceModel/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,40 @@ public function restoreTransactionIsolationLevel()
{
$this->getConnection()->query('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ');
}

/**
* Get create script for triggers
*
* @param string $tableName
* @param boolean $addDropIfExists
* @param boolean $stripDefiner
* @return string
*/
public function getTableTriggersSql($tableName, $addDropIfExists = false, $stripDefiner = true)
{
$script = "--\n-- Triggers structure for table `{$tableName}`\n--\n";
$triggers = $this->getConnection()->query('SHOW TRIGGERS LIKE \''. $tableName . '\'')->fetchAll();

if (!$triggers) {
return '';
}
foreach ($triggers as $trigger) {
if ($addDropIfExists) {
$script .= 'DROP TRIGGER IF EXISTS ' . $trigger['Trigger'] . ";\n";
}
$script .= "delimiter ;;\n";

$triggerData = $this->getConnection()->query('SHOW CREATE TRIGGER '. $trigger['Trigger'])->fetch();
if ($stripDefiner) {
$cleanedScript = preg_replace('/DEFINER=[^\s]*/', '', $triggerData['SQL Original Statement']);
$script .= $cleanedScript . "\n";
} else {
$script .= $triggerData['SQL Original Statement'] . "\n";
}
$script .= ";;\n";
$script .= "delimiter ;\n";
}

return $script;
}
}
12 changes: 11 additions & 1 deletion app/code/Magento/Bundle/Model/Product/CopyConstructor/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ public function build(Product $product, Product $duplicate)
$bundleOptions = $product->getExtensionAttributes()->getBundleProductOptions() ?: [];
$duplicatedBundleOptions = [];
foreach ($bundleOptions as $key => $bundleOption) {
$duplicatedBundleOptions[$key] = clone $bundleOption;
$duplicatedBundleOption = clone $bundleOption;
/**
* Set option and selection ids to 'null' in order to create new option(selection) for duplicated product,
* but not modifying existing one, which led to lost of option(selection) in original product.
*/
$productLinks = $duplicatedBundleOption->getProductLinks() ?: [];
foreach ($productLinks as $productLink) {
$productLink->setSelectionId(null);
}
$duplicatedBundleOption->setOptionId(null);
$duplicatedBundleOptions[$key] = $duplicatedBundleOption;
}
$duplicate->getExtensionAttributes()->setBundleProductOptions($duplicatedBundleOptions);
}
Expand Down
62 changes: 46 additions & 16 deletions app/code/Magento/Bundle/Model/ResourceModel/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,39 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
parent::_afterSave($object);

$condition = [
$conditions = [
'option_id = ?' => $object->getId(),
'store_id = ? OR store_id = 0' => $object->getStoreId(),
'parent_product_id = ?' => $object->getParentId()
];

$connection = $this->getConnection();
$connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition);

$data = new \Magento\Framework\DataObject();
$data->setOptionId($object->getId())
->setStoreId($object->getStoreId())
->setParentProductId($object->getParentId())
->setTitle($object->getTitle());

$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());

/**
* also saving default value if this store view scope
*/
if ($this->isOptionPresent($conditions)) {
$connection->update(
$this->getTable('catalog_product_bundle_option_value'),
[
'title' => $object->getTitle()
],
$conditions
);
} else {
$data = new \Magento\Framework\DataObject();
$data->setOptionId($object->getId())
->setStoreId($object->getStoreId())
->setParentProductId($object->getParentId())
->setTitle($object->getTitle());

if ($object->getStoreId()) {
$data->setStoreId(0);
$data->setTitle($object->getDefaultTitle());
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());

/**
* also saving default value if this store view scope
*/
if ($object->getStoreId()) {
$data->setStoreId(0);
$data->setTitle($object->getDefaultTitle());
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
}
}

return $this;
Expand Down Expand Up @@ -210,4 +218,26 @@ public function save(\Magento\Framework\Model\AbstractModel $object)

return $this;
}

/**
* Is Bundle option present in the database
*
* @param array $conditions
*
* @return bool
*/
private function isOptionPresent($conditions)
{
$connection = $this->getConnection();

$select = $connection->select()->from($this->getTable('catalog_product_bundle_option_value'));
foreach ($conditions as $condition => $conditionValue) {
$select->where($condition, $conditionValue);
}
$select->limit(1);

$rowSelect = $connection->fetchRow($select);

return (is_array($rowSelect) && !empty($rowSelect));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Bundle\Test\Unit\Model\Product\CopyConstructor;

use Magento\Bundle\Api\Data\BundleOptionInterface;
use Magento\Bundle\Model\Link;
use Magento\Bundle\Model\Product\CopyConstructor\Bundle;
use Magento\Catalog\Api\Data\ProductExtensionInterface;
use Magento\Catalog\Model\Product;
Expand Down Expand Up @@ -45,6 +46,7 @@ public function testBuildNegative()
*/
public function testBuildPositive()
{
/** @var Product|\PHPUnit_Framework_MockObject_MockObject $product */
$product = $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -60,18 +62,42 @@ public function testBuildPositive()
->method('getExtensionAttributes')
->willReturn($extensionAttributesProduct);

$productLink = $this->getMockBuilder(Link::class)
->setMethods(['setSelectionId'])
->disableOriginalConstructor()
->getMock();
$productLink->expects($this->exactly(2))
->method('setSelectionId')
->with($this->identicalTo(null));
$firstOption = $this->getMockBuilder(BundleOptionInterface::class)
->setMethods(['getProductLinks'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$firstOption->expects($this->once())
->method('getProductLinks')
->willReturn([$productLink]);
$firstOption->expects($this->once())
->method('setOptionId')
->with($this->identicalTo(null));
$secondOption = $this->getMockBuilder(BundleOptionInterface::class)
->setMethods(['getProductLinks'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$secondOption->expects($this->once())
->method('getProductLinks')
->willReturn([$productLink]);
$secondOption->expects($this->once())
->method('setOptionId')
->with($this->identicalTo(null));
$bundleOptions = [
$this->getMockBuilder(BundleOptionInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass(),
$this->getMockBuilder(BundleOptionInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass()
$firstOption,
$secondOption
];
$extensionAttributesProduct->expects($this->once())
->method('getBundleProductOptions')
->willReturn($bundleOptions);

/** @var Product|\PHPUnit_Framework_MockObject_MockObject $duplicate */
$duplicate = $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

<?php $items = $block->getChildren($parentItem) ?>
<?php $_order = $block->getItem()->getOrderItem()->getOrder() ?>
<?php $_count = count($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<?php $_order = $block->getItem()->getOrderItem()->getOrder() ?>

<?php $items = $block->getChildren($parentItem) ?>
<?php $_count = count($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
?>
<?php $parentItem = $block->getItem() ?>
<?php $items = array_merge([$parentItem], $parentItem->getChildrenItems()); ?>
<?php $_count = count($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<?php $parentItem = $block->getItem() ?>
<?php $items = array_merge([$parentItem->getOrderItem()], $parentItem->getOrderItem()->getChildrenItems()) ?>
<?php $shipItems = $block->getChildren($parentItem) ?>
<?php $_count = count($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>
Expand Down
Loading

0 comments on commit 5eba0f3

Please sign in to comment.