Skip to content

Commit

Permalink
Merge pull request #3244 from magento-epam/EPAM-PR-12
Browse files Browse the repository at this point in the history
[epam] MAGETWO-71375: [Magento Cloud] Zero Subtotal Orders have incorrect status
  • Loading branch information
rganin authored Oct 9, 2018
2 parents 80469a6 + 3880bce commit a474225
Show file tree
Hide file tree
Showing 31 changed files with 887 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public function getJsonConfig()
$configValue = $preConfiguredValues->getData('bundle_option/' . $optionId);
if ($configValue) {
$defaultValues[$optionId] = $configValue;
$configQty = $preConfiguredValues->getData('bundle_option_qty/' . $optionId);
if ($configQty) {
$options[$optionId]['selections'][$configValue]['qty'] = $configQty;
}
}
}
$position++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;

use Magento\Framework\App\ResourceConnection;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Store\Model\Store;

/**
* Flat item eraser. Used to clear items from the catalog flat table.
*/
class Eraser
{
/**
Expand Down Expand Up @@ -50,12 +55,7 @@ public function __construct(
*/
public function removeDeletedProducts(array &$ids, $storeId)
{
$select = $this->connection->select()->from(
$this->productIndexerHelper->getTable('catalog_product_entity')
)->where(
'entity_id IN(?)',
$ids
);
$select = $this->getSelectForProducts($ids);
$result = $this->connection->query($select);

$existentProducts = [];
Expand All @@ -69,6 +69,61 @@ public function removeDeletedProducts(array &$ids, $storeId)
$this->deleteProductsFromStore($productsToDelete, $storeId);
}

/**
* Remove products with "Disabled" status from the flat table(s).
*
* @param array $ids
* @param int $storeId
* @return void
*/
public function removeDisabledProducts(array &$ids, $storeId)
{
/* @var $statusAttribute \Magento\Eav\Model\Entity\Attribute */
$statusAttribute = $this->productIndexerHelper->getAttribute('status');

$select = $this->getSelectForProducts($ids);
$select->joinLeft(
['status_global_attr' => $statusAttribute->getBackendTable()],
' status_global_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
[]
);
$select->joinLeft(
['status_attr' => $statusAttribute->getBackendTable()],
' status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
. ' AND status_attr.store_id = ' . $storeId,
[]
);
$select->where('IFNULL(status_attr.value, status_global_attr.value) = ?', Status::STATUS_DISABLED);

$result = $this->connection->query($select);

$disabledProducts = [];
foreach ($result->fetchAll() as $product) {
$disabledProducts[] = $product['entity_id'];
}

if (!empty($disabledProducts)) {
$ids = array_diff($ids, $disabledProducts);
$this->deleteProductsFromStore($disabledProducts, $storeId);
}
}

/**
* Get Select object for existed products.
*
* @param array $ids
* @return \Magento\Framework\DB\Select
*/
private function getSelectForProducts(array $ids)
{
$productTable = $this->productIndexerHelper->getTable('catalog_product_entity');
$select = $this->connection->select()->from($productTable)
->columns('entity_id')
->where('entity_id IN(?)', $ids);
return $select;
}

/**
* Delete products from flat table(s)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function execute($id = null)
$tableExists = $this->_isFlatTableExists($store->getId());
if ($tableExists) {
$this->flatItemEraser->removeDeletedProducts($ids, $store->getId());
$this->flatItemEraser->removeDisabledProducts($ids, $store->getId());
}

/* @var $status \Magento\Eav\Model\Entity\Attribute */
Expand Down
34 changes: 22 additions & 12 deletions app/code/Magento/Catalog/Model/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\UrlRewrite\Model\UrlFinderInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
use Magento\Framework\App\Config\ScopeConfigInterface;

/**
* Product Url model
Expand Down Expand Up @@ -45,38 +46,37 @@ class Url extends \Magento\Framework\DataObject
*/
protected $urlFinder;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param \Magento\Framework\UrlFactory $urlFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Filter\FilterManager $filter
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
* @param UrlFinderInterface $urlFinder
* @param array $data
* @param ScopeConfigInterface|null $scopeConfig
*/
public function __construct(
\Magento\Framework\UrlFactory $urlFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Filter\FilterManager $filter,
\Magento\Framework\Session\SidResolverInterface $sidResolver,
UrlFinderInterface $urlFinder,
array $data = []
array $data = [],
ScopeConfigInterface $scopeConfig = null
) {
parent::__construct($data);
$this->urlFactory = $urlFactory;
$this->storeManager = $storeManager;
$this->filter = $filter;
$this->sidResolver = $sidResolver;
$this->urlFinder = $urlFinder;
}

/**
* Retrieve URL Instance
*
* @return \Magento\Framework\UrlInterface
*/
private function getUrlInstance()
{
return $this->urlFactory->create();
$this->scopeConfig = $scopeConfig ?:
\Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class);
}

/**
Expand Down Expand Up @@ -157,10 +157,19 @@ public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE,
UrlRewrite::STORE_ID => $storeId,
];
$useCategories = $this->scopeConfig->getValue(
\Magento\Catalog\Helper\Product::XML_PATH_PRODUCT_URL_USE_CATEGORY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

if ($categoryId) {
$filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;
} elseif (!$useCategories) {
$filterData[UrlRewrite::METADATA]['category_id'] = '';
}

$rewrite = $this->urlFinder->findOneByData($filterData);

if ($rewrite) {
$requestPath = $rewrite->getRequestPath();
$product->setRequestPath($requestPath);
Expand Down Expand Up @@ -194,6 +203,7 @@ public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
$routeParams['_query'] = [];
}

return $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
$url = $this->urlFactory->create()->setScope($storeId);
return $url->getUrl($routePath, $routeParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,13 @@ protected function _addUrlRewrite()
['cu' => $this->getTable('catalog_url_rewrite_product_category')],
'u.url_rewrite_id=cu.url_rewrite_id'
)->where('cu.category_id IN (?)', $this->_urlRewriteCategory);
} else {
$select->joinLeft(
['cu' => $this->getTable('catalog_url_rewrite_product_category')],
'u.url_rewrite_id=cu.url_rewrite_id'
)->where('cu.url_rewrite_id IS NULL');
}

// more priority is data with category id
$urlRewrites = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<element name="productStatusUseDefault" type="checkbox" selector="input[name='use_default[status]']"/>
<element name="productNameUseDefault" type="checkbox" selector="input[name='use_default[name]']"/>
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
<element name="productTaxClass" type="select" selector="//*[@name='product[tax_class_id]']"/>
<element name="productTaxClassUseDefault" type="checkbox" selector="input[name='use_default[tax_class_id]']"/>
<element name="advancedPricingLink" type="button" selector="button[data-index='advanced_pricing_button']"/>
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testRemoveDeletedProducts()
$productsToDeleteIds = [1, 2];
$select = $this->createMock(\Magento\Framework\DB\Select::class);
$select->expects($this->once())->method('from')->with('catalog_product_entity')->will($this->returnSelf());
$select->expects($this->once())->method('columns')->with('entity_id')->will($this->returnSelf());
$select->expects($this->once())->method('where')->with('entity_id IN(?)', $productsToDeleteIds)
->will($this->returnSelf());
$products = [['entity_id' => 2]];
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@
<backend_model>Magento\Catalog\Model\Indexer\Product\Flat\System\Config\Mode</backend_model>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="default_sort_by" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<field id="default_sort_by" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Product Listing Sort by</label>
<comment>Applies to category pages</comment>
<source_model>Magento\Catalog\Model\Config\Source\ListSort</source_model>
</field>
<field id="list_allow_all" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
<!--Fill shipment form for free shipping-->
<actionGroup name="ShipmentFormFreeShippingActionGroup">
<fillField selector="{{CheckoutShippingSection.email}}" userInput="{{CustomerEntityOne.email}}" stepKey="setCustomerEmail"/>
<fillField selector="{{CheckoutShippingSection.firstName}}" userInput="{{CustomerEntityOne.firstname}}" stepKey="SetCustomerFirstName"/>
<fillField selector="{{CheckoutShippingSection.lastName}}" userInput="{{CustomerEntityOne.lastname}}" stepKey="SetCustomerLastName"/>
<fillField selector="{{CheckoutShippingSection.street}}" userInput="{{CustomerAddressSimple.street}}" stepKey="SetCustomerStreetAddress"/>
<fillField selector="{{CheckoutShippingSection.city}}" userInput="{{CustomerAddressSimple.city}}" stepKey="SetCustomerCity"/>
<fillField selector="{{CheckoutShippingSection.postcode}}" userInput="{{CustomerAddressSimple.postcode}}" stepKey="SetCustomerZipCode"/>
<fillField selector="{{CheckoutShippingSection.telephone}}" userInput="{{CustomerAddressSimple.telephone}}" stepKey="SetCustomerPhoneNumber"/>
<click selector="{{CheckoutShippingSection.region}}" stepKey="clickToSetState"/>
<click selector="{{CheckoutShippingSection.state}}" stepKey="clickToChooseState"/>
<see userInput="$0.00 Free Free Shipping" selector="{{CheckoutShippingMethodsSection.shippingMethodRowByName('Free Shipping')}}" stepKey="seeShippingMethod" after="clickToChooseState"/>
<click selector="{{CheckoutShippingMethodsSection.checkShippingMethodByName('Free Shipping')}}" stepKey="selectFlatShippingMethod" after="seeShippingMethod"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask" after="selectFlatShippingMethod"/>
<click selector="{{CheckoutShippingSection.next}}" stepKey="clickToSaveShippingInfo"/>
<waitForPageLoad time="5" stepKey="waitForReviewAndPaymentsPageIsLoaded"/>
<seeInCurrentUrl url="payment" stepKey="reviewAndPaymentIsShown"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<element name="next" type="button" selector="button.button.action.continue.primary" timeout="30"/>
<element name="firstShippingMethod" type="radio" selector="//*[@id='checkout-shipping-method-load']//input[@class='radio']"/>
<element name="defaultShipping" type="button" selector=".billing-address-details"/>
<element name="state" type="button" selector="//*[text()='Alabama']"/>
<element name="stateInput" type="input" selector="input[name=region]"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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="ZeroSubtotalOrdersWithProcessingStatusTest">
<annotations>
<features value="Checkout"/>
<stories value="MAGETWO-71375: Zero Subtotal Orders have incorrect status"/>
<title value="Checking status of Zero Subtotal Orders with 'Processing' New Order Status"/>
<description value="Created order should be in Processing status"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-94178"/>
<group value="checkout"/>
</annotations>
<before>
<createData entity="SimpleSubCategory" stepKey="simplecategory"/>
<createData entity="SimpleProduct" stepKey="simpleproduct">
<requiredEntity createDataKey="simplecategory"/>
</createData>
<createData entity="PaymentMethodsSettingConfig" stepKey="paymentMethodsSettingConfig"/>
<createData entity="FreeShippingMethodsSettingConfig" stepKey="freeShippingMethodsSettingConfig"/>
<!--Go to Admin page-->
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>

<after>
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteSalesRule">
<argument name="ruleName" value="{{ApiSalesRule.name}}"/>
</actionGroup>
<createData entity="DefaultShippingMethodsConfig" stepKey="defaultShippingMethodsConfig"/>
<createData entity="DisableFreeShippingConfig" stepKey="disableFreeShippingConfig"/>
<createData entity="DisablePaymentMethodsSettingConfig" stepKey="disablePaymentMethodsSettingConfig"/>
<actionGroup ref="logout" stepKey="logout"/>
<deleteData createDataKey="simpleproduct" stepKey="deleteProduct"/>
<deleteData createDataKey="simplecategory" stepKey="deleteCategory"/>
</after>

<!--Open MARKETING > Cart Price Rules-->
<amOnPage url="{{AdminCartPriceRulesPage.url}}" stepKey="amOnCartPriceList"/>
<waitForPageLoad stepKey="waitForRulesPage"/>

<!--Add New Rule-->
<click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>
<fillField selector="{{AdminCartPriceRulesFormSection.ruleName}}" userInput="{{ApiSalesRule.name}}" stepKey="fillRuleName"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.websites}}" userInput="Main Website" stepKey="selectWebsite"/>
<actionGroup ref="selectNotLoggedInCustomerGroup" stepKey="chooseNotLoggedInCustomerGroup"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.coupon}}" userInput="Specific Coupon" stepKey="selectCouponType"/>
<fillField selector="{{AdminCartPriceRulesFormSection.couponCode}}" userInput="{{_defaultCoupon.code}}" stepKey="fillCouponCode"/>
<fillField selector="{{AdminCartPriceRulesFormSection.userPerCoupon}}" userInput="99" stepKey="fillUserPerCoupon"/>
<click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Percent of product price discount" stepKey="selectActionType"/>
<fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="100" stepKey="fillDiscountAmount"/>
<click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/>
<see selector="{{AdminCartPriceRulesSection.messages}}" userInput="You saved the rule." stepKey="seeSuccessMessage"/>

<!--Proceed to store front and place an order with free shipping using created coupon-->
<!--Add product to card-->
<actionGroup ref="AddSimpleProductToCart" stepKey="AddProductToCard">
<argument name="product" value="$$simpleproduct$$"/>
</actionGroup>

<!--Proceed to shipment-->
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickToOpenCard"/>
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="clickToProceedToCheckout"/>
<waitForPageLoad stepKey="waitForTheFormIsOpened"/>

<!--Fill shipping form-->
<actionGroup ref="ShipmentFormFreeShippingActionGroup" stepKey="shipmentFormFreeShippingActionGroup"/>

<click selector="{{DiscountSection.DiscountTab}}" stepKey="clickToAddDiscount"/>
<fillField selector="{{DiscountSection.DiscountInput}}" userInput="{{_defaultCoupon.code}}" stepKey="TypeDiscountCode"/>
<click selector="{{DiscountSection.ApplyCodeBtn}}" stepKey="clickToApplyDiscount"/>
<waitForPageLoad stepKey="WaitForDiscountToBeAdded"/>
<see userInput="Your coupon was successfully applied." stepKey="verifyText"/>

<waitForElement selector="{{CheckoutPaymentSection.placeOrder}}" time="30" stepKey="waitForPlaceOrderButton"/>
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber}}" stepKey="grabOrderNumber"/>

<!--Proceed to Admin panel > SALES > Orders. Created order should be in Processing status-->
<amOnPage url="/admin/sales/order/" stepKey="navigateToSalesOrderPage"/>
<waitForPageLoad stepKey="waitForSalesOrderPageLoaded"/>

<!-- Open Order -->
<actionGroup ref="filterOrderGridById" stepKey="filterOrderGridById">
<argument name="orderId" value="$grabOrderNumber"/>
</actionGroup>
<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForCreatedOrderPageOpened"/>

<!--Verify that Created order is in Processing status-->
<see selector="{{AdminShipmentOrderInformationSection.orderStatus}}" userInput="Processing" stepKey="seeShipmentOrderStatus"/>
</test>
</tests>
Loading

0 comments on commit a474225

Please sign in to comment.