Skip to content

Commit 7268151

Browse files
committed
Merge branch 'mainline-time_zone' into MAGETWO-45300
2 parents 5ce8923 + 2e8d1fa commit 7268151

File tree

86 files changed

+1888
-894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1888
-894
lines changed

app/code/Magento/Backend/Model/Session/AdminConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function __construct(
8484
$adminPath = $this->extractAdminPath();
8585
$this->setCookiePath($adminPath);
8686
$this->setName($sessionName);
87+
$this->setCookieSecure($this->_httpRequest->isSecure());
8788
}
8889

8990
/**

app/code/Magento/Backend/Test/Unit/Model/Session/AdminConfigTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ public function testSetCookiePathNonDefault()
105105
}
106106

107107
/**
108-
* Test for setting session name for admin
109-
*
108+
* Test for setting session name and secure_cookie for admin
109+
* @dataProvider requestSecureDataProvider
110+
* @param $secureRequest
110111
*/
111-
public function testSetSessionNameByConstructor()
112+
public function testSetSessionSettingsByConstructor($secureRequest)
112113
{
113114
$sessionName = 'admin';
115+
$this->requestMock->expects($this->once())->method('isSecure')->willReturn($secureRequest);
114116

115117
$validatorMock = $this->getMockBuilder('Magento\Framework\Validator\ValidatorInterface')
116118
->disableOriginalConstructor()
@@ -136,5 +138,11 @@ public function testSetSessionNameByConstructor()
136138
]
137139
);
138140
$this->assertSame($sessionName, $adminConfig->getName());
141+
$this->assertSame($secureRequest, $adminConfig->getCookieSecure());
142+
}
143+
144+
public function requestSecureDataProvider()
145+
{
146+
return [[true], [false]];
139147
}
140148
}

app/code/Magento/Bundle/Model/LinkManagement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public function addChild(
254254

255255
try {
256256
$selectionModel->save();
257+
$resource->addProductRelations($product->getId(), [$linkProductModel->getId()]);
257258
} catch (\Exception $e) {
258259
throw new CouldNotSaveException(__('Could not save child: "%1"', $e->getMessage()), $e);
259260
}
@@ -294,7 +295,7 @@ public function removeChild($sku, $optionId, $childSku)
294295
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
295296
$resource = $this->bundleFactory->create();
296297
$resource->dropAllUnneededSelections($product->getId(), $excludeSelectionIds);
297-
$resource->saveProductRelations($product->getId(), array_unique($usedProductIds));
298+
$resource->removeProductRelations($product->getId(), array_unique($usedProductIds));
298299

299300
return true;
300301
}

app/code/Magento/Bundle/Model/OptionRepository.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,22 @@ public function save(
170170
$option->setParentId($product->getId());
171171

172172
$optionId = $option->getOptionId();
173-
$linksToAdd = [];
174173
if (!$optionId) {
174+
$linksToAdd = [];
175175
$option->setDefaultTitle($option->getTitle());
176176
if (is_array($option->getProductLinks())) {
177177
$linksToAdd = $option->getProductLinks();
178178
}
179+
try {
180+
$this->optionResource->save($option);
181+
} catch (\Exception $e) {
182+
throw new CouldNotSaveException(__('Could not save option'), $e);
183+
}
184+
185+
/** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */
186+
foreach ($linksToAdd as $linkedProduct) {
187+
$this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct);
188+
}
179189
} else {
180190
$optionCollection = $this->type->getOptionsCollection($product);
181191

@@ -188,19 +198,13 @@ public function save(
188198

189199
$option->setData(array_merge($existingOption->getData(), $option->getData()));
190200
$this->updateOptionSelection($product, $option);
201+
try {
202+
$this->optionResource->save($option);
203+
} catch (\Exception $e) {
204+
throw new CouldNotSaveException(__('Could not save option'), $e);
205+
}
191206
}
192-
193-
try {
194-
$this->optionResource->save($option);
195-
} catch (\Exception $e) {
196-
throw new CouldNotSaveException(__('Could not save option'), $e);
197-
}
198-
199-
/** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */
200-
foreach ($linksToAdd as $linkedProduct) {
201-
$this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct);
202-
}
203-
207+
$product->setIsRelationsChanged(true);
204208
return $option->getOptionId();
205209
}
206210

app/code/Magento/Bundle/Model/ResourceModel/Bundle.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,30 @@ public function saveProductRelations($parentId, $childIds)
142142

143143
return $this;
144144
}
145+
146+
/**
147+
* Add product relations
148+
*
149+
* @param int $parentId
150+
* @param array $childIds
151+
* @return $this
152+
*/
153+
public function addProductRelations($parentId, $childIds)
154+
{
155+
$this->_productRelation->addRelations($parentId, $childIds);
156+
return $this;
157+
}
158+
159+
/**
160+
* Remove product relations
161+
*
162+
* @param int $parentId
163+
* @param array $childIds
164+
* @return $this
165+
*/
166+
public function removeProductRelations($parentId, $childIds)
167+
{
168+
$this->_productRelation->removeRelations($parentId, $childIds);
169+
return $this;
170+
}
145171
}

app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ public function testRemoveChild()
868868
$this->product->expects($this->any())->method('getId')->will($this->returnValue(3));
869869

870870
$bundle->expects($this->once())->method('dropAllUnneededSelections')->with(3, []);
871-
$bundle->expects($this->once())->method('saveProductRelations')->with(3, []);
871+
$bundle->expects($this->once())->method('removeProductRelations')->with(3, []);
872872
//Params come in lowercase to method
873873
$this->assertTrue($this->model->removeChild($productSku, $optionId, $childSku));
874874
}

app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ public function testSaveExistingOption()
408408
->method('getProductLinks')
409409
->willReturn([$productLinkUpdate, $productLinkNew]);
410410

411-
$this->optionResourceMock->expects($this->once())->method('save')->with($optionMock)->willReturnSelf();
412411
$this->linkManagementMock->expects($this->once())
413412
->method('addChild')
414413
->with($productMock, $optionId, $productLinkNew);

app/code/Magento/Bundle/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<plugin name="bundle" type="Magento\Bundle\Model\Plugin\PriceBackend" sortOrder="100" />
7979
</type>
8080
<type name="Magento\Catalog\Api\ProductRepositoryInterface">
81-
<plugin name="bundleSaveOptions" type="\Magento\Bundle\Model\Plugin\BundleSaveOptions"/>
81+
<plugin name="bundleSaveOptions" type="\Magento\Bundle\Model\Plugin\BundleSaveOptions" sortOrder="100"/>
8282
</type>
8383
<type name="Magento\Catalog\Model\Product">
8484
<plugin name="bundleLoadOptions" type="\Magento\Bundle\Model\Plugin\BundleLoadOptions"/>

app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/Form.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ protected function _prepareLayout()
9898
[
9999
'id' => 'delete',
100100
'label' => __('Delete Category'),
101-
'onclick' => "categoryDelete('" . $this->getUrl(
102-
'catalog/*/delete',
103-
['_current' => true]
104-
) . "')",
101+
'onclick' => "categoryDelete('" . $this->getDeleteUrl() . "')",
105102
'class' => 'delete'
106103
]
107104
);
@@ -115,7 +112,9 @@ protected function _prepareLayout()
115112
[
116113
'id' => 'reset',
117114
'label' => __('Reset'),
118-
'onclick' => "categoryReset('" . $this->getUrl($resetPath, ['_current' => true]) . "',true)",
115+
'onclick' => "categoryReset('"
116+
. $this->getUrl($resetPath, $this->getDefaultUrlParams())
117+
. "',true)",
119118
'class' => 'reset'
120119
]
121120
);
@@ -259,8 +258,7 @@ public function getHeader()
259258
*/
260259
public function getDeleteUrl(array $args = [])
261260
{
262-
$params = ['_current' => true];
263-
$params = array_merge($params, $args);
261+
$params = array_merge($this->getDefaultUrlParams(), $args);
264262
return $this->getUrl('catalog/*/delete', $params);
265263
}
266264

@@ -272,8 +270,7 @@ public function getDeleteUrl(array $args = [])
272270
*/
273271
public function getRefreshPathUrl(array $args = [])
274272
{
275-
$params = ['_current' => true];
276-
$params = array_merge($params, $args);
273+
$params = array_merge($this->getDefaultUrlParams(), $args);
277274
return $this->getUrl('catalog/*/refreshPath', $params);
278275
}
279276

@@ -359,4 +356,12 @@ protected function getButtonChildBlock($childId, $blockClassName = null)
359356
}
360357
return $this->getLayout()->createBlock($blockClassName, $this->getNameInLayout() . '-' . $childId);
361358
}
359+
360+
/**
361+
* @return array
362+
*/
363+
protected function getDefaultUrlParams()
364+
{
365+
return ['_current' => true, '_query' => ['isAjax' => null]];
366+
}
362367
}

app/code/Magento/Catalog/Block/Product/View/Options/Type/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function getValuesHtml()
142142
' name="options[' .
143143
$_option->getId() .
144144
']' .
145-
(!empty($arraySign) ? '[' . $htmlValue . ']' : '') .
145+
$arraySign .
146146
'" id="options_' .
147147
$_option->getId() .
148148
'_' .

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,31 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product
2626
*/
2727
protected $productTypeManager;
2828

29+
/**
30+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
31+
*/
32+
protected $productRepository;
33+
2934
/**
3035
* @param Action\Context $context
3136
* @param Builder $productBuilder
3237
* @param Initialization\Helper $initializationHelper
3338
* @param \Magento\Catalog\Model\Product\Copier $productCopier
3439
* @param \Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager
40+
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
3541
*/
3642
public function __construct(
3743
\Magento\Backend\App\Action\Context $context,
3844
Product\Builder $productBuilder,
3945
Initialization\Helper $initializationHelper,
4046
\Magento\Catalog\Model\Product\Copier $productCopier,
41-
\Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager
47+
\Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager,
48+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
4249
) {
4350
$this->initializationHelper = $initializationHelper;
4451
$this->productCopier = $productCopier;
4552
$this->productTypeManager = $productTypeManager;
53+
$this->productRepository = $productRepository;
4654
parent::__construct($context, $productBuilder);
4755
}
4856

@@ -74,6 +82,7 @@ public function execute()
7482

7583
$originalSku = $product->getSku();
7684
$product->save();
85+
$this->handleImageRemoveError($data, $product->getId());
7786
$productId = $product->getId();
7887
$productAttributeSetId = $product->getAttributeSetId();
7988
$productTypeId = $product->getTypeId();
@@ -147,4 +156,33 @@ public function execute()
147156
}
148157
return $resultRedirect;
149158
}
159+
160+
/**
161+
* Notify customer when image was not deleted in specific case.
162+
* TODO: temporary workaround must be eliminated in MAGETWO-45306
163+
*
164+
* @param array $postData
165+
* @param int $productId
166+
* @return void
167+
*/
168+
private function handleImageRemoveError($postData, $productId)
169+
{
170+
if (isset($postData['product']['media_gallery']['images'])) {
171+
$removedImagesAmount = 0;
172+
foreach ($postData['product']['media_gallery']['images'] as $image) {
173+
if (!empty($image['removed'])) {
174+
$removedImagesAmount++;
175+
}
176+
}
177+
if ($removedImagesAmount) {
178+
$expectedImagesAmount = count($postData['product']['media_gallery']['images']) - $removedImagesAmount;
179+
$product = $this->productRepository->getById($productId);
180+
if ($expectedImagesAmount != count($product->getMediaGallery('images'))) {
181+
$this->messageManager->addNotice(
182+
__('The image cannot be removed as it has been assigned to the other image role')
183+
);
184+
}
185+
}
186+
}
187+
}
150188
}

app/code/Magento/Catalog/Model/CategoryRepository.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
106106
*/
107107
public function get($categoryId, $storeId = null)
108108
{
109-
if (!isset($this->instances[$categoryId])) {
109+
$cacheKey = null !== $storeId ? $storeId : 'all';
110+
if (!isset($this->instances[$categoryId][$cacheKey])) {
110111
/** @var Category $category */
111112
$category = $this->categoryFactory->create();
112113
if (null !== $storeId) {
@@ -116,9 +117,9 @@ public function get($categoryId, $storeId = null)
116117
if (!$category->getId()) {
117118
throw NoSuchEntityException::singleField('id', $categoryId);
118119
}
119-
$this->instances[$categoryId] = $category;
120+
$this->instances[$categoryId][$cacheKey] = $category;
120121
}
121-
return $this->instances[$categoryId];
122+
return $this->instances[$categoryId][$cacheKey];
122123
}
123124

124125
/**

app/code/Magento/Catalog/Model/Product.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,11 +1505,11 @@ public function getMediaGalleryImages()
15051505
if (!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
15061506
$images = $this->_collectionFactory->create();
15071507
foreach ($this->getMediaGallery('images') as $image) {
1508-
if (isset($image['disabled']) && $image['disabled']) {
1508+
if ((isset($image['disabled']) && $image['disabled']) || empty($image['value_id'])) {
15091509
continue;
15101510
}
15111511
$image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
1512-
$image['id'] = !empty($image['value_id']) ? $image['value_id'] : null;
1512+
$image['id'] = $image['value_id'];
15131513
$image['path'] = $directory->getAbsolutePath($this->getMediaConfig()->getMediaPath($image['file']));
15141514
$images->addItem(new \Magento\Framework\DataObject($image));
15151515
}

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,29 @@ protected function initializeProductData(array $productData, $createNew)
301301
foreach ($productData as $key => $value) {
302302
$product->setData($key, $value);
303303
}
304+
$this->assignProductToWebsites($product);
304305

305306
return $product;
306307
}
307308

309+
/**
310+
* @param \Magento\Catalog\Model\Product $product
311+
* @return void
312+
*/
313+
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
314+
{
315+
if (!$this->storeManager->hasSingleStore()) {
316+
317+
if ($this->storeManager->getStore()->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
318+
$websiteIds = array_keys($this->storeManager->getWebsites());
319+
} else {
320+
$websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
321+
}
322+
323+
$product->setWebsiteIds(array_unique(array_merge($product->getWebsiteIds(), $websiteIds)));
324+
}
325+
}
326+
308327
/**
309328
* Process product options, creating new options, updating and deleting existing options
310329
*

0 commit comments

Comments
 (0)