Skip to content

Commit

Permalink
Merge pull request #4067 from magento-epam/EPAM-PR-51
Browse files Browse the repository at this point in the history
- fixed  MAGETWO-64260: Performance for grouped products with large # of options
- fixed MAGETWO-98522: Adding out of stock items to comparison shows the success message but fails
- fixed MAGETWO-98584: Google chart API used by Magento dashboard scheduled to be turned off
- fixed MAGETWO-98947: UPS CGI url gateway to migrate from http to https
  • Loading branch information
irenelagno authored Apr 18, 2019
2 parents 729650d + 842442e commit 6cc245b
Show file tree
Hide file tree
Showing 21 changed files with 658 additions and 241 deletions.
159 changes: 66 additions & 93 deletions app/code/Magento/Backend/Block/Dashboard/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backend\Block\Dashboard;

/**
Expand All @@ -15,7 +17,7 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
/**
* Api URL
*/
const API_URL = 'http://chart.apis.google.com/chart';
const API_URL = 'https://image-charts.com/chart';

/**
* All series
Expand Down Expand Up @@ -76,6 +78,7 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
/**
* Google chart api data encoding
*
* @deprecated since the Google Image Charts API not accessible from March 14, 2019
* @var string
*/
protected $_encoding = 'e';
Expand Down Expand Up @@ -187,11 +190,12 @@ public function getChartUrl($directUrl = true)
{
$params = [
'cht' => 'lc',
'chf' => 'bg,s,ffffff',
'chco' => 'ef672f',
'chls' => '7',
'chxs' => '0,676056,15,0,l,676056|1,676056,15,0,l,676056',
'chm' => 'h,f2ebde,0,0:1:.1,1,-1',
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
'chm' => 'B,f4d4b2,0,0,0',
'chco' => 'db4814',
'chxs' => '0,0,11|1,0,11',
'chma' => '15,15,15,15'
];

$this->_allSeries = $this->getRowsData($this->_dataRows);
Expand Down Expand Up @@ -279,20 +283,11 @@ public function getChartUrl($directUrl = true)
$this->_axisLabels['x'] = $dates;
$this->_allSeries = $datas;

//Google encoding values
if ($this->_encoding == "s") {
// simple encoding
$params['chd'] = "s:";
$dataDelimiter = "";
$dataSetdelimiter = ",";
$dataMissing = "_";
} else {
// extended encoding
$params['chd'] = "e:";
$dataDelimiter = "";
$dataSetdelimiter = ",";
$dataMissing = "__";
}
// Image-Charts Awesome data format values
$params['chd'] = "a:";
$dataDelimiter = ",";
$dataSetdelimiter = "|";
$dataMissing = "_";

// process each string in the array, and find the max length
$localmaxvalue = [0];
Expand All @@ -306,7 +301,6 @@ public function getChartUrl($directUrl = true)
$minvalue = min($localminvalue);

// default values
$yrange = 0;
$yLabels = [];
$miny = 0;
$maxy = 0;
Expand All @@ -321,52 +315,21 @@ public function getChartUrl($directUrl = true)
$maxy = ceil($maxvalue + 1);
$yLabels = range($miny, $maxy, 1);
}
$yrange = $maxy;
$yorigin = 0;
}

$chartdata = [];

foreach ($this->getAllSeries() as $index => $serie) {
$thisdataarray = $serie;
if ($this->_encoding == "s") {
// SIMPLE ENCODING
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
$currentvalue = $thisdataarray[$j];
if (is_numeric($currentvalue)) {
$ylocation = round(
(strlen($this->_simpleEncoding) - 1) * ($yorigin + $currentvalue) / $yrange
);
$chartdata[] = substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter;
} else {
$chartdata[] = $dataMissing . $dataDelimiter;
}
}
} else {
// EXTENDED ENCODING
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
$currentvalue = $thisdataarray[$j];
if (is_numeric($currentvalue)) {
if ($yrange) {
$ylocation = 4095 * ($yorigin + $currentvalue) / $yrange;
} else {
$ylocation = 0;
}
$firstchar = floor($ylocation / 64);
$secondchar = $ylocation % 64;
$mappedchar = substr(
$this->_extendedEncoding,
$firstchar,
1
) . substr(
$this->_extendedEncoding,
$secondchar,
1
);
$chartdata[] = $mappedchar . $dataDelimiter;
} else {
$chartdata[] = $dataMissing . $dataDelimiter;
}
$count = count($thisdataarray);
for ($j = 0; $j < $count; $j++) {
$currentvalue = $thisdataarray[$j];
if (is_numeric($currentvalue)) {
$ylocation = $yorigin + $currentvalue;
$chartdata[] = $ylocation . $dataDelimiter;
} else {
$chartdata[] = $dataMissing . $dataDelimiter;
}
}
$chartdata[] = $dataSetdelimiter;
Expand All @@ -381,45 +344,13 @@ public function getChartUrl($directUrl = true)

$valueBuffer = [];

if (sizeof($this->_axisLabels) > 0) {
if (count($this->_axisLabels) > 0) {
$params['chxt'] = implode(',', array_keys($this->_axisLabels));
$indexid = 0;
foreach ($this->_axisLabels as $idx => $labels) {
if ($idx == 'x') {
/**
* Format date
*/
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
if ($_label != '') {
$period = new \DateTime($_label, new \DateTimeZone($timezoneLocal));
switch ($this->getDataHelper()->getParam('period')) {
case '24h':
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
$period->setTime($period->format('H'), 0, 0),
\IntlDateFormatter::NONE,
\IntlDateFormatter::SHORT
);
break;
case '7d':
case '1m':
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
$period,
\IntlDateFormatter::SHORT,
\IntlDateFormatter::NONE
);
break;
case '1y':
case '2y':
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
break;
}
} else {
$this->_axisLabels[$idx][$_index] = '';
}
}

$this->formatAxisLabelDate($idx, $timezoneLocal);
$tmpstring = implode('|', $this->_axisLabels[$idx]);

$valueBuffer[] = $indexid . ":|" . $tmpstring;
} elseif ($idx == 'y') {
$valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
Expand Down Expand Up @@ -447,6 +378,46 @@ public function getChartUrl($directUrl = true)
}
}

/**
* Format dates for axis labels
*
* @param string $idx
* @param string $timezoneLocal
*
* @return void
*/
private function formatAxisLabelDate($idx, $timezoneLocal)
{
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
if ($_label != '') {
$period = new \DateTime($_label, new \DateTimeZone($timezoneLocal));
switch ($this->getDataHelper()->getParam('period')) {
case '24h':
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
$period->setTime($period->format('H'), 0, 0),
\IntlDateFormatter::NONE,
\IntlDateFormatter::SHORT
);
break;
case '7d':
case '1m':
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
$period,
\IntlDateFormatter::SHORT,
\IntlDateFormatter::NONE
);
break;
case '1y':
case '2y':
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
break;
}
} else {
$this->_axisLabels[$idx][$_index] = '';
}
}
}

/**
* Get rows data
*
Expand Down Expand Up @@ -540,6 +511,8 @@ protected function getHeight()
}

/**
* Sets data helper
*
* @param \Magento\Backend\Helper\Dashboard\AbstractDashboard $dataHelper
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?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="AddOutOfStockProductToCompareListTest">
<annotations>
<features value="Catalog"/>
<title value="Add out of stock product to compare list"/>
<description value="Add out of stock product to compare list"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-98644"/>
<useCaseId value="MAGETWO-98522"/>
<group value="Catalog"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 0" stepKey="displayOutOfStockNo"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
<createData entity="SimpleSubCategory" stepKey="category"/>
<createData entity="SimpleProduct4" stepKey="product">
<requiredEntity createDataKey="category"/>
</createData>
</before>
<after>
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 0" stepKey="displayOutOfStockNo2"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
<deleteData createDataKey="product" stepKey="deleteProduct"/>
<deleteData createDataKey="category" stepKey="deleteCategory"/>
<actionGroup ref="logout" stepKey="logout"/>
</after>
<!--Open product page-->
<comment userInput="Open product page" stepKey="openProdPage"/>
<amOnPage url="{{StorefrontProductPage.url($$product.name$$)}}" stepKey="goToSimpleProductPage"/>
<waitForPageLoad stepKey="waitForSimpleProductPage"/>
<!--'Add to compare' link is not available-->
<comment userInput="'Add to compare' link is not available" stepKey="addToCompareLinkAvailability"/>
<dontSeeElement selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="dontSeeAddToCompareLink"/>
<!--Turn on 'out on stock' config-->
<comment userInput="Turn on 'out of stock' config" stepKey="onOutOfStockConfig"/>
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 1" stepKey="displayOutOfStockYes"/>
<!--Clear cache and reindex-->
<comment userInput="Clear cache and reindex" stepKey="cleanCache"/>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
<!--Open product page-->
<comment userInput="Open product page" stepKey="openProductPage"/>
<amOnPage url="{{StorefrontProductPage.url($$product.name$$)}}" stepKey="goToSimpleProductPage2"/>
<waitForPageLoad stepKey="waitForSimpleProductPage2"/>
<!--Click on 'Add to Compare' link-->
<comment userInput="Click on 'Add to Compare' link" stepKey="clickOnAddToCompareLink"/>
<click selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="clickOnAddToCompare"/>
<waitForPageLoad stepKey="waitForProdAddToCmpList"/>
<!--Assert success message-->
<comment userInput="Assert success message" stepKey="assertSuccessMsg"/>
<grabTextFrom selector="{{AdminProductMessagesSection.successMessage}}" stepKey="grabTextFromSuccessMessage"/>
<assertEquals expected='You added product $$product.name$$ to the comparison list.' expectedType="string" actual="($grabTextFromSuccessMessage)" stepKey="assertSuccessMessage"/>
<!--See product in the comparison list-->
<comment userInput="See product in the comparison list" stepKey="seeProductInComparisonList"/>
<amOnPage url="{{StorefrontProductComparePage.url}}" stepKey="navigateToComparePage"/>
<waitForPageLoad stepKey="waitForStorefrontProductComparePageLoad"/>
<seeElement selector="{{StorefrontProductCompareMainSection.ProductLinkByName($product.name$)}}" stepKey="seeProductInCompareList"/>
<!--Go to Category page and delete product from comparison list-->
<comment userInput="Go to Category page and delete prduct from comparison list" stepKey="deletProdFromCmpList"/>
<amOnPage url="{{StorefrontCategoryPage.url($$category.name$$)}}" stepKey="onCategoryPage"/>
<waitForPageLoad time="30" stepKey="waitForPageLoad1"/>
<click selector="{{StorefrontComparisonSidebarSection.ClearAll}}" stepKey="clickClearAll"/>
<waitForPageLoad time="30" stepKey="waitForConfirmPageLoad"/>
<click selector="{{AdminDeleteRoleSection.confirm}}" stepKey="confirmProdDelate"/>
<waitForPageLoad time="30" stepKey="waitForConfirmLoad"/>
<!--Add product to compare list from Category page-->
<comment userInput="Add product to compare list fom Category page" stepKey="addToCmpFromCategPage"/>
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverOverProduct"/>
<click selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="clickAddToCompare"/>
<waitForPageLoad stepKey="waitProdAddingToCmpList"/>
<!--Assert success message-->
<comment userInput="Assert success message" stepKey="assertSuccessMsg2"/>
<grabTextFrom selector="{{AdminProductMessagesSection.successMessage}}" stepKey="grabTextFromSuccessMessage2"/>
<assertEquals expected='You added product $$product.name$$ to the comparison list.' expectedType="string" actual="($grabTextFromSuccessMessage)" stepKey="assertSuccessMessage2"/>
<!--Check that product displays on add to compare widget-->
<comment userInput="Check that product displays on add to compare widget" stepKey="checkProdNameOnWidget"/>
<seeElement selector="{{StorefrontComparisonSidebarSection.ProductTitleByName($$product.name$$)}}" stepKey="seeProdNameOnCmpWidget"/>
<!--See product in the compare page-->
<comment userInput="See product in the compare page" stepKey="seeProductInComparePage"/>
<amOnPage url="{{StorefrontProductComparePage.url}}" stepKey="navigateToComparePage2"/>
<waitForPageLoad stepKey="waitForStorefrontProductComparePageLoad2"/>
<seeElement selector="{{StorefrontProductCompareMainSection.ProductLinkByName($product.name$)}}" stepKey="seeProductInCompareList2"/>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\ViewModel\Product\Checker;

use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\StockConfigurationInterface;

/**
* Check is available add to compare.
*/
class AddToCompareAvailability implements ArgumentInterface
{
/**
* @var StockConfigurationInterface
*/
private $stockConfiguration;

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

/**
* Is product available for comparison.
*
* @param ProductInterface $product
* @return bool
*/
public function isAvailableForCompare(ProductInterface $product): bool
{
return $this->isInStock($product) || $this->stockConfiguration->isShowOutOfStock();
}

/**
* Get is in stock status.
*
* @param ProductInterface $product
* @return bool
*/
private function isInStock(ProductInterface $product): bool
{
$quantityAndStockStatus = $product->getQuantityAndStockStatus();
if (!$quantityAndStockStatus) {
return $product->isSalable();
}

return isset($quantityAndStockStatus['is_in_stock']) && $quantityAndStockStatus['is_in_stock'];
}
}
Loading

0 comments on commit 6cc245b

Please sign in to comment.