Skip to content

Commit

Permalink
Merge pull request #5317 from magento-tsg-csl3/2.4-develop-pr13
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr13)
  • Loading branch information
zakdma authored Feb 13, 2020
2 parents 9e9703a + 3c84234 commit 293cd41
Show file tree
Hide file tree
Showing 16 changed files with 584 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ define([
options.bin = context.paymentPayload.details.bin;
}

if (shippingAddress) {
if (shippingAddress && this.isValidShippingAddress(shippingAddress)) {
options.additionalInformation = {
shippingGivenName: shippingAddress.firstname,
shippingSurname: shippingAddress.lastname,
Expand Down Expand Up @@ -206,6 +206,25 @@ define([
}

return false;
},

/**
* Validate shipping address
*
* @param {Object} shippingAddress
* @return {Boolean}
*/
isValidShippingAddress: function (shippingAddress) {
var isValid = false;

// check that required fields are not empty
if (shippingAddress.firstname && shippingAddress.lastname && shippingAddress.telephone &&
shippingAddress.street && shippingAddress.city && shippingAddress.regionCode &&
shippingAddress.postcode && shippingAddress.countryId) {
isValid = true;
}

return isValid;
}
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ define(
})
.then(function (hostedFieldsInstance) {
self.hostedFieldsInstance = hostedFieldsInstance;
self.isPlaceOrderActionAllowed(true);
self.isPlaceOrderActionAllowed(false);
self.initFormValidationEvents(hostedFieldsInstance);

return self.hostedFieldsInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<createData entity="Simple_US_Customer" stepKey="customer"/>
<!--Login as admin-->
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>
<createData entity="CustomerAccountSharingGlobal" stepKey="setConfigCustomerAccountToGlobal"/>
</before>

<!--Create website, Sore adn Store View-->
Expand Down Expand Up @@ -328,6 +329,7 @@
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="DeleteWebsite">
<argument name="websiteName" value="secondWebsite"/>
</actionGroup>
<createData entity="CustomerAccountSharingDefault" stepKey="setConfigCustomerAccountDefault"/>
<actionGroup ref="logout" stepKey="logout"/>

<!--Do reindex and flush cache-->
Expand Down
17 changes: 5 additions & 12 deletions app/code/Magento/Cms/Model/ResourceModel/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,9 @@ public function getIsUniqueBlockToStores(AbstractModel $object)
$entityMetadata = $this->metadataPool->getMetadata(BlockInterface::class);
$linkField = $entityMetadata->getLinkField();

$stores = (array)$object->getData('store_id');
$isDefaultStore = $this->_storeManager->isSingleStoreMode()
|| array_search(Store::DEFAULT_STORE_ID, $stores) !== false;

if (!$isDefaultStore) {
$stores[] = Store::DEFAULT_STORE_ID;
}
$stores = $this->_storeManager->isSingleStoreMode()
? [Store::DEFAULT_STORE_ID]
: (array)$object->getData('store_id');

$select = $this->getConnection()->select()
->from(['cb' => $this->getMainTable()])
Expand All @@ -200,11 +196,8 @@ public function getIsUniqueBlockToStores(AbstractModel $object)
'cb.' . $linkField . ' = cbs.' . $linkField,
[]
)
->where('cb.identifier = ? ', $object->getData('identifier'));

if (!$isDefaultStore) {
$select->where('cbs.store_id IN (?)', $stores);
}
->where('cb.identifier = ? ', $object->getData('identifier'))
->where('cbs.store_id IN (?)', $stores);

if ($object->getId()) {
$select->where('cb.' . $entityMetadata->getIdentifierField() . ' <> ?', $object->getId());
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Cms/Test/Mftf/Test/CheckStaticBlocksTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,23 @@
<seeInCurrentUrl url="cms/block/new" stepKey="VerifyNewBlockPageIsOpened1"/>
<!--Add new BLock with the same data-->
<actionGroup ref="FillOutBlockContent" stepKey="FillOutBlockContent1"/>
<selectOption selector="{{BlockNewPageBasicFieldsSection.storeView}}" userInput="Default Store View" stepKey="selectDefaultStoreView" />
<selectOption selector="{{BlockNewPageBasicFieldsSection.storeView}}" userInput="{{customStore.name}}" stepKey="selectSecondStoreView1" />
<click selector="{{BlockNewPagePageActionsSection.saveBlock}}" stepKey="ClickToSaveBlock1"/>
<waitForPageLoad stepKey="waitForPageLoad6"/>
<!--Verify that corresponding message is displayed-->
<see userInput="A block identifier with the same properties already exists in the selected store." stepKey="VerifyBlockIsSaved1"/>
<!--Click to go back and add new block-->
<click selector="{{BlockNewPagePageActionsSection.back}}" stepKey="ClickToGoBack1"/>
<waitForPageLoad stepKey="waitForPageLoad7"/>
<click selector="{{BlockPageActionsSection.addNewBlock}}" stepKey="ClickToAddNewBlock2"/>
<waitForPageLoad stepKey="waitForPageLoad8"/>
<seeInCurrentUrl url="cms/block/new" stepKey="VerifyNewBlockPageIsOpened2"/>
<!--Add new BLock with the same data for another store view-->
<actionGroup ref="FillOutBlockContent" stepKey="FillOutBlockContent2"/>
<selectOption selector="{{BlockNewPageBasicFieldsSection.storeView}}" userInput="Default Store View" stepKey="selectDefaultStoreView" />
<selectOption selector="{{BlockNewPageBasicFieldsSection.storeView}}" userInput="{{customStore.name}}" stepKey="selectSecondStoreView1" />
<click selector="{{BlockNewPagePageActionsSection.saveBlock}}" stepKey="ClickToSaveBlock2"/>
<waitForPageLoad stepKey="waitForPageLoad9"/>
<see userInput="You saved the block." stepKey="VerifyBlockIsSaved2"/>

<after>
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="DeleteWebsite">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,14 @@ public function execute()
['customer' => $customer, 'request' => $this->getRequest()]
);

if (isset($customerData['sendemail_store_id'])) {
if (isset($customerData['sendemail_store_id']) && $customerData['sendemail_store_id'] !== false) {
$customer->setStoreId($customerData['sendemail_store_id']);
try {
$this->customerAccountManagement->validateCustomerStoreIdByWebsiteId($customer);
} catch (LocalizedException $exception) {
throw new LocalizedException(__("The Store View selected for sending Welcome email from".
" is not related to the customer's associated website."));
}
}

// Save customer
Expand Down
24 changes: 18 additions & 6 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
if ($customer->getId()) {
$customer = $this->customerRepository->get($customer->getEmail());
$websiteId = $customer->getWebsiteId();

if ($this->isCustomerInStore($websiteId, $customer->getStoreId())) {
throw new InputException(__('This customer already exists in this store.'));
}
Expand All @@ -896,13 +895,10 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
$customer->setWebsiteId($websiteId);
}

$this->validateCustomerStoreIdByWebsiteId($customer);

// Update 'created_in' value with actual store name
if ($customer->getId() === null) {
$websiteId = $customer->getWebsiteId();
if ($websiteId && !$this->isCustomerInStore($websiteId, $customer->getStoreId())) {
throw new LocalizedException(__('The store view is not in the associated website.'));
}

$storeName = $this->storeManager->getStore($customer->getStoreId())->getName();
$customer->setCreatedIn($storeName);
}
Expand Down Expand Up @@ -1144,6 +1140,22 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
return in_array($storeId, $ids);
}

/**
* Validate customer store id by customer website id.
*
* @param CustomerInterface $customer
* @return bool
* @throws LocalizedException
*/
public function validateCustomerStoreIdByWebsiteId(CustomerInterface $customer)
{
if (!$this->isCustomerInStore($customer->getWebsiteId(), $customer->getStoreId())) {
throw new LocalizedException(__('The store view is not in the associated website.'));
}

return true;
}

/**
* Validate the Reset Password Token for a customer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ protected function setUp()
->getMock();
$this->managementMock = $this->getMockBuilder(AccountManagement::class)
->disableOriginalConstructor()
->setMethods(['createAccount'])
->setMethods(['createAccount', 'validateCustomerStoreIdByWebsiteId'])
->getMock();
$this->addressDataFactoryMock = $this->getMockBuilder(AddressInterfaceFactory::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -522,6 +522,9 @@ public function testExecuteWithExistentCustomer()
->with('customer/*/edit', ['id' => $customerId, '_current' => true])
->willReturn(true);

$this->managementMock->method('validateCustomerStoreIdByWebsiteId')
->willReturn(true);

$this->assertEquals($redirectMock, $this->model->execute());
}

Expand Down
Loading

0 comments on commit 293cd41

Please sign in to comment.