0

There is a Mage::reset() equivalent in Magento 2?

EDIT

The problem is:

I created a cli command that will create file to upload ebay listing... Here I got a foreach loop:

protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
    $areaObject = $this->_areaList->getArea(\Magento\Framework\App\Area::AREA_ADMINHTML);
    $areaObject->load(\Magento\Framework\App\Area::PART_TRANSLATE);
----
    foreach ($input->getOption(self::C_EBAY_STORES) as $ebaystore){
        foreach ($input->getOption(self::C_EBAY_SITES) as $site){

            $locale = $this->_helper->getLocale($site);
            $this->_storeManagerInterface->setCurrentStore($locale['store']);
            $this->_storeManagerInterface->getStore()->setCurrentCurrencyCode($locale['currency']);
            $this->_coreSession->setCountryCode($locale['iso']);
            $this->_emulation->startEnvironmentEmulation($this->_storeManagerInterface->getStore()->getCode(), 'frontend');

            
            $collection = $this->getCollection($this->_helper->getEbayAttribute($ebaystore,$site));
            foreach($collection as $product){
                if($product->isSaleable()){
                    
                    if(!in_array($product->getId(),$syncIds)){
                        $syncIds[] = $product->getId();
                    }
                    
                    $product->load($product->getId());              
            
                    $output->writeln("\t\t<info>SKU: ".$product->getSku()."</info>");
                    $output->writeln("\t\t<info>Minimal Price: ".print_r($product->getPriceInfo()->getPrice('final_price')->getAmount(),true)."</info>");
                    $output->writeln("\t\t<info>Core Session: ".print_r($this->_coreSession->getData(),true)."</info>");
                    $output->writeln("\t\t<comment>- - -</comment>");
                }
            }
            $this->_emulation->stopEnvironmentEmulation();
        }
    }

The problem is thet txtRates ara calculated only at the beginning, but i ned to refresh it every time after $this->_coreSession->setCountryCode($locale['iso']); to get the corrects rates for each country.

In Magento 1.9 i used this:

            $locale = Mage::helper('ebaysync')->getLocale($site);
            Mage::reset();
            Mage::app()->setCurrentStore($locale['store']);
            Mage::app()->getStore()->setCurrentCurrencyCode($locale['currency']);
            Mage::getSingleton('core/session')->setCountryCode($locale['iso']);

but i can't find any solution for Magento 2;

Any help?

1
  • Try to load your product collection adding a filter on storeId. Aug 23, 2020 at 7:22

1 Answer 1

0

Can you try with cleaning the cache programmatically? That might work for you. Just a suggestion. Because In magento 1 reset method used to warm up the magento cache. So you can give a try.

1
  • Tried to disable the cache, but taxes are calculated only when the script start
    – krybbio
    Aug 23, 2020 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.