Skip to content

Commit 5e6a571

Browse files
author
Hayder Sharhan
committed
Merge remote-tracking branch 'api/for-pr' into for-pr
2 parents 7a775c7 + 7413c18 commit 5e6a571

File tree

169 files changed

+3061
-1738
lines changed

Some content is hidden

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

169 files changed

+3061
-1738
lines changed

app/code/Magento/Backend/Block/System/Store/Edit/Form/Group.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,12 @@ protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
135135
'disabled' => $groupModel->isReadOnly()
136136
]
137137
);
138-
139138
if ($this->_coreRegistry->registry('store_action') == 'edit') {
140-
$stores = $this->_storeFactory->create()->getCollection()->addGroupFilter(
141-
$groupModel->getId()
142-
)->toOptionArray();
139+
$storeActive = 1;
140+
$stores = $this->_storeFactory->create()->getCollection()
141+
->addGroupFilter($groupModel->getId())
142+
->addStatusFilter($storeActive)
143+
->toOptionArray();
143144
$fieldset->addField(
144145
'group_default_store_id',
145146
'select',

app/code/Magento/Backend/Block/System/Store/Edit/Form/Store.php

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function __construct(
5050
*
5151
* @param \Magento\Framework\Data\Form $form
5252
* @return void
53-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
5453
*/
5554
protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
5655
{
@@ -75,27 +74,7 @@ protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
7574
'disabled' => $storeModel->isReadOnly()
7675
]
7776
);
78-
if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) {
79-
if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) {
80-
$form->getElement('store_group_id')->setDisabled(true);
81-
82-
$fieldset->addField(
83-
'store_hidden_group_id',
84-
'hidden',
85-
['name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]
86-
);
87-
} else {
88-
$fieldset->addField(
89-
'store_original_group_id',
90-
'hidden',
91-
[
92-
'name' => 'store[original_group_id]',
93-
'no_span' => true,
94-
'value' => $storeModel->getGroupId()
95-
]
96-
);
97-
}
98-
}
77+
$fieldset = $this->prepareGroupIdField($form, $storeModel, $fieldset);
9978
}
10079

10180
$fieldset->addField(
@@ -131,6 +110,7 @@ protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
131110
'options' => [0 => __('Disabled'), 1 => __('Enabled')],
132111
'required' => true,
133112
'disabled' => $storeModel->isReadOnly()
113+
|| ($storeModel->getId() && $storeModel->isDefault() && $storeModel->isActive())
134114
]
135115
);
136116

@@ -185,4 +165,41 @@ protected function _getStoreGroups()
185165
}
186166
return $groups;
187167
}
168+
169+
/**
170+
* Prepare group id field in the fieldset
171+
*
172+
* @param \Magento\Framework\Data\Form $form
173+
* @param \Magento\Store\Model\Store $storeModel
174+
* @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
175+
* @return \Magento\Framework\Data\Form\Element\Fieldset
176+
*/
177+
private function prepareGroupIdField(
178+
\Magento\Framework\Data\Form $form,
179+
\Magento\Store\Model\Store $storeModel,
180+
\Magento\Framework\Data\Form\Element\Fieldset $fieldset
181+
) {
182+
if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) {
183+
if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) {
184+
$form->getElement('store_group_id')->setDisabled(true);
185+
186+
$fieldset->addField(
187+
'store_hidden_group_id',
188+
'hidden',
189+
['name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]
190+
);
191+
} else {
192+
$fieldset->addField(
193+
'store_original_group_id',
194+
'hidden',
195+
[
196+
'name' => 'store[original_group_id]',
197+
'no_span' => true,
198+
'value' => $storeModel->getGroupId()
199+
]
200+
);
201+
}
202+
}
203+
return $fieldset;
204+
}
188205
}

app/code/Magento/Backend/Controller/Adminhtml/System/Store/Save.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function execute()
4242

4343
case 'group':
4444
$postData['group']['name'] = $this->filterManager->removeTags($postData['group']['name']);
45+
/** @var \Magento\Store\Model\Group $groupModel */
4546
$groupModel = $this->_objectManager->create('Magento\Store\Model\Group');
4647
if ($postData['group']['group_id']) {
4748
$groupModel->load($postData['group']['group_id']);
@@ -50,11 +51,13 @@ public function execute()
5051
if ($postData['group']['group_id'] == '') {
5152
$groupModel->setId(null);
5253
}
53-
54+
if (!$this->isSelectedDefaultStoreActive($postData, $groupModel)) {
55+
throw new \Magento\Framework\Exception\LocalizedException(
56+
__('An inactive store view cannot be saved as default store view')
57+
);
58+
}
5459
$groupModel->save();
55-
5660
$this->_eventManager->dispatch('store_group_save', ['group' => $groupModel]);
57-
5861
$this->messageManager->addSuccess(__('You saved the store.'));
5962
break;
6063

@@ -77,17 +80,14 @@ public function execute()
7780
$storeModel->getGroupId()
7881
);
7982
$storeModel->setWebsiteId($groupModel->getWebsiteId());
80-
if (!$storeModel->isActive() && !$storeModel->isCanDisable()) {
83+
if (!$storeModel->isActive() && $storeModel->isDefault()) {
8184
throw new \Magento\Framework\Exception\LocalizedException(
82-
__('The default store must have at least one enabled store view')
85+
__('The default store cannot be disabled')
8386
);
8487
}
8588
$storeModel->save();
86-
8789
$this->_objectManager->get('Magento\Store\Model\StoreManager')->reinitStores();
88-
8990
$this->_eventManager->dispatch($eventName, ['store' => $storeModel]);
90-
9191
$this->messageManager->addSuccess(__('You saved the store view.'));
9292
break;
9393
default:
@@ -112,4 +112,24 @@ public function execute()
112112
$redirectResult->setPath('adminhtml/*/');
113113
return $redirectResult;
114114
}
115+
116+
/**
117+
* Verify if selected default store is active
118+
*
119+
* @param array $postData
120+
* @param \Magento\Store\Model\Group $groupModel
121+
* @return bool
122+
*/
123+
private function isSelectedDefaultStoreActive(array $postData, \Magento\Store\Model\Group $groupModel)
124+
{
125+
if (!empty($postData['group']['default_store_id'])) {
126+
$defaultStoreId = $postData['group']['default_store_id'];
127+
if (!empty($groupModel->getStores()[$defaultStoreId]) &&
128+
!$groupModel->getStores()[$defaultStoreId]->isActive()
129+
) {
130+
return false;
131+
}
132+
}
133+
return true;
134+
}
115135
}

app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/cells/action-delete.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
-->
77
<button class="action-delete"
88
data-bind="
9-
click: function(){ $parents[1].deleteRecord($parent.index, $parent.recordId); },
9+
click: function(){ $parent.processingDeleteRecord($record().index, $record().recordId); },
1010
attr: {
11-
title: $parents[1].deleteButtonLabel
11+
title: $parent.deleteButtonLabel
1212
}
1313
">
14-
<span data-bind="text: $parents[1].deleteButtonLabel"></span>
14+
<span data-bind="text: $parent.deleteButtonLabel"></span>
1515
</button>

app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/grid.html

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,44 @@
3434
</label>
3535

3636
<div class="admin__field-control" data-role="grid-wrapper">
37+
<div class="admin__control-table-pagination" visible="!!$data.recordData().length">
38+
<div class="admin__data-grid-pager">
39+
<button class="action-previous" type="button" data-bind="attr: {title: $t('Previous Page')}, click: previousPage, disable: isFirst()"></button>
40+
<input class="admin__control-text" type="number" data-bind="attr: {id: ++ko.uid}, value: currentPage">
41+
<label class="admin__control-support-text" data-bind="attr: {for: ko.uid}, text: 'of ' + pages()"></label>
42+
<button class="action-next" type="button" data-bind="attr: {title: $t('Next Page')}, click: nextPage, disable: isLast()"></button>
43+
</div>
44+
</div>
3745
<div class="admin__control-table-wrapper">
3846
<table class="admin__dynamic-rows data-grid" data-role="grid">
3947
<thead if="element.columnsHeader">
4048
<tr>
4149
<th if="dndConfig.enabled"
4250
class="data-grid-draggable-row-cell"/>
4351

44-
<!-- ko foreach: {data: labels, as: 'item'} -->
45-
<th class="data-grid-th"
46-
text="item.label"
47-
visible="item.visible"
48-
disabled="item.disabled"
49-
css="$parent.setClasses(item)">
52+
<th repeat="foreach: labels, item: '$label'"
53+
class="data-grid-th"
54+
text="$label().label"
55+
visible="$label().visible"
56+
disable="$label().disabled"
57+
css="setClasses($label())">
5058
</th>
51-
<!-- /ko -->
5259
</tr>
5360
</thead>
5461

5562
<tbody data-bind="foreach: elems">
56-
<tr class="data-row"
57-
css="'_odd-row': $index() % 2">
58-
<td if="$parent.dndConfig.enabled"
63+
<tr repeat="foreach: elems, item: '$record'"
64+
class="data-row"
65+
css="'_odd-row': $index % 2">
66+
<td if="dndConfig.enabled"
5967
class="data-grid-draggable-row-cell"
60-
template="name: $parent.dndConfig.template, data: $parent.dnd"/>
68+
template="name: dndConfig.template, data: dnd"/>
6169

62-
<!-- ko foreach: { data: elems, as: 'elem'} -->
70+
<!-- ko fastForEach: { data: $record().elems, as: 'elem'} -->
6371
<td if="elem.template"
6472
visible="elem.visible"
65-
disabled="elem.disabled"
66-
css="$parents[1].setClasses(elem)"
73+
disable="elem.disabled"
74+
css="$parent.setClasses(elem)"
6775
template="elem.template"
6876
attr="'data-index': index"/>
6977
<!-- /ko -->

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ protected function mapProductLinkToSelectionModel(
204204

205205
/**
206206
* {@inheritdoc}
207+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
207208
*/
208209
public function addChild(
209210
\Magento\Catalog\Api\Data\ProductInterface $product,
@@ -238,19 +239,25 @@ public function addChild(
238239
if ($linkProductModel->isComposite()) {
239240
throw new InputException(__('Bundle product could not contain another composite product'));
240241
}
242+
241243
if ($selections) {
242244
foreach ($selections as $selection) {
243245
if ($selection['option_id'] == $optionId &&
244246
$selection['product_id'] == $linkProductModel->getEntityId()) {
245-
throw new CouldNotSaveException(
246-
__(
247-
'Child with specified sku: "%1" already assigned to product: "%2"',
248-
[$linkedProduct->getSku(), $product->getSku()]
249-
)
250-
);
247+
if (!$product->getCopyFromView()) {
248+
throw new CouldNotSaveException(
249+
__(
250+
'Child with specified sku: "%1" already assigned to product: "%2"',
251+
[$linkedProduct->getSku(), $product->getSku()]
252+
)
253+
);
254+
} else {
255+
return $this->bundleSelection->create()->load($linkProductModel->getEntityId());
256+
}
251257
}
252258
}
253259
}
260+
254261
$selectionModel = $this->bundleSelection->create();
255262
$selectionModel = $this->mapProductLinkToSelectionModel(
256263
$selectionModel,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function save(
189189
$option->setStoreId($product->getStoreId());
190190
$option->setParentId($product->getData($metadata->getLinkField()));
191191
$linksToAdd = [];
192-
$option->setDefaultTitle($option->getTitle());
192+
$option->setDefaultTitle($option->getDefaultTitle() ?: $option->getTitle());
193193
if (is_array($option->getProductLinks())) {
194194
$linksToAdd = $option->getProductLinks();
195195
}

app/code/Magento/Bundle/Model/Product/OptionList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function getItems(\Magento\Catalog\Api\Data\ProductInterface $product)
7575
);
7676
$optionDataObject->setOptionId($option->getOptionId())
7777
->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())
78+
->setDefaultTitle($option->getDefaultTitle())
7879
->setSku($product->getSku())
7980
->setProductLinks($productLinks);
8081
$optionList[] = $optionDataObject;

app/code/Magento/Bundle/Model/Product/SaveHandler.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,26 @@ public function execute($entityType, $entity, $arguments = [])
5959
if ($entity->getTypeId() !== 'bundle' || empty($bundleProductOptions)) {
6060
return $entity;
6161
}
62-
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
63-
foreach ($this->optionRepository->getList($entity->getSku()) as $option) {
64-
$this->removeOptionLinks($entity->getSku(), $option);
65-
$this->optionRepository->delete($option);
66-
}
6762

68-
$options = $bundleProductOptions ?: [];
69-
foreach ($options as $option) {
70-
$option->setOptionId(null);
71-
$this->optionRepository->save($entity, $option);
63+
if (!$entity->getCopyFromView()) {
64+
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
65+
foreach ($this->optionRepository->getList($entity->getSku()) as $option) {
66+
$this->removeOptionLinks($entity->getSku(), $option);
67+
$this->optionRepository->delete($option);
68+
}
69+
70+
$options = $bundleProductOptions ?: [];
71+
foreach ($options as $option) {
72+
$option->setOptionId(null);
73+
$this->optionRepository->save($entity, $option);
74+
}
75+
} else {
76+
//save only labels and not selections + product links
77+
$options = $bundleProductOptions ?: [];
78+
foreach ($options as $option) {
79+
$this->optionRepository->save($entity, $option);
80+
$entity->setCopyFromView(false);
81+
}
7282
}
7383
return $entity;
7484
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Model\ResourceModel\Selection\Plugin;
7+
8+
use Magento\Store\Model\Store;
9+
10+
class Collection
11+
{
12+
/**
13+
* Join website product limitation override
14+
* we don't need the website->product filter for children on selections
15+
*
16+
* @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $subject
17+
* @param \Closure $proceed
18+
* @param null|string|bool|int|Store $store
19+
* @return $this
20+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
21+
*/
22+
public function aroundAddStoreFilter(
23+
\Magento\Bundle\Model\ResourceModel\Selection\Collection $subject,
24+
\Closure $proceed,
25+
$store = null
26+
) {
27+
return $subject;
28+
}
29+
}

0 commit comments

Comments
 (0)