Skip to content

Commit c3199e7

Browse files
author
He, Joan(johe)
committed
Merge pull request #550 from magento-api/for-pr
[API] Bug Fixes
2 parents 9ee50d9 + 4ebda96 commit c3199e7

File tree

42 files changed

+353
-106
lines changed

Some content is hidden

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

42 files changed

+353
-106
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: 32 additions & 6 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,16 +51,19 @@ 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

6164
case 'store':
6265
$eventName = 'store_edit';
66+
/** @var \Magento\Store\Model\Store $storeModel */
6367
$storeModel = $this->_objectManager->create('Magento\Store\Model\Store');
6468
$postData['store']['name'] = $this->filterManager->removeTags($postData['store']['name']);
6569
if ($postData['store']['store_id']) {
@@ -76,12 +80,14 @@ public function execute()
7680
$storeModel->getGroupId()
7781
);
7882
$storeModel->setWebsiteId($groupModel->getWebsiteId());
83+
if (!$storeModel->isActive() && $storeModel->isDefault()) {
84+
throw new \Magento\Framework\Exception\LocalizedException(
85+
__('The default store cannot be disabled')
86+
);
87+
}
7988
$storeModel->save();
80-
8189
$this->_objectManager->get('Magento\Store\Model\StoreManager')->reinitStores();
82-
8390
$this->_eventManager->dispatch($eventName, ['store' => $storeModel]);
84-
8591
$this->messageManager->addSuccess(__('You saved the store view.'));
8692
break;
8793
default:
@@ -106,4 +112,24 @@ public function execute()
106112
$redirectResult->setPath('adminhtml/*/');
107113
return $redirectResult;
108114
}
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+
}
109135
}

app/code/Magento/CatalogSearch/view/frontend/templates/advanced/form.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<?php $_code = $_attribute->getAttributeCode() ?>
2323
<div class="field <?php /* @escapeNotVerified */ echo $_code ?>">
2424
<label class="label" for="<?php /* @escapeNotVerified */ echo $_code ?>">
25-
<span><?php echo $block->escapeHtml($block->getAttributeLabel($_attribute)) ?></span>
25+
<span><?php echo $block->escapeHtml(__($block->getAttributeLabel($_attribute))) ?></span>
2626
</label>
2727
<div class="control">
2828
<?php switch ($block->getAttributeInputType($_attribute)):

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ define(
7979
isAddressDetailsVisible: quote.billingAddress() != null,
8080
isAddressFormVisible: !customer.isLoggedIn() || addressOptions.length == 1,
8181
isAddressSameAsShipping: false,
82-
saveInAddressBook: true
82+
saveInAddressBook: 1
8383
});
8484

8585
quote.billingAddress.subscribe(function (newAddress) {
@@ -95,7 +95,7 @@ define(
9595
if (newAddress != null && newAddress.saveInAddressBook !== undefined) {
9696
this.saveInAddressBook(newAddress.saveInAddressBook);
9797
} else {
98-
this.saveInAddressBook(true);
98+
this.saveInAddressBook(1);
9999
}
100100
this.isAddressDetailsVisible(true);
101101
}, this);
@@ -157,7 +157,7 @@ define(
157157
newBillingAddress;
158158

159159
if (customer.isLoggedIn() && !this.customerHasAddresses) {
160-
this.saveInAddressBook(true);
160+
this.saveInAddressBook(1);
161161
}
162162
addressData.save_in_address_book = this.saveInAddressBook();
163163
newBillingAddress = createBillingAddress(addressData);

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ define(
6767
isFormPopUpVisible: formPopUpState.isVisible,
6868
isFormInline: addressList().length == 0,
6969
isNewAddressAdded: ko.observable(false),
70-
saveInAddressBook: true,
70+
saveInAddressBook: 1,
7171
quoteIsVirtual: quote.isVirtual(),
7272

7373
/**
@@ -296,7 +296,7 @@ define(
296296
}
297297

298298
if (customer.isLoggedIn()) {
299-
shippingAddress.save_in_address_book = true;
299+
shippingAddress.save_in_address_book = 1;
300300
}
301301
selectShippingAddress(shippingAddress);
302302
}

app/code/Magento/Cms/Setup/InstallData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
336336
$content = preg_replace('/<li class="last">/ims', '<li>', $content);
337337
$replacment = '<li class="last privacy">' .
338338
"<a href=\"{{store direct_url=\"privacy-policy-cookie-restriction-mode\"}}\">" .
339-
"Privacy and Cookie Policy</a></li>\r\n</ul>";
339+
__('Privacy and Cookie Policy') . "</a></li>\r\n</ul>";
340340
$content = preg_replace('/<\\/ul>/ims', $replacment, $content);
341341
$footerLinksBlock->setContent($content)->save();
342342
}

app/code/Magento/Directory/Model/CountryInformationAcquirer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,17 @@ public function getCountryInfo($countryId)
9696
$store->getCode()
9797
);
9898

99-
$countries = $this->directoryHelper->getCountryCollection($store)->addCountryIdFilter($countryId)->load();
100-
if ($countries->count() == 0) {
99+
$countriesCollection = $this->directoryHelper->getCountryCollection($store)->load();
100+
$regions = $this->directoryHelper->getRegionData();
101+
$country = $countriesCollection->getItemById($countryId);
102+
103+
if (!$country) {
101104
throw new NoSuchEntityException(
102105
__(
103106
'Requested country is not available.'
104107
)
105108
);
106109
}
107-
$regions = $this->directoryHelper->getRegionData();
108-
$country = $countries->getItemById($countryId);
109110
$countryInfo = $this->setCountryInfo($country, $regions, $storeLocale);
110111

111112
return $countryInfo;
@@ -129,7 +130,6 @@ protected function setCountryInfo($country, $regions, $storeLocale)
129130
$countryInfo->setFullNameLocale($country->getName($storeLocale));
130131
$countryInfo->setFullNameEnglish($country->getName('en_US'));
131132

132-
133133
if (array_key_exists($countryId, $regions)) {
134134
$regionsInfo = [];
135135
foreach ($regions[$countryId] as $id => $regionData) {

app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function loadByStore($store = null)
143143
* Loads Item By Id
144144
*
145145
* @param string $countryId
146-
* @return \Magento\Directory\Model\ResourceModel\Country
146+
* @return \Magento\Directory\Model\ResourceModel\Country|null
147147
*/
148148
public function getItemById($countryId)
149149
{
@@ -152,7 +152,7 @@ public function getItemById($countryId)
152152
return $country;
153153
}
154154
}
155-
return $this->_countryFactory->create();
155+
return null;
156156
}
157157

158158
/**

app/code/Magento/Directory/Test/Unit/Model/CountryInformationAcquirerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ public function testGetCountryInfo()
129129
'',
130130
false
131131
);
132-
$countryCollection->expects($this->once())->method('addCountryIdFilter')->willReturnSelf();
133132
$countryCollection->expects($this->once())->method('load')->willReturnSelf();
134-
$countryCollection->expects($this->once())->method('count')->willReturn(1);
135133
$countryCollection->expects($this->once())->method('getItemById')->with('AE')->willReturn($testCountryInfo);
136134

137135
$this->directoryHelper->expects($this->once())->method('getCountryCollection')->willReturn($countryCollection);
@@ -174,11 +172,10 @@ public function testGetCountryInfoNotFound()
174172
'',
175173
false
176174
);
177-
$countryCollection->expects($this->once())->method('addCountryIdFilter')->willReturnSelf();
178175
$countryCollection->expects($this->once())->method('load')->willReturnSelf();
179-
$countryCollection->expects($this->once())->method('count')->willReturn(0);
180176

181177
$this->directoryHelper->expects($this->once())->method('getCountryCollection')->willReturn($countryCollection);
178+
$countryCollection->expects($this->once())->method('getItemById')->willReturn(null);
182179
$this->model->getCountryInfo('AE');
183180
}
184181
}

0 commit comments

Comments
 (0)