Skip to content

Commit

Permalink
SIM-1: Make sure base product shows up first.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirmorozov committed May 11, 2019
1 parent 73c39bf commit 843ce7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Helper/Api.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

namespace Morozov\Similarity\Helper;

class Api extends \Magento\Framework\App\Helper\AbstractHelper
{
const MASTER_URL = 'https://master.similarity.morozov.group/';
const PATH_REGIONS = 'api/regions';
const MASTER_URL = 'https://master.similarity.morozov.group/';
const PATH_REGIONS = 'api/regions';

const PATH_GET_UPSELLS = 'api/view/%s';
const PATH_REINDEX = 'api/reindex';
const PATH_REINDEX = 'api/reindex';

/**
* @var \Magento\Framework\App\ResourceConnection
Expand All @@ -29,7 +30,8 @@ public function __construct(
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Morozov\Similarity\Helper\Data $similarityHelper,
\Morozov\Similarity\Helper\Product $productHelper
) {
)
{
$this->resourceConnection = $resourceConnection;
$this->similarityHelper = $similarityHelper;
$this->productHelper = $productHelper;
Expand All @@ -41,7 +43,7 @@ public function __construct(
/**
* Service ==> Magento
*/
public function getUpSells($productId)
public function getUpSells($productId, $showTarget = true)
{
$url = $this->similarityHelper->getUrl() . sprintf(self::PATH_GET_UPSELLS, $productId);
$ctxParams = [];
Expand All @@ -63,7 +65,7 @@ public function getUpSells($productId)
$items = \Zend_Json::decode($response); // error
$tempArr = [];
foreach ($items as $item) {
if ($item[1] > 0.0000001) {
if ( $item[1] > 0.0000001 || $showTarget) {
$tempArr[$item[0][0]['entity_id']] = $item[0][0]['image'] . $item[1];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function aroundGetUpSellProductCollection(
{
if ($this->defaultHelper->canUse()) {
try {
if ($ids = $this->apiHelper->getUpSells($product->getEntityId())) {
if ($ids = $this->apiHelper->getUpSells($product->getEntityId(), false)) {
$productCollection = $this->collectionFactory->create();
$productCollection
->addAttributeToFilter('entity_id', ['in' => $ids])
Expand Down

0 comments on commit 843ce7a

Please sign in to comment.