Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-99645
Browse files Browse the repository at this point in the history
  • Loading branch information
slavvka committed May 14, 2019
2 parents 777ff40 + 3a49c28 commit 911f546
Show file tree
Hide file tree
Showing 18 changed files with 854 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminSlideOutDialogSection">
<element name="closeButton" type="button" selector=".modal-slide._show [data-role='closeBtn']" timeout="30"/>
<element name="closeButton" type="button" selector=".modal-slide._show [data-role=&quot;closeBtn&quot;]" timeout="30"/>
<element name="cancelButton" type="button" selector="//*[contains(@class, 'modal-slide') and contains(@class, '_show')]//*[contains(@class, 'page-actions')]//button[normalize-space(.)='Cancel']" timeout="30"/>
<element name="doneButton" type="button" selector="//*[contains(@class, 'modal-slide') and contains(@class, '_show')]//*[contains(@class, 'page-actions')]//button[normalize-space(.)='Done']" timeout="30"/>
<element name="saveButton" type="button" selector="//*[contains(@class, 'modal-slide') and contains(@class, '_show')]//*[contains(@class, 'page-actions')]//button[normalize-space(.)='Save']" timeout="30"/>
Expand Down
90 changes: 70 additions & 20 deletions app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1570,26 +1570,9 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType =
$this->_allIdsCache = null;

if (is_string($attribute) && $attribute == 'is_saleable') {
$columns = $this->getSelect()->getPart(\Magento\Framework\DB\Select::COLUMNS);
foreach ($columns as $columnEntry) {
list($correlationName, $column, $alias) = $columnEntry;
if ($alias == 'is_saleable') {
if ($column instanceof \Zend_Db_Expr) {
$field = $column;
} else {
$connection = $this->getSelect()->getConnection();
if (empty($correlationName)) {
$field = $connection->quoteColumnAs($column, $alias, true);
} else {
$field = $connection->quoteColumnAs([$correlationName, $column], $alias, true);
}
}
$this->getSelect()->where("{$field} = ?", $condition);
break;
}
}

return $this;
$this->addIsSaleableAttributeToFilter($condition);
} elseif (is_string($attribute) && $attribute == 'tier_price') {
$this->addTierPriceAttributeToFilter($attribute, $condition);
} else {
return parent::addAttributeToFilter($attribute, $condition, $joinType);
}
Expand Down Expand Up @@ -2469,4 +2452,71 @@ public function getPricesCount()

return $this->_pricesCount;
}

/**
* Add is_saleable attribute to filter
*
* @param array|null $condition
* @return $this
*/
private function addIsSaleableAttributeToFilter($condition)
{
$columns = $this->getSelect()->getPart(Select::COLUMNS);
foreach ($columns as $columnEntry) {
list($correlationName, $column, $alias) = $columnEntry;
if ($alias == 'is_saleable') {
if ($column instanceof \Zend_Db_Expr) {
$field = $column;
} else {
$connection = $this->getSelect()->getConnection();
if (empty($correlationName)) {
$field = $connection->quoteColumnAs($column, $alias, true);
} else {
$field = $connection->quoteColumnAs([$correlationName, $column], $alias, true);
}
}
$this->getSelect()->where("{$field} = ?", $condition);
break;
}
}

return $this;
}

/**
* Add tier price attribute to filter
*
* @param string $attribute
* @param array|null $condition
* @return $this
*/
private function addTierPriceAttributeToFilter($attribute, $condition)
{
$attrCode = $attribute;
$connection = $this->getConnection();
$attrTable = $this->_getAttributeTableAlias($attrCode);
$entity = $this->getEntity();
$fKey = 'e.' . $this->getEntityPkName($entity);
$pKey = $attrTable . '.' . $this->getEntityPkName($entity);
$attribute = $entity->getAttribute($attrCode);
$attrFieldName = $attrTable . '.value';
$fKey = $connection->quoteColumnAs($fKey, null);
$pKey = $connection->quoteColumnAs($pKey, null);

$condArr = ["{$pKey} = {$fKey}"];
$this->getSelect()->join(
[$attrTable => $this->getTable('catalog_product_entity_tier_price')],
'(' . implode(') AND (', $condArr) . ')',
[$attrCode => $attrFieldName]
);
$this->removeAttributeToSelect($attrCode);
$this->_filterAttributes[$attrCode] = $attribute->getId();
$this->_joinFields[$attrCode] = ['table' => '', 'field' => $attrFieldName];
$field = $this->_getAttributeTableAlias($attrCode) . '.value';
$conditionSql = $this->_getConditionSql($field, $condition);
$this->getSelect()->where($conditionSql, null, Select::TYPE_CONDITION);
$this->_totalRecords = null;

return $this;
}
}
21 changes: 21 additions & 0 deletions app/code/Magento/Cms/Test/Mftf/Data/WysiwygConfigData.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="WysiwygEnabledByDefault">
<data key="path">cms/wysiwyg/enabled</data>
<data key="scope_id">0</data>
<data key="value">enabled</data>
</entity>
<entity name="WysiwygDisabledByDefault">
<data key="path">cms/wysiwyg/enabled</data>
<data key="scope_id">0</data>
<data key="value">hidden</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StorefrontRegisterCustomerFromOrderSuccessPage">
<arguments>
<argument name="customer" />
</arguments>
<click selector="{{CheckoutSuccessRegisterSection.createAccountButton}}" stepKey="clickCreateAccountButton"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.passwordField}}" userInput="{{customer.password}}" stepKey="typePassword"/>
<fillField selector="{{StorefrontCustomerCreateFormSection.confirmPasswordField}}" userInput="{{customer.password}}" stepKey="typeConfirmationPassword"/>
<click selector="{{StorefrontCustomerCreateFormSection.createAccountButton}}" stepKey="clickOnCreateAccount"/>
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
<see selector="{{StorefrontMessagesSection.success}}" userInput="Thank you for registering" stepKey="verifyAccountCreated"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Downloadable\Observer;

use Magento\Downloadable\Model\ResourceModel\Link\Purchased\Collection as PurchasedCollection;
use Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

/**
* Assign Downloadable links to customer created after issuing guest order.
*/
class UpdateLinkPurchasedObserver implements ObserverInterface
{
/**
* Purchased links collection factory
*
* @var CollectionFactory
*/
private $purchasedCollectionFactory;

/**
* @param CollectionFactory $purchasedCollectionFactory
*/
public function __construct(
CollectionFactory $purchasedCollectionFactory
) {
$this->purchasedCollectionFactory = $purchasedCollectionFactory;
}

/**
* Link customer_id to downloadable link purchased after update order
*
* @param Observer $observer
* @return $this
*/
public function execute(Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$orderId = $order->getId();
$customerId = $order->getCustomerId();
if (!$orderId || !$customerId) {
return $this;
}
$purchasedLinksCollection = $this->getPurchasedCollection((int)$orderId);
foreach ($purchasedLinksCollection as $linkPurchased) {
$linkPurchased->setCustomerId($customerId)->save();
}

return $this;
}

/**
* Get purchased collection by order id
*
* @param int $orderId
* @return PurchasedCollection
*/
private function getPurchasedCollection(int $orderId): PurchasedCollection
{
return $this->purchasedCollectionFactory->create()->addFieldToFilter(
'order_id',
['eq' => $orderId]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StorefrontAssertDownloadableProductIsPresentInCustomerAccount">
<arguments>
<argument name="product"/>
</arguments>
<amOnPage url="{{StorefrontCustomerDownloadableProductsPage.url}}" stepKey="goToCustomerDownloadableProductsPage"/>
<seeElement selector="{{StorefrontCustomerDownloadableProductsSection.productName(product.name)}}" stepKey="seeStorefontDownloadableProductsProductName" />
</actionGroup>
</actionGroups>
21 changes: 21 additions & 0 deletions app/code/Magento/Downloadable/Test/Mftf/Data/CatalogConfigData.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="EnableGuestCheckoutWithDownloadableItems">
<data key="path">catalog/downloadable/disable_guest_checkout</data>
<data key="scope_id">0</data>
<data key="value">0</data>
</entity>
<entity name="DisableGuestCheckoutWithDownloadableItems">
<data key="path">catalog/downloadable/disable_guest_checkout</data>
<data key="scope_id">0</data>
<data key="value">1</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
<page name="StorefrontCustomerDownloadableProductsPage" url="downloadable/customer/products/" area="storefront" module="Magento_Downloadable">
<section name="StorefrontCustomerDownloadableProductsSection"/>
</page>
</pages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="StorefrontCustomerDownloadableProductsSection">
<element name="productName" type="text" selector="//table[@id='my-downloadable-products-table']//strong[contains(@class, 'product-name') and normalize-space(.)='{{productName}}']" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="LinkDownloadableProductFromGuestToCustomerTest">
<annotations>
<features value="Downloadable"/>
<stories value="Downloadable products in customer account"/>
<title value="Customer should see downloadable products after place order as guest and registering after that"/>
<description value="Verify that in 'My Downloadable Products' section in customer account user can see products."/>
<severity value="AVERAGE"/>
<useCaseId value="MAGETWO-98655"/>
<testCaseId value="MC-16148"/>
<group value="catalog"/>
<group value="downloadable"/>
</annotations>
<before>
<magentoCLI command="config:set {{EnableGuestCheckoutWithDownloadableItems.path}} {{EnableGuestCheckoutWithDownloadableItems.value}}" stepKey="enableGuestCheckoutWithDownloadableItems" />
<createData entity="ApiDownloadableProduct" stepKey="createProduct"/>
<createData entity="ApiDownloadableLink" stepKey="addDownloadableLink">
<requiredEntity createDataKey="createProduct"/>
</createData>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>
<after>
<magentoCLI command="config:set {{DisableGuestCheckoutWithDownloadableItems.path}} {{DisableGuestCheckoutWithDownloadableItems.value}}" stepKey="disableGuestCheckoutWithDownloadableItems" />
<deleteData stepKey="deleteProduct" createDataKey="createProduct"/>
<actionGroup ref="RemoveCustomerFromAdminActionGroup" stepKey="deleteCustomer">
<argument name="customer" value="Simple_US_NY_Customer"/>
</actionGroup>
<actionGroup ref="logout" stepKey="logout"/>
</after>
<!--Step 1: Go to Storefront as Guest-->
<actionGroup ref="CustomerLogoutStorefrontActionGroup" stepKey="logoutCustomer"/>
<!--Step 2: Add downloadable product to shopping cart-->
<amOnPage url="{{StorefrontProductPage.url($$createProduct.custom_attributes[url_key]$$)}}" stepKey="amOnStorefrontProductPage"/>
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
<argument name="product" value="$$createProduct$$"/>
<argument name="productCount" value="1"/>
</actionGroup>
<!--Step 3: Go to checkout-->
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart" />
<!--Step 4: Select Check/Money Order payment, fill required fields and click Update and Place Order-->
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyOrderPayment"/>
<actionGroup ref="GuestCheckoutFillNewBillingAddressActionGroup" stepKey="changeAddress">
<argument name="customerVar" value="Simple_US_NY_Customer"/>
<argument name="customerAddressVar" value="US_Address_NY"/>
</actionGroup>
<click selector="{{CheckoutPaymentSection.update}}" stepKey="clickUpdateButton" />
<waitForPageLoad stepKey="waitUpdateAddress"/>
<actionGroup ref="CheckoutPlaceOrderActionGroup" stepKey="placeOrder">
<argument name="orderNumberMessage" value="CONST.successGuestCheckoutOrderNumberMessage"/>
<argument name="emailYouMessage" value="CONST.successCheckoutEmailYouMessage" />
</actionGroup>
<!--Step 5: Create customer account after placing order-->
<actionGroup ref="StorefrontRegisterCustomerFromOrderSuccessPage" stepKey="createCustomerAfterPlaceOrder">
<argument name="customer" value="CustomerEntityOne"/>
</actionGroup>
<!--Step 6: Go To My Account -> My Downloadable Products and check if downloadable product link exist-->
<actionGroup ref="StorefrontAssertDownloadableProductIsPresentInCustomerAccount" stepKey="seeStorefontMyDownloadableProductsProductName">
<argument name="product" value="$$createProduct$$"/>
</actionGroup>
</test>
</tests>
1 change: 1 addition & 0 deletions app/code/Magento/Downloadable/etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</event>
<event name="sales_order_save_after">
<observer name="downloadable_observer" instance="Magento\Downloadable\Observer\SetLinkStatusObserver" />
<observer name="downloadable_observer_assign_customer" instance="Magento\Downloadable\Observer\UpdateLinkPurchasedObserver" />
</event>
<event name="sales_model_service_quote_submit_success">
<observer name="checkout_type_onepage_save_order_after" instance="Magento\Downloadable\Observer\SetHasDownloadableProductsObserver" />
Expand Down
Loading

0 comments on commit 911f546

Please sign in to comment.