Magento 2 Cron job can't get finalPrice for configurable productCron job at three distinct timesCron job doesn't workMagento 2 cron job not re-indexing products as expectedMagento 2 Custom cron job is ignoredCron job issue with indexingCron job permission issue?i had error while starting the cron jobCron Job In MagentoMagento2 cron job issue - Cron job is not workingSet different cron on magento 1

CAST throwing error when run in stored procedure but not when run as raw query

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)

Arrow those variables!

I would say: "You are another teacher", but she is a woman and I am a man

What is a romance in Latin?

Unable to supress ligatures in headings which are set in Caps

Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?

How do I handle a potential work/personal life conflict as the manager of one of my friends?

Does the Idaho Potato Commission associate potato skins with healthy eating?

How do I deal with an unproductive colleague in a small company?

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"

Is it inappropriate for a student to attend their mentor's dissertation defense?

Valid term from quadratic sequence?

Extract rows of a table, that include less than x NULLs

What does the expression "A Mann!" means

Can a virus destroy the BIOS of a modern computer?

Why is this clock signal connected to a capacitor to gnd?

When (not how or why) to calculate Big O of an algorithm

Determining Impedance With An Antenna Analyzer

How badly should I try to prevent a user from XSSing themselves?

Detention in 1997

Could the museum Saturn V's be refitted for one more flight?

How to prevent "they're falling in love" trope



Magento 2 Cron job can't get finalPrice for configurable product


Cron job at three distinct timesCron job doesn't workMagento 2 cron job not re-indexing products as expectedMagento 2 Custom cron job is ignoredCron job issue with indexingCron job permission issue?i had error while starting the cron jobCron Job In MagentoMagento2 cron job issue - Cron job is not workingSet different cron on magento 1













1















I have the following in my cron folder and also I have the following the Controller folder which is exact same code and it get the price when I load in the url but it refuse to get price in cron folder.



I can get the name just fine but no price



enter image description here



<?php
namespace VendorModuleCron;

class GenerateXml


protected $_productCollectionFactory;
protected $_stockItemRepository;
protected $_fileSystem;
protected $_storeManager;
protected $_imageHelper;
protected $_stockRegistry;

public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
MagentoFrameworkFilesystem $filesystem,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCatalogHelperImage $imageHelper
)

$this->_productCollectionFactory = $productCollectionFactory;
$this->_stockItemRepository = $stockItemRepository;
$this->_fileSystem = $filesystem;
$this->_storeManager = $storeManager;
$this->_imageHelper = $imageHelper;
$this->_stockRegistry = $stockRegistry;


public function execute()

$mediaProductUrl = $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product';
$placeholderImageUrl = $this->_imageHelper->getDefaultPlaceholderUrl('image');
$content = '';
$fileName = 'test';
$productCollection = $this->getProductCollection();
foreach ($productCollection as $product)
if ($product->getTypeId() == 'configurable')
$productCstock = $this->getStockItem($product->getId());
$prices = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
$content .= '<item>' . PHP_EOL;
$content .= '<price>' . $prices . '</price>' . PHP_EOL;
$content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
$content .= '</item>' . PHP_EOL;
$configChild = $product->getTypeInstance()->getUsedProducts($product);
foreach ($configChild as $child)
$productStock = $this->getStockItem($product->getId());
$content .= '<item>' . PHP_EOL;
$content .= '<price>' . $prices . '</price>' . PHP_EOL;
$content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
$content .= '</item>' . PHP_EOL;



$feed = $this->createHeader() . $content . $this->createFooter();
$media = $this->_fileSystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$media->writeFile("customFeed/" . $fileName . ".xml", $feed);


return $this;


public function getProductCollection()

$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
return $collection;


public function getStockItem($productId)

return $this->_stockRegistry->getStockStatus($productId);


public function createHeader()

$header = '<?xml version="1.0"?>' . PHP_EOL;
$header .= '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' . PHP_EOL;
$header .= '<xs:element name="item">' . PHP_EOL;
return $header;


public function createFooter()

$footer = '</xs:element>' . PHP_EOL;
$footer .= '</xs:schema>' . PHP_EOL;
return $footer;


}


I've also tried different method such as getFinalPrice() but no luck in cron. It only works in controller.



Anyone know what I could be missing in cron get price?










share|improve this question




























    1















    I have the following in my cron folder and also I have the following the Controller folder which is exact same code and it get the price when I load in the url but it refuse to get price in cron folder.



    I can get the name just fine but no price



    enter image description here



    <?php
    namespace VendorModuleCron;

    class GenerateXml


    protected $_productCollectionFactory;
    protected $_stockItemRepository;
    protected $_fileSystem;
    protected $_storeManager;
    protected $_imageHelper;
    protected $_stockRegistry;

    public function __construct(
    MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
    MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
    MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
    MagentoFrameworkFilesystem $filesystem,
    MagentoStoreModelStoreManagerInterface $storeManager,
    MagentoCatalogHelperImage $imageHelper
    )

    $this->_productCollectionFactory = $productCollectionFactory;
    $this->_stockItemRepository = $stockItemRepository;
    $this->_fileSystem = $filesystem;
    $this->_storeManager = $storeManager;
    $this->_imageHelper = $imageHelper;
    $this->_stockRegistry = $stockRegistry;


    public function execute()

    $mediaProductUrl = $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product';
    $placeholderImageUrl = $this->_imageHelper->getDefaultPlaceholderUrl('image');
    $content = '';
    $fileName = 'test';
    $productCollection = $this->getProductCollection();
    foreach ($productCollection as $product)
    if ($product->getTypeId() == 'configurable')
    $productCstock = $this->getStockItem($product->getId());
    $prices = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
    $content .= '<item>' . PHP_EOL;
    $content .= '<price>' . $prices . '</price>' . PHP_EOL;
    $content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
    $content .= '</item>' . PHP_EOL;
    $configChild = $product->getTypeInstance()->getUsedProducts($product);
    foreach ($configChild as $child)
    $productStock = $this->getStockItem($product->getId());
    $content .= '<item>' . PHP_EOL;
    $content .= '<price>' . $prices . '</price>' . PHP_EOL;
    $content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
    $content .= '</item>' . PHP_EOL;



    $feed = $this->createHeader() . $content . $this->createFooter();
    $media = $this->_fileSystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
    $media->writeFile("customFeed/" . $fileName . ".xml", $feed);


    return $this;


    public function getProductCollection()

    $collection = $this->_productCollectionFactory->create();
    $collection->addAttributeToSelect('*');
    return $collection;


    public function getStockItem($productId)

    return $this->_stockRegistry->getStockStatus($productId);


    public function createHeader()

    $header = '<?xml version="1.0"?>' . PHP_EOL;
    $header .= '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' . PHP_EOL;
    $header .= '<xs:element name="item">' . PHP_EOL;
    return $header;


    public function createFooter()

    $footer = '</xs:element>' . PHP_EOL;
    $footer .= '</xs:schema>' . PHP_EOL;
    return $footer;


    }


    I've also tried different method such as getFinalPrice() but no luck in cron. It only works in controller.



    Anyone know what I could be missing in cron get price?










    share|improve this question


























      1












      1








      1


      1






      I have the following in my cron folder and also I have the following the Controller folder which is exact same code and it get the price when I load in the url but it refuse to get price in cron folder.



      I can get the name just fine but no price



      enter image description here



      <?php
      namespace VendorModuleCron;

      class GenerateXml


      protected $_productCollectionFactory;
      protected $_stockItemRepository;
      protected $_fileSystem;
      protected $_storeManager;
      protected $_imageHelper;
      protected $_stockRegistry;

      public function __construct(
      MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
      MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
      MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
      MagentoFrameworkFilesystem $filesystem,
      MagentoStoreModelStoreManagerInterface $storeManager,
      MagentoCatalogHelperImage $imageHelper
      )

      $this->_productCollectionFactory = $productCollectionFactory;
      $this->_stockItemRepository = $stockItemRepository;
      $this->_fileSystem = $filesystem;
      $this->_storeManager = $storeManager;
      $this->_imageHelper = $imageHelper;
      $this->_stockRegistry = $stockRegistry;


      public function execute()

      $mediaProductUrl = $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product';
      $placeholderImageUrl = $this->_imageHelper->getDefaultPlaceholderUrl('image');
      $content = '';
      $fileName = 'test';
      $productCollection = $this->getProductCollection();
      foreach ($productCollection as $product)
      if ($product->getTypeId() == 'configurable')
      $productCstock = $this->getStockItem($product->getId());
      $prices = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
      $content .= '<item>' . PHP_EOL;
      $content .= '<price>' . $prices . '</price>' . PHP_EOL;
      $content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
      $content .= '</item>' . PHP_EOL;
      $configChild = $product->getTypeInstance()->getUsedProducts($product);
      foreach ($configChild as $child)
      $productStock = $this->getStockItem($product->getId());
      $content .= '<item>' . PHP_EOL;
      $content .= '<price>' . $prices . '</price>' . PHP_EOL;
      $content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
      $content .= '</item>' . PHP_EOL;



      $feed = $this->createHeader() . $content . $this->createFooter();
      $media = $this->_fileSystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
      $media->writeFile("customFeed/" . $fileName . ".xml", $feed);


      return $this;


      public function getProductCollection()

      $collection = $this->_productCollectionFactory->create();
      $collection->addAttributeToSelect('*');
      return $collection;


      public function getStockItem($productId)

      return $this->_stockRegistry->getStockStatus($productId);


      public function createHeader()

      $header = '<?xml version="1.0"?>' . PHP_EOL;
      $header .= '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' . PHP_EOL;
      $header .= '<xs:element name="item">' . PHP_EOL;
      return $header;


      public function createFooter()

      $footer = '</xs:element>' . PHP_EOL;
      $footer .= '</xs:schema>' . PHP_EOL;
      return $footer;


      }


      I've also tried different method such as getFinalPrice() but no luck in cron. It only works in controller.



      Anyone know what I could be missing in cron get price?










      share|improve this question
















      I have the following in my cron folder and also I have the following the Controller folder which is exact same code and it get the price when I load in the url but it refuse to get price in cron folder.



      I can get the name just fine but no price



      enter image description here



      <?php
      namespace VendorModuleCron;

      class GenerateXml


      protected $_productCollectionFactory;
      protected $_stockItemRepository;
      protected $_fileSystem;
      protected $_storeManager;
      protected $_imageHelper;
      protected $_stockRegistry;

      public function __construct(
      MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
      MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository,
      MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry,
      MagentoFrameworkFilesystem $filesystem,
      MagentoStoreModelStoreManagerInterface $storeManager,
      MagentoCatalogHelperImage $imageHelper
      )

      $this->_productCollectionFactory = $productCollectionFactory;
      $this->_stockItemRepository = $stockItemRepository;
      $this->_fileSystem = $filesystem;
      $this->_storeManager = $storeManager;
      $this->_imageHelper = $imageHelper;
      $this->_stockRegistry = $stockRegistry;


      public function execute()

      $mediaProductUrl = $this->_storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product';
      $placeholderImageUrl = $this->_imageHelper->getDefaultPlaceholderUrl('image');
      $content = '';
      $fileName = 'test';
      $productCollection = $this->getProductCollection();
      foreach ($productCollection as $product)
      if ($product->getTypeId() == 'configurable')
      $productCstock = $this->getStockItem($product->getId());
      $prices = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
      $content .= '<item>' . PHP_EOL;
      $content .= '<price>' . $prices . '</price>' . PHP_EOL;
      $content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
      $content .= '</item>' . PHP_EOL;
      $configChild = $product->getTypeInstance()->getUsedProducts($product);
      foreach ($configChild as $child)
      $productStock = $this->getStockItem($product->getId());
      $content .= '<item>' . PHP_EOL;
      $content .= '<price>' . $prices . '</price>' . PHP_EOL;
      $content .= '<title>' . $product->getName() . '</title>' . PHP_EOL;
      $content .= '</item>' . PHP_EOL;



      $feed = $this->createHeader() . $content . $this->createFooter();
      $media = $this->_fileSystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
      $media->writeFile("customFeed/" . $fileName . ".xml", $feed);


      return $this;


      public function getProductCollection()

      $collection = $this->_productCollectionFactory->create();
      $collection->addAttributeToSelect('*');
      return $collection;


      public function getStockItem($productId)

      return $this->_stockRegistry->getStockStatus($productId);


      public function createHeader()

      $header = '<?xml version="1.0"?>' . PHP_EOL;
      $header .= '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">' . PHP_EOL;
      $header .= '<xs:element name="item">' . PHP_EOL;
      return $header;


      public function createFooter()

      $footer = '</xs:element>' . PHP_EOL;
      $footer .= '</xs:schema>' . PHP_EOL;
      return $footer;


      }


      I've also tried different method such as getFinalPrice() but no luck in cron. It only works in controller.



      Anyone know what I could be missing in cron get price?







      magento2.2.2 crontab cronjobs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago







      Juliano Vargas

















      asked Mar 29 at 22:26









      Juliano VargasJuliano Vargas

      586523




      586523




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Try to run cron functionality with store emulation.



          protected $emulation;

          public function __construct(
          MagentoStoreModelAppEmulation $emulation
          )

          $this->emulation = $emulation;


          public function execute()

          $_store = 1;
          $this->emulation->startEnvironmentEmulation($_store, MagentoFrameworkAppArea::AREA_FRONTEND, true);

          // your logic here

          $this->emulation->stopEnvironmentEmulation();



          As cronjob does not have store settled, so you need to run your code by above way.






          share|improve this answer























          • you'r star That works as treat. Just need to correct my answer actually it was just the configurable product that I couldn't get final price and also the product url was returning the non-friendly url now with emulation in place everything is returning correctly.

            – Juliano Vargas
            2 days ago











          • Thats great, have a good day !!!!

            – Yash Shah
            2 days ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268018%2fmagento-2-cron-job-cant-get-finalprice-for-configurable-product%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Try to run cron functionality with store emulation.



          protected $emulation;

          public function __construct(
          MagentoStoreModelAppEmulation $emulation
          )

          $this->emulation = $emulation;


          public function execute()

          $_store = 1;
          $this->emulation->startEnvironmentEmulation($_store, MagentoFrameworkAppArea::AREA_FRONTEND, true);

          // your logic here

          $this->emulation->stopEnvironmentEmulation();



          As cronjob does not have store settled, so you need to run your code by above way.






          share|improve this answer























          • you'r star That works as treat. Just need to correct my answer actually it was just the configurable product that I couldn't get final price and also the product url was returning the non-friendly url now with emulation in place everything is returning correctly.

            – Juliano Vargas
            2 days ago











          • Thats great, have a good day !!!!

            – Yash Shah
            2 days ago















          1














          Try to run cron functionality with store emulation.



          protected $emulation;

          public function __construct(
          MagentoStoreModelAppEmulation $emulation
          )

          $this->emulation = $emulation;


          public function execute()

          $_store = 1;
          $this->emulation->startEnvironmentEmulation($_store, MagentoFrameworkAppArea::AREA_FRONTEND, true);

          // your logic here

          $this->emulation->stopEnvironmentEmulation();



          As cronjob does not have store settled, so you need to run your code by above way.






          share|improve this answer























          • you'r star That works as treat. Just need to correct my answer actually it was just the configurable product that I couldn't get final price and also the product url was returning the non-friendly url now with emulation in place everything is returning correctly.

            – Juliano Vargas
            2 days ago











          • Thats great, have a good day !!!!

            – Yash Shah
            2 days ago













          1












          1








          1







          Try to run cron functionality with store emulation.



          protected $emulation;

          public function __construct(
          MagentoStoreModelAppEmulation $emulation
          )

          $this->emulation = $emulation;


          public function execute()

          $_store = 1;
          $this->emulation->startEnvironmentEmulation($_store, MagentoFrameworkAppArea::AREA_FRONTEND, true);

          // your logic here

          $this->emulation->stopEnvironmentEmulation();



          As cronjob does not have store settled, so you need to run your code by above way.






          share|improve this answer













          Try to run cron functionality with store emulation.



          protected $emulation;

          public function __construct(
          MagentoStoreModelAppEmulation $emulation
          )

          $this->emulation = $emulation;


          public function execute()

          $_store = 1;
          $this->emulation->startEnvironmentEmulation($_store, MagentoFrameworkAppArea::AREA_FRONTEND, true);

          // your logic here

          $this->emulation->stopEnvironmentEmulation();



          As cronjob does not have store settled, so you need to run your code by above way.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 30 at 11:29









          Yash ShahYash Shah

          68618




          68618












          • you'r star That works as treat. Just need to correct my answer actually it was just the configurable product that I couldn't get final price and also the product url was returning the non-friendly url now with emulation in place everything is returning correctly.

            – Juliano Vargas
            2 days ago











          • Thats great, have a good day !!!!

            – Yash Shah
            2 days ago

















          • you'r star That works as treat. Just need to correct my answer actually it was just the configurable product that I couldn't get final price and also the product url was returning the non-friendly url now with emulation in place everything is returning correctly.

            – Juliano Vargas
            2 days ago











          • Thats great, have a good day !!!!

            – Yash Shah
            2 days ago
















          you'r star That works as treat. Just need to correct my answer actually it was just the configurable product that I couldn't get final price and also the product url was returning the non-friendly url now with emulation in place everything is returning correctly.

          – Juliano Vargas
          2 days ago





          you'r star That works as treat. Just need to correct my answer actually it was just the configurable product that I couldn't get final price and also the product url was returning the non-friendly url now with emulation in place everything is returning correctly.

          – Juliano Vargas
          2 days ago













          Thats great, have a good day !!!!

          – Yash Shah
          2 days ago





          Thats great, have a good day !!!!

          – Yash Shah
          2 days ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268018%2fmagento-2-cron-job-cant-get-finalprice-for-configurable-product%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

          БиармияSxpst500bh2ntaf! 3h2r