How to add product qty and product price store wise progrmatically in magento 2Update price attribute and save attributeProducts are not showing on category and search resultHow to create/update bulk of products at a time programmaticallyAvailable Inventory not showing with product infoauto save in stock if qty greater than 0Magento 2: Add a product to the cart programmaticallyHow to Update Magento 2 configurable child products price by REST APIMagento 2.2.5: Add, Update and Delete existing products Custom OptionsOnly 1 product adding to order when creating orders programmatically in Magento 2How to add category Path when creating product progrmatically in magento 2

C++ debug of nlohmann json using GDB

On a tidally locked planet, would time be quantized?

What was the exact wording from Ivanhoe of this advice on how to free yourself from slavery?

New brakes for 90s road bike

Is it better practice to read straight from sheet music rather than memorize it?

How should I respond when I lied about my education and the company finds out through background check?

Are paving bricks differently sized for sand bedding vs mortar bedding?

Why does the Sun have different day lengths, but not the gas giants?

Pre-modern battle - command it, or fight in it?

Why Shazam when there is already Superman?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

dpdt switch to spst switch

What if a revenant (monster) gains fire resistance?

lightning-datatable row number error

Why can Carol Danvers change her suit colours in the first place?

A social experiment. What is the worst that can happen?

Not using 's' for he/she/it

Strong empirical falsification of quantum mechanics based on vacuum energy density

Does a 'pending' US visa application constitute a denial?

Aragorn's "guise" in the Orthanc Stone

Multiplicative persistence

How do you make your own symbol when Detexify fails?

Is aluminum electrical wire used on aircraft?

The screen of my macbook suddenly broken down how can I do to recover



How to add product qty and product price store wise progrmatically in magento 2


Update price attribute and save attributeProducts are not showing on category and search resultHow to create/update bulk of products at a time programmaticallyAvailable Inventory not showing with product infoauto save in stock if qty greater than 0Magento 2: Add a product to the cart programmaticallyHow to Update Magento 2 configurable child products price by REST APIMagento 2.2.5: Add, Update and Delete existing products Custom OptionsOnly 1 product adding to order when creating orders programmatically in Magento 2How to add category Path when creating product progrmatically in magento 2













0















I want to create product progrmatically.
product creating section is done, after creating the product i want to update the product qty and price store wise.
I have following array which return me the qty and price store wise.




Array
(
[0] => 1-13-45
[1] => 2-12-22
)




In my helper i have below function to update the qty and price store wise.



public function __construct(
MagentoCatalogModelProductRepository $productRepository)
$this->_productRepository = $productRepository;

public function updateStockAndPricesByStore($product_id,$store_data)

foreach($store_data as $store)
$store_datas = explode("-",$store);
$store_id = $store_datas[0];
$qty = $store_datas[1];
$price = $store_datas[2];

$new_product = $this->_productRepository->getById($product_id, false, $store_id);

$new_product->setPrice($price);
$new_product->save();
$new_product->setStockData(
array(
'use_config_manage_stock' => 0,
// checkbox for 'Use config settings'
'manage_stock' => 1, // manage stock
'is_in_stock' => 1, // Stock Availability of product
'qty' => $qty // qty of product
)
);
//End for each
//End of function updateStockAndPricesByStoree


I can get the product name after getById function like this



echo $new_product->getName()


But unable to update the product qty and product price by using this code.



How can i update the product price and stock programatically?










share|improve this question


























    0















    I want to create product progrmatically.
    product creating section is done, after creating the product i want to update the product qty and price store wise.
    I have following array which return me the qty and price store wise.




    Array
    (
    [0] => 1-13-45
    [1] => 2-12-22
    )




    In my helper i have below function to update the qty and price store wise.



    public function __construct(
    MagentoCatalogModelProductRepository $productRepository)
    $this->_productRepository = $productRepository;

    public function updateStockAndPricesByStore($product_id,$store_data)

    foreach($store_data as $store)
    $store_datas = explode("-",$store);
    $store_id = $store_datas[0];
    $qty = $store_datas[1];
    $price = $store_datas[2];

    $new_product = $this->_productRepository->getById($product_id, false, $store_id);

    $new_product->setPrice($price);
    $new_product->save();
    $new_product->setStockData(
    array(
    'use_config_manage_stock' => 0,
    // checkbox for 'Use config settings'
    'manage_stock' => 1, // manage stock
    'is_in_stock' => 1, // Stock Availability of product
    'qty' => $qty // qty of product
    )
    );
    //End for each
    //End of function updateStockAndPricesByStoree


    I can get the product name after getById function like this



    echo $new_product->getName()


    But unable to update the product qty and product price by using this code.



    How can i update the product price and stock programatically?










    share|improve this question
























      0












      0








      0








      I want to create product progrmatically.
      product creating section is done, after creating the product i want to update the product qty and price store wise.
      I have following array which return me the qty and price store wise.




      Array
      (
      [0] => 1-13-45
      [1] => 2-12-22
      )




      In my helper i have below function to update the qty and price store wise.



      public function __construct(
      MagentoCatalogModelProductRepository $productRepository)
      $this->_productRepository = $productRepository;

      public function updateStockAndPricesByStore($product_id,$store_data)

      foreach($store_data as $store)
      $store_datas = explode("-",$store);
      $store_id = $store_datas[0];
      $qty = $store_datas[1];
      $price = $store_datas[2];

      $new_product = $this->_productRepository->getById($product_id, false, $store_id);

      $new_product->setPrice($price);
      $new_product->save();
      $new_product->setStockData(
      array(
      'use_config_manage_stock' => 0,
      // checkbox for 'Use config settings'
      'manage_stock' => 1, // manage stock
      'is_in_stock' => 1, // Stock Availability of product
      'qty' => $qty // qty of product
      )
      );
      //End for each
      //End of function updateStockAndPricesByStoree


      I can get the product name after getById function like this



      echo $new_product->getName()


      But unable to update the product qty and product price by using this code.



      How can i update the product price and stock programatically?










      share|improve this question














      I want to create product progrmatically.
      product creating section is done, after creating the product i want to update the product qty and price store wise.
      I have following array which return me the qty and price store wise.




      Array
      (
      [0] => 1-13-45
      [1] => 2-12-22
      )




      In my helper i have below function to update the qty and price store wise.



      public function __construct(
      MagentoCatalogModelProductRepository $productRepository)
      $this->_productRepository = $productRepository;

      public function updateStockAndPricesByStore($product_id,$store_data)

      foreach($store_data as $store)
      $store_datas = explode("-",$store);
      $store_id = $store_datas[0];
      $qty = $store_datas[1];
      $price = $store_datas[2];

      $new_product = $this->_productRepository->getById($product_id, false, $store_id);

      $new_product->setPrice($price);
      $new_product->save();
      $new_product->setStockData(
      array(
      'use_config_manage_stock' => 0,
      // checkbox for 'Use config settings'
      'manage_stock' => 1, // manage stock
      'is_in_stock' => 1, // Stock Availability of product
      'qty' => $qty // qty of product
      )
      );
      //End for each
      //End of function updateStockAndPricesByStoree


      I can get the product name after getById function like this



      echo $new_product->getName()


      But unable to update the product qty and product price by using this code.



      How can i update the product price and stock programatically?







      product magento2.2 price programmatically inventory






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      MujahidhMujahidh

      1,41012036




      1,41012036




















          0






          active

          oldest

          votes











          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%2f266973%2fhow-to-add-product-qty-and-product-price-store-wise-progrmatically-in-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f266973%2fhow-to-add-product-qty-and-product-price-store-wise-progrmatically-in-magento-2%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