#StackBounty: #magento2 Magento 2 catalog_product_get_final_price event not working for configurable product

Bounty: 50

I have to set the product price to a custom value depends up on the customer. So I have written an event catalog_product_get_final_price and in the observer I have set the custom price for the product. But this is working only for “Simple Product” (visibility both). When I view the configurable product nothing is happened. Even I have write a die() in the observer and it is working when I view the Simple product but not for the configurable product. That means when I view the configurable product, the event is not triggering.

How can I set the simple product’s price to a custom value using event? I need this for the “listing” and “view page”


Get this bounty!!!

#StackBounty: #magento2 #cache How did these theme developers manage to not use cache on their MegaMenu?

Bounty: 50

These theme developers are not caching this block and creating performance issues for hundreds if not thousands of Magento 2 sites.

The megamenu implementation is not being cached, why is this?

topmenu.phtml

    <?php
        $_helper = $this->helper('ClumsywaveMegaHelperData');
        $_config = $_helper->getConfig('cw_mega');
        $columnsLimit = 0;
        $header_type = $_helper->getConfig('clumsy_settings/header/header_type');

        if($_config['general']['enable']) {
    ?>
<?php $_menu = $block->getMegamenuHtml(); ?>

<nav class="navigation sw-megamenu <?php if($header_type == 8 || $header_type == 10): ?>side-megamenu<?php endif; ?>" role="navigation">
    <ul>
        <?php echo $_menu; ?>
    </ul>
</nav>

ClumsywaveMegaBlockTopmenu.php

class Topmenu extends MagentoFrameworkViewElementTemplate
{

    protected $_categoryHelper;
    protected $_categoryFlatConfig;
    protected $_topMenu;
    protected $_categoryFactory;
    protected $_helper;
    protected $_filterProvider;
    protected $_blockFactory;
    protected $_megamenuConfig;
    protected $_storeManager;

    public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoCatalogHelperCategory $categoryHelper,
        ClumsywaveMegaHelperData $helper,
        MagentoCatalogModelIndexerCategoryFlatState $categoryFlatState,
        MagentoCatalogModelCategoryFactory $categoryFactory,
        MagentoThemeBlockHtmlTopmenu $topMenu,
        MagentoCmsModelTemplateFilterProvider $filterProvider,
        MagentoCmsModelBlockFactory $blockFactory
    ) {

        $this->_categoryHelper = $categoryHelper;
        $this->_categoryFlatConfig = $categoryFlatState;
        $this->_categoryFactory = $categoryFactory;
        $this->_topMenu = $topMenu;
        $this->_helper = $helper;
        $this->_filterProvider = $filterProvider;
        $this->_blockFactory = $blockFactory;
        $this->_storeManager = $context->getStoreManager();

        parent::__construct($context);
    }

    public function getCategoryHelper()
    {
        return $this->_categoryHelper;
    }

    public function getCategoryModel($id)
    {
        $_category = $this->_categoryFactory->create();
        $_category->load($id);

        return $_category;
    }

    public function getHtml($outermostClass = '', $childrenWrapClass = '', $limit = 0)
    {
        return $this->_topMenu->getHtml($outermostClass, $childrenWrapClass, $limit);
    }

    public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
    {
        return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
    }

    public function getChildCategories($category)
    {
        if ($this->_categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource()) {
            $subcategories = (array)$category->getChildrenNodes();
        } else {
            $subcategories = $category->getChildren();
        }

        return $subcategories;
    }

    public function getActiveChildCategories($category)
    {
        $children = [];
        if ($this->_categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource()) {
            $subcategories = (array)$category->getChildrenNodes();
        } else {
            $subcategories = $category->getChildren();
        }
        foreach($subcategories as $category) {
            if (!$category->getIsActive()) {
                continue;
            }
            $children[] = $category;
        }
        return $children;
    }

    public function getBlockContent($content = '') {
        if(!$this->_filterProvider)
            return $content;
        return $this->_filterProvider->getBlockFilter()->filter(trim($content));
    }

    public function getCustomBlockHtml($type='after') {
        $html = '';

        $block_ids = $this->_megamenuConfig['custom_links']['staticblock_'.$type];

        if (!$block_ids) return '';

        $block_ids = preg_replace('/s/', '', $block_ids);
        $ids = explode(',', $block_ids);
        $store_id = $this->_storeManager->getStore()->getId();

        foreach($ids as $block_id) {
            $block = $this->_blockFactory->create();
            $block->setStoreId($store_id)->load($block_id);

            if(!$block) continue;

            $block_content = $block->getContent();

            if(!$block_content) continue;

            $content = $this->_filterProvider->getBlockFilter()->setStoreId($store_id)->filter($block_content);
            if(substr($content, 0, 4) == '<ul>')
                $content = substr($content, 4);
            if(substr($content, strlen($content) - 5) == '</ul>')
                $content = substr($content, 0, -5);

            $html .= $content;
        }

        return $html;
    }
    public function getSubmenuItemsHtml($children, $level = 1, $max_level = 0, $column_width=12, $menu_type = 'fullwidth', $columns = null)
    {
        $html = '';

        if(!$max_level || ($max_level && $max_level == 0) || ($max_level && $max_level > 0 && $max_level-1 >= $level)) {
            $column_class = "";
            if($level == 1 && $columns && ($menu_type == 'fullwidth' || $menu_type == 'staticwidth')) {
                $column_class = "col-sm-".$column_width." ";
                $column_class .= "mega-columns columns".$columns;
            }
            $html = '<ul class="subchildmenu '.$column_class.'">';
            foreach($children as $child) {
                $cat_model = $this->getCategoryModel($child->getId());

                $sw_menu_hide_item = $cat_model->getData('sw_menu_hide_item');

                if (!$sw_menu_hide_item) {
                    $sub_children = $this->getActiveChildCategories($child);

                    $sw_menu_cat_label = $cat_model->getData('sw_menu_cat_label');
                    $sw_menu_icon_img = $cat_model->getData('sw_menu_icon_img');
                    $sw_menu_font_icon = $cat_model->getData('sw_menu_font_icon');

                    $item_class = 'level'.$level.' ';
                    if(count($sub_children) > 0)
                        $item_class .= 'parent ';
                    $html .= '<li class="ui-menu-item '.$item_class.'">';
                    if(count($sub_children) > 0) {
                        $html .= '
'; } if($level == 1 && $sw_menu_icon_img) { $html .= ''; } $html .= '<a href="'.$this->_categoryHelper->getCategoryUrl($child).'">'; if ($level > 1 && $sw_menu_icon_img) $html .= '<img class="menu-thumb-icon" src="' . $this->_helper->getBaseUrl().'catalog/category/' . $sw_menu_icon_img . '" alt="'.$child->getName().'"/>'; elseif($sw_menu_font_icon) $html .= '<em class="menu-thumb-icon '.$sw_menu_font_icon.'"></em>'; $html .= '<span>'.$child->getName(); if($sw_menu_cat_label) $html .= '<span class="cat-label cat-label-'.$sw_menu_cat_label.'">'.$this->_megamenuConfig['cat_labels'][$sw_menu_cat_label].'</span>'; $html .= '</span></a>'; if(count($sub_children) > 0) { $html .= $this->getSubmenuItemsHtml($sub_children, $level+1, $max_level, $column_width, $menu_type); } $html .= '</li>'; } } $html .= '</ul>'; } return $html; } public function getMegamenuHtml() { $html = ''; $categories = $this->getStoreCategories(true,false,true); $this->_megamenuConfig = $this->_helper->getConfig('sw_megamenu'); $max_level = $this->_megamenuConfig['general']['max_level']; $html .= $this->getCustomBlockHtml('before'); foreach($categories as $category) { if (!$category->getIsActive()) { continue; } $cat_model = $this->getCategoryModel($category->getId()); $sw_menu_hide_item = $cat_model->getData('sw_menu_hide_item'); if(!$sw_menu_hide_item) { $children = $this->getActiveChildCategories($category); $sw_menu_cat_label = $cat_model->getData('sw_menu_cat_label'); $sw_menu_icon_img = $cat_model->getData('sw_menu_icon_img'); $sw_menu_font_icon = $cat_model->getData('sw_menu_font_icon'); $sw_menu_cat_columns = $cat_model->getData('sw_menu_cat_columns'); $sw_menu_float_type = $cat_model->getData('sw_menu_float_type'); if(!$sw_menu_cat_columns){ $sw_menu_cat_columns = 4; } $menu_type = $cat_model->getData('sw_menu_type'); if(!$menu_type) $menu_type = $this->_megamenuConfig['general']['menu_type']; $custom_style = ''; if($menu_type=="staticwidth") $custom_style = ' style="width: 500px;"'; $sw_menu_static_width = $cat_model->getData('sw_menu_static_width'); if($menu_type=="staticwidth" && $sw_menu_static_width) $custom_style = ' style="width: '.$sw_menu_static_width.';"'; $item_class = 'level0 '; $item_class .= $menu_type.' '; $menu_top_content = $cat_model->getData('sw_menu_block_top_content'); $menu_left_content = $cat_model->getData('sw_menu_block_left_content'); $menu_left_width = $cat_model->getData('sw_menu_block_left_width'); if(!$menu_left_content || !$menu_left_width) $menu_left_width = 0; $menu_right_content = $cat_model->getData('sw_menu_block_right_content'); $menu_right_width = $cat_model->getData('sw_menu_block_right_width'); if(!$menu_right_content || !$menu_right_width) $menu_right_width = 0; $menu_bottom_content = $cat_model->getData('sw_menu_block_bottom_content'); if($sw_menu_float_type) $sw_menu_float_type = 'fl-'.$sw_menu_float_type.' '; if(count($children) > 0 || (($menu_type=="fullwidth" || $menu_type=="staticwidth") && ($menu_top_content || $menu_left_content || $menu_right_content || $menu_bottom_content))) $item_class .= 'parent '; $html .= '<li class="ui-menu-item '.$item_class.$sw_menu_float_type.'">'; if(count($children) > 0) { $html .= '
'; } $html .= '<a href="'.$this->_categoryHelper->getCategoryUrl($category).'" class="level-top">'; if ($sw_menu_icon_img) $html .= '<img class="menu-thumb-icon" src="' . $this->_helper->getBaseUrl().'catalog/category/' . $sw_menu_icon_img . '" alt="'.$category->getName().'"/>'; elseif($sw_menu_font_icon) $html .= '<em class="menu-thumb-icon '.$sw_menu_font_icon.'"></em>'; $html .= '<span>'.$category->getName().'</span>'; if($sw_menu_cat_label) $html .= '<span class="cat-label cat-label-'.$sw_menu_cat_label.'">'.$this->_megamenuConfig['cat_labels'][$sw_menu_cat_label].'</span>'; $html .= '</a>'; if(count($children) > 0 || (($menu_type=="fullwidth" || $menu_type=="staticwidth") && ($menu_top_content || $menu_left_content || $menu_right_content || $menu_bottom_content))) { $html .= '
'; if(($menu_type=="fullwidth" || $menu_type=="staticwidth") && $menu_top_content) { $html .= ''; } if(count($children) > 0 || (($menu_type=="fullwidth" || $menu_type=="staticwidth") && ($menu_left_content || $menu_right_content))) { $html .= '
'; if(($menu_type=="fullwidth" || $menu_type=="staticwidth") && $menu_left_content && $menu_left_width > 0) { $html .= ''; } $html .= $this->getSubmenuItemsHtml($children, 1, $max_level, 12-$menu_left_width-$menu_right_width, $menu_type, $sw_menu_cat_columns); if(($menu_type=="fullwidth" || $menu_type=="staticwidth") && $menu_right_content && $menu_right_width > 0) { $html .= ''; } $html .= '</div>'; } if(($menu_type=="fullwidth" || $menu_type=="staticwidth") && $menu_bottom_content) { $html .= ''; } $html .= '</div>'; } $html .= '</li>'; } } $html .= $this->getCustomBlockHtml('after'); return $html; } }

view/layout/default.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="catalog.topnav" remove="true"/>
        <referenceContainer name="page.top">
            <block class="ClumsywaveMegaBlockTopmenu" name="sw.topnav" template="Clumsywave_Mega::topmenu.phtml" cacheable="true" before="-"/>
        </referenceContainer>
        <referenceContainer name="after.body.start">
            <block class="ClumsywaveThemeBlockTemplate" name="category_list_on_left" template="Clumsywave_Mega::onepagecategory/category_list.phtml" after="-"/>
        </referenceContainer>
    </body>
</page>


Get this bounty!!!

#StackBounty: #magento2 #dependency-injection #di #factory Registering a shared service with a custom factory

Bounty: 50

I’m wondering how (if I can) register a shared service with a custom factory.

Consider the following code:

class MyApiFactory {
    private $config;

    public function ___construct(Config $config) {
        $this->config = $config;
    }

    //this method could either be __invoke
    //or the class could implement some factory interface
    public function create() {
        return new MyApi($this->config->get('some-value'), $this->config->get('some-other-value'));
    }

}

class MyApi {
}

class MyService1 {
    public function __construct(MyApi $api) {}
}

class MyService2 {
    public function __construct(MyApi $api) {}
}

With other PHP DI frameworks – I would register MyApiFactory as a factory for MyApi. If I requested for service MyService1 the DI container would see that It needs MyApi and therefore execute MyApiFactory to get MyApiMyApi would then be stored as a service (if the container supports sharing).

Then I ask for MyService2 which also needs MyApi – as MyApi has already been created before – it just pulls it from the DI container and injects it in MyService2.

Therefore MyApi in MyService1 & MyService2 are the same.

I can’t seem to find a way to do this in Magento 2. Basically I want to avoid creating MyApi twice.

The only way I can think to do this is to keep a record of the created MyApi inside MyApiFactory so the second time MyApiFactory::create is called it returns the existing instance. Then I would have to inject MyApiFactory into MyService1 & MyService2 and call create within there constructors or wherever.

This (to me) seems wholly unnecessary and quite unintuitive – is this a problem anyone else has come across? Is there some support for shared services with custom factories in Magento 2 ?

This was more of a question to the Magento 2 developers rather than the community, I did originally create this as an issue but that got shut down, refs: https://github.com/magento/magento2/issues/8182#issuecomment-273763661


Get this bounty!!!

#StackBounty: #magento2 #topmenu how to sort order of custom links nav in magento2

Bounty: 50

I have used following code to insert custom links in topmenu.

but those are coming in the last of main nav.i want first about us then some other category then contact us etc.

<?php 

namespace DcwCustomerPluginBlock;

use MagentoFrameworkDataTreeNodeFactory;

class Topmenu
{
    /**
     * @var NodeFactory
     */
    protected $nodeFactory;

    public function __construct(
        NodeFactory $nodeFactory
    ) {
        $this->nodeFactory = $nodeFactory;
    }

    public function beforeGetHtml(
        MagentoThemeBlockHtmlTopmenu $subject,
        $outermostClass = '',
        $childrenWrapClass = '',
        $limit = 0
    ) {
        $node = $this->nodeFactory->create(
            [
                'data' => [
            'name' => __('ABOUT US'),
            'id' => 'aboutus',
            'url' => 'http://www.example.com/',
            'has_active' => true,
            'is_active' => true // (expression to determine if menu item is selected or not)
        ],
                'idField' => 'id',
                'tree' => $subject->getMenu()->getTree()
            ]
        );
        $subject->getMenu()->addChild($node);
        $node = $this->nodeFactory->create(
            [
                'data' => [
            'name' => __('CONTACT US'),
            'id' => 'contactus',
            'url' => 'http://www.example.com/',
            'has_active' => true,
            'is_active' => true // (expression to determine if menu item is selected or not)
        ],
                'idField' => 'id',
                'tree' => $subject->getMenu()->getTree()
            ]
        );
        $subject->getMenu()->addChild($node);
        $node = $this->nodeFactory->create(
            [
                'data' => [
            'name' => __('CATALOG DOWNLOAD'),
            'id' => 'catalogdownload',
            'url' => 'http://www.example.com/',
            'has_active' => true,
            'is_active' => true // (expression to determine if menu item is selected or not)
        ],
                'idField' => 'id',
                'tree' => $subject->getMenu()->getTree()
            ]
        );
        $subject->getMenu()->addChild($node);
    }


}


Get this bounty!!!

#StackBounty: #magento2 #attributes #custom-options Magento 2 Configurable option not showing my custom theme

Bounty: 50

Magento 2 Configurable Swatch option option not showing my custom theme but it’s working in Default theme

My Default theme
enter image description here

Custom Theme
enter image description here

Product Details page it’s working fine only problem is listing page. How to i fix this


Get this bounty!!!

#StackBounty: #magento2 #module #category-selector Magento 2 How to save category selector data for custom module?

Bounty: 50

I’ve used below code to show category selector on custom module. Its show wihout any error. Below is code for showing category selector on form.

$fieldset->addType(
        'categories',
        'MagentoCatalogBlockAdminhtmlProductHelperFormCategory'
);




$fieldset->addField(
        'category',
        'categories',
        [
            'name' => 'category',
            'label' => __('Category'),
            'title' => __('Category')
        ]
    );

I’ve save data using controller using below code as its array i need to convert it in string to save.

if ($data['category']):
  $data['category'] = implode(",",$data['category']);
endif;

its saved successfully. but when i edit data its thorow me error.

[2017-05-03 12:54:58] report.CRITICAL: exception 'Exception' with message 'Notice: Array to string conversion in /var/www/html/magento/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2930' in /var/www/html/magento/vendor/magento/framework/App/ErrorHandler.php:61

Am i missing something here?

Update:

below is form code:

class Main extends MagentoBackendBlockWidgetFormGeneric implements MagentoBackendBlockWidgetTabTabInterface
{
     /**
     * @var MagentoCmsModelWysiwygConfig
     */
    protected $_wysiwygConfig;

    /**
     * @var MagentoStoreModelSystemStore
     */
    protected $_systemStore;

    /**
     * @param MagentoBackendBlockTemplateContext $context
     * @param MagentoFrameworkRegistry $registry
     * @param MagentoFrameworkDataFormFactory $formFactory
     * @param MagentoStoreModelSystemStore $systemStore
     * @param MagentoCmsModelWysiwygConfig $wysiwygConfig
     * @param array $data
     */

    public function __construct(
        MagentoBackendBlockTemplateContext $context,
        MagentoFrameworkRegistry $registry,
        MagentoFrameworkDataFormFactory $formFactory,
        MagentoStoreModelSystemStore $systemStore,
        MagentoCmsModelWysiwygConfig $wysiwygConfig,
        array $data = []
    ) {
        $this->_systemStore = $systemStore;
        $this->_wysiwygConfig = $wysiwygConfig;
        parent::__construct($context, $registry, $formFactory, $data);
    }

    public function getTabLabel()
    {
        return __('Item Information');
    }


    public function getTabTitle()
    {
        return __('Item Information');
    }


    public function canShowTab()
    {
        return true;
    }


    public function isHidden()
    {
        return false;
    }

    /**
     * Prepare form before rendering HTML
     *
     * @return $this    
     */
    protected function _prepareForm()
    {
        $model = $this->_coreRegistry->registry('current_kensium_advisor_items');
        /** @var MagentoFrameworkDataForm $form */
        $form = $this->_formFactory->create();
        $form->setHtmlIdPrefix('item_');
        $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Item Information')]);
        if ($model->getId()) {
            $fieldset->addField('id', 'hidden', ['name' => 'id']);
        }
        $fieldset->addType(
        'categories',
        'MagentoCatalogBlockAdminhtmlProductHelperFormCategory'
       );

    $fieldset->addField(
            'advisor_name',
            'text',
            [
                'name' => 'advisor_name',
                'label' => __('Name'),
                'title' => __('Name'),
                'required' => true
            ]
        );

Update:
I’ve updated code here for module.

https://github.com/kul3101/Category-Selector/tree/master/Test/Category/app/code/Test/Category


Get this bounty!!!

#StackBounty: #magento2 #api #integration #mule Magento2 with Mule

Bounty: 50

I would like to ask You about integration Magento2 with Mule.

Have you done something like that?
How you did integration? By using Magento’s default Apis or custom one?
Have you done some base-schema-connector for projects?

Fell free to write your experience (good and bad) about that.


Get this bounty!!!

#StackBounty: #magento2 #language Magento 2 set locale programmatically?

Bounty: 50

i am create one test php file in magento root directory.
i install ar_SA Language pack and try to convert one string English to Saudi Arabia here is my test code.

<?php

ini_set('display_errors', 1);
ini_set('max_execution_time', 0);
ini_set("memory_limit", "-1");
set_time_limit(0);
error_reporting(E_ALL);
require './app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$localeInterface = $objectManager->create('MagentoFrameworkTranslateInterface');
$localeInterface->setLocale('ar_SA');
echo $localeInterface->getLocale(); // it's print ar_SA

echo __('Check Value');

I have the corresponding translation in /i18n/ar_SA.csv file, it doesn’t print the translated sentence.


Get this bounty!!!

#StackBounty: #magento2 #tax #quoteitem #interface Magento 2 how to get product id from QuoteDetailsItemInterface object

Bounty: 50

I am using Magento 2.1.5 . I am trying to get product id in tax apply function calculateWithTaxNotInPrice is below

 /**
     * {@inheritdoc}
     */
    protected function calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $quantity, $round = true)
    {
        $taxRateRequest = $this->getAddressRateRequest()->setProductClassId(
            $this->taxClassManagement->getTaxClassId($item->getTaxClassKey())
        );


        //want to get product id here from item object but its give null value
        var_dump($item->getProductId());exit;


        $rate = $this->calculationTool->getRate($taxRateRequest);
        $appliedRates = $this->calculationTool->getAppliedRates($taxRateRequest);

        $applyTaxAfterDiscount = $this->config->applyTaxAfterDiscount($this->storeId);
        $discountAmount = $item->getDiscountAmount();
        $discountTaxCompensationAmount = 0;

        // Calculate $rowTotal
        $price = $this->calculationTool->round($item->getUnitPrice());
        $rowTotal = $price * $quantity;
        $rowTaxes = [];
        $rowTaxesBeforeDiscount = [];
        $appliedTaxes = [];
        //Apply each tax rate separately
        foreach ($appliedRates as $appliedRate) {
            $taxId = $appliedRate['id'];
            $taxRate = $appliedRate['percent'];
            $rowTaxPerRate = $this->calculationTool->calcTaxAmount($rowTotal, $taxRate, false, false);
            $deltaRoundingType = self::KEY_REGULAR_DELTA_ROUNDING;
            if ($applyTaxAfterDiscount) {
                $deltaRoundingType = self::KEY_TAX_BEFORE_DISCOUNT_DELTA_ROUNDING;
            }
            $rowTaxPerRate = $this->roundAmount($rowTaxPerRate, $taxId, false, $deltaRoundingType, $round, $item);
            $rowTaxAfterDiscount = $rowTaxPerRate;

            //Handle discount
            if ($applyTaxAfterDiscount) {
                //TODO: handle originalDiscountAmount
                $taxableAmount = max($rowTotal - $discountAmount, 0);
                $rowTaxAfterDiscount = $this->calculationTool->calcTaxAmount(
                    $taxableAmount,
                    $taxRate,
                    false,
                    false
                );
                $rowTaxAfterDiscount = $this->roundAmount(
                    $rowTaxAfterDiscount,
                    $taxId,
                    false,
                    self::KEY_REGULAR_DELTA_ROUNDING,
                    $round,
                    $item
                );
            }
            $appliedTaxes[$taxId] = $this->getAppliedTax(
                $rowTaxAfterDiscount,
                $appliedRate
            );

            $rowTaxes[] = $rowTaxAfterDiscount;
            $rowTaxesBeforeDiscount[] = $rowTaxPerRate;
        }
        $rowTax = array_sum($rowTaxes);
        $rowTaxBeforeDiscount = array_sum($rowTaxesBeforeDiscount);
        $rowTotalInclTax = $rowTotal + $rowTaxBeforeDiscount;
        $priceInclTax = $rowTotalInclTax / $quantity;
        if ($round) {
            $priceInclTax = $this->calculationTool->round($priceInclTax);
        }

        return $this->taxDetailsItemDataObjectFactory->create()
            ->setCode($item->getCode())
            ->setType($item->getType())
            ->setRowTax($rowTax)
            ->setPrice($price)
            ->setPriceInclTax($priceInclTax)
            ->setRowTotal($rowTotal)
            ->setRowTotalInclTax($rowTotalInclTax)
            ->setDiscountTaxCompensationAmount($discountTaxCompensationAmount)
            ->setAssociatedItemCode($item->getAssociatedItemCode())
            ->setTaxPercent($rate)
            ->setAppliedTaxes($appliedTaxes);
    }

In above code QuoteDetailsItemInterface $item have no product id method in interface MagentoTaxApiDataQuoteDetailsItemInterface

Can anyone suggest me how to include product id method in interface?

I have also add method in interface MagentoTaxApiDataQuoteDetailsItemInterface as below

 public function getProductId();

 public function setProductId($productId);

Also I have define same method in model Magento/Tax/Model/Sales/Quote/ItemDetails as below

/**
 * {@inheritdoc}
 */
public function getProductId()
{
    return $this->getData('product_id');
}

/**
 * {@inheritdoc}
 */
public function setProductId($productId)
{
    return $this->getData('product_id',$productId);
}

But it’s not working.

Any help would be much appreciated.Thanks!


Get this bounty!!!

#StackBounty: #magento2 #multistore #frontend #magento2.1.6 How apply AMP on Magento 2?

Bounty: 50

How can I apply the Google AMP on my Magento 2 store without using a paid module?


Get this bounty!!!