Skip to content

Commit

Permalink
- fix cart price for configurable products
Browse files Browse the repository at this point in the history
- get full category path
  • Loading branch information
bnayalivne committed Mar 1, 2018
1 parent a3b5af6 commit 7823594
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 22 deletions.
10 changes: 7 additions & 3 deletions Controller/Adminhtml/Install/Reinstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@

use \Magento\Backend\App\Action\Context;
use \Magento\Framework\View\Result\PageFactory;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use \Remarkety\Mgconnector\Model\Install as InstallModel;

class Reinstall extends \Magento\Backend\App\Action
{
protected $resultPageFactory;
protected $installModel;
private $configHelper;

public function __construct(Context $context,
PageFactory $resultPageFactory,
InstallModel $installModel,
\Magento\Config\Model\ResourceModel\Config $resourceConfig,
\Magento\Store\Model\StoreManager $storeManager,
\Magento\Customer\Model\Session $customerSession
\Magento\Customer\Model\Session $customerSession,
ConfigHelper $configHelper
){
parent::__construct($context);
$this->installModel = $installModel;
Expand All @@ -32,7 +35,7 @@ public function __construct(Context $context,
$this->config = $resourceConfig;
$this->storeManager = $storeManager;
$this->session = $customerSession;

$this->configHelper = $configHelper;


}
Expand All @@ -46,6 +49,7 @@ public function execute()
->deleteConfig('remarkety/mgconnector/intervals', 'default',0)
->deleteConfig('remarkety/mgconnector/last_response_status', 'default',0)
->deleteConfig('remarkety/mgconnector/last_response_message', 'default',0);
$this->configHelper->setCategoriesFullPath($this->configHelper->useCategoriesFullPath());

foreach ($this->storeManager->getWebsites() as $_website) {
foreach ($_website->getGroups() as $_group) {
Expand All @@ -63,4 +67,4 @@ public function execute()

$this->_redirect('*/install/install', array('mode' => 'install_create'));
}
}
}
20 changes: 20 additions & 0 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class ConfigHelper
const WEBHOOKS_ENABLED = 'remarkety/mgconnector/webhooks';
const PRODUCT_WEBHOOKS_DISABLED = 'remarkety/mgconnector/product_webhooks_disable';
const FORCE_ASYNC_WEBHOOKS = 'remarkety/mgconnector/forceasyncwebhooks';
const USE_CATEGORIES_FULL_PATH = 'remarkety/mgconnector/categories_full_path';

protected $_activeStore;
protected $_scopeConfig;
protected $configResource;
protected $cacheTypeList;
private $_useCategoriesFullPath = null;

public function __construct(
ScopeConfigInterface $scopeConfig,
Expand Down Expand Up @@ -86,4 +88,22 @@ public function setWebhooksGloballStatus($enabled){
);
$this->cacheTypeList->cleanType('config');
}

public function useCategoriesFullPath(){
if(is_null($this->_useCategoriesFullPath)) {
$fullPath = $this->_scopeConfig->getValue(self::USE_CATEGORIES_FULL_PATH);
$this->_useCategoriesFullPath = !empty($fullPath);
}
return $this->_useCategoriesFullPath;
}

public function setCategoriesFullPath($value = true){
$this->configResource->saveConfig(
self::USE_CATEGORIES_FULL_PATH,
$value ? 1 : 0,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
$this->cacheTypeList->cleanType('config');
}
}
29 changes: 27 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
protected $_catalogProductTypeConfigurable;
private $categoryMapCache = [];
protected $categoryFactory;
protected $configHelper;
public function __construct(\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\Module\ModuleResource $moduleResource,
\Magento\Integration\Model\Integration $integration,
Expand All @@ -22,7 +23,8 @@ public function __construct(\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Product\Gallery\GalleryManagement $galleryManagement,
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $catalogProductTypeConfigurable,
\Magento\Catalog\Model\CategoryFactory $categoryFactory
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
ConfigHelper $configHelper
){
$this->integration = $integration;
$this->moduleResource = $moduleResource;
Expand All @@ -32,6 +34,7 @@ public function __construct(\Magento\Framework\App\Helper\Context $context,
$this->galleryManagement = $galleryManagement;
$this->_catalogProductTypeConfigurable = $catalogProductTypeConfigurable;
$this->categoryFactory = $categoryFactory;
$this->configHelper = $configHelper;
parent::__construct($context);
}

Expand Down Expand Up @@ -139,11 +142,33 @@ public function getImage($product)
}
}

/**
* @param $category_id
* @return array|bool
*/
public function getCategory($category_id)
{
if (!isset($this->categoryMapCache[$category_id])) {
$fullPath = $this->configHelper->useCategoriesFullPath();
/**
* @var Category $category
*/
$category = $this->categoryFactory->create()->load($category_id);
$this->categoryMapCache[$category_id] = $category->getName();
if(!$fullPath){
$name = $category->getName();
} else {
$parents = $category->getParentCategories();
if(count($parents) > 0) {
$nameParts = [];
foreach ($parents as $parentCategory) {
$nameParts[] = $parentCategory->getName();
}
$name = implode(" / ", $nameParts);
} else {
$name = $category->getName();
}
}
$this->categoryMapCache[$category_id] = $name;
}
if (!isset($this->categoryMapCache[$category_id])) return false;

Expand Down
23 changes: 9 additions & 14 deletions Model/Api/Data.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
namespace Remarkety\Mgconnector\Model\Api;

use Magento\Catalog\Model\Category;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\DataObject;
use Magento\Quote\Model\Quote\Item;
use Remarkety\Mgconnector\Api\Data\QueueInterface;
use Remarkety\Mgconnector\Api\DataInterface;
use \Magento\Catalog\Model\ProductFactory;
Expand Down Expand Up @@ -453,7 +455,7 @@ public function getProducts(
$mappedArray = $row->getData();
if ($row->getCategoryIds()) {
foreach ($row->getCategoryIds() AS $category_id) {
$prod['categories'][] = $this->getCategory($category_id);
$prod['categories'][] = $this->dataHelper->getCategory($category_id);
}
}

Expand Down Expand Up @@ -558,17 +560,6 @@ private function loadProduct($product_id){
return $this->productRepository->getById($product_id);
}

public function getCategory($category_id)
{
if (!isset($this->categoryMapCache[$category_id])) {
$category = $this->categoryFactory->create()->load($category_id);
$this->categoryMapCache[$category_id] = $category->getName();
}
if (!isset($this->categoryMapCache[$category_id])) return false;

return ['code' => $category_id, 'name' => $this->categoryMapCache[$category_id]];
}

/**
* Get All products from catalog
*
Expand Down Expand Up @@ -1024,7 +1015,7 @@ public function getQuotes(

$itemArray = [];
foreach ($itemsCollection as $item) {
if (($item->getData('parent_item_id') || $item->getData('parent_item_id') == null) && $item->getData('product_type') == 'simple') {
if ($item->getProductType() == 'simple') {
$itemsData = $item->getData();
$itemData = [];
foreach ($map['carts']['line_items'] as $element => $value) {
Expand All @@ -1034,6 +1025,10 @@ public function getQuotes(
}
}
}
$parentItem = $item->getParentItem();
if($parentItem && $parentItem->getProductType() == Configurable::TYPE_CODE){
$itemData['price'] = $parentItem->getPrice();
}
$itemArray[] = $itemData;
}
}
Expand Down Expand Up @@ -1241,7 +1236,7 @@ public function setConfig($mage_store_id, $configName, $scope, $newValue)
*/
public function getVersion()
{
return '2.2.16';
return '2.2.17';
}

/**
Expand Down
12 changes: 11 additions & 1 deletion Model/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use \Magento\Authorization\Model\Role;
use \Magento\Authorization\Model\Rules;
use \Magento\Store\Model\Store;
use Remarkety\Mgconnector\Helper\ConfigHelper;
use \Remarkety\Mgconnector\Model\Request as MgconnectorRequest;
use \Remarkety\Mgconnector\Model\Webtracking;
use \Magento\Framework\UrlInterface;
Expand Down Expand Up @@ -348,7 +349,16 @@ protected function _markInstalled($storeId) {
if(!empty($response['storePublicId'])){
$this->_webtracking->setRemarketyPublicId($storeId, $response['storePublicId']);
}

//check if we should use full categories path
$use_full_cat_path = $this->scopeConfigInterface->getValue(ConfigHelper::USE_CATEGORIES_FULL_PATH);
if(is_null($use_full_cat_path)){
$this->_resourceConfig->saveConfig(
ConfigHelper::USE_CATEGORIES_FULL_PATH,
1,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
}
$this->_cache->cleanType('config');
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lib-libxml": "*"
},
"type": "magento2-module",
"version": "2.2.16",
"version": "2.2.17",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Remarkety_Mgconnector" setup_version="2.2.16">
<module name="Remarkety_Mgconnector" setup_version="2.2.17">
</module>
</config>

0 comments on commit 7823594

Please sign in to comment.