Magento 2 : We need to save product two time After generating Custom Option programmatically?Product custom option duplication on save within loopCreating Custom Option on Product SaveCreate custom option programatically in magento 1.7.0.1Forcing a certain custom option value when customer adding product to cartMagento add custom options to cartHow to change product name in quote item dynamicallyHow to add custom options programmatically for configurable product in Magento 2Magento 2 custom option not showing created programmaticallyI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options

What's the difference between "ricochet" and "bounce"?

Not taking the bishop with the knight, why?

Was Mohammed the most popular first name for boys born in Berlin in 2018?

Publishing an article in a journal without a related degree

Examples where existence is harder than evaluation

Narcissistic cube asks who are we?

How did Captain Marvel know where to find these characters?

Is it safe to keep the GPU on 100% utilization for a very long time?

Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019

What can cause an unfrozen indoor copper drain pipe to crack?

How come mathematicians published in Annals of Eugenics?

Is there an idiom that means "revealing a secret unintentionally"?

Can the president of the United States be guilty of insider trading?

Does STATISTICS IO output include Version Store reads?

Hexagonal Grid Filling

Do Monks gain the 9th level Unarmored Movement benefit when wearing armor or using a shield?

Does a surprised creature obey the 1st level spell Command?

Pre-1993 comic in which Wolverine's claws were turned to rubber?

Output the date in the Mel calendar

Was there a contingency plan in place if Little Boy failed to detonate?

What dice to use in a game that revolves around triangles?

Compactness in normed vector spaces.

What's an appropriate age to involve kids in life changing decisions?

Generating 10-character passwords, with 3-6 digits and 3-6 uppercase letters, in C++



Magento 2 : We need to save product two time After generating Custom Option programmatically?


Product custom option duplication on save within loopCreating Custom Option on Product SaveCreate custom option programatically in magento 1.7.0.1Forcing a certain custom option value when customer adding product to cartMagento add custom options to cartHow to change product name in quote item dynamicallyHow to add custom options programmatically for configurable product in Magento 2Magento 2 custom option not showing created programmaticallyI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I have work on Custom Module.
In Our Module I had use



<event name="catalog_product_save_after">
<observer name="add_custom_option" instance="NamespaceModulenameObserverAddCustomOption" />
</event>


In observer i Had Generate Product Custom Option Programmatically



 $product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogModelProductOption')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
//$product->save();



i have use this code for generate Product custom Option.




//$product->save();




i had comment this code because it provide me Error




No Such Entity




After saving Product.



Product Options are generated Successfully in Product But Not Display in Front-end



I had Run All Commands



  • setup:upgrade

  • setup:static-content:deploy -f

  • indexer:reindex

  • cache:flush

But Custom Option Not Appears in Front-end



But When i have save product second time after saving product the Options are Appears in Front-end Without need Run any Commands.




I Need Solution to save Product One time and Get Product Option Front End




Is This Possible ?










share|improve this question






















  • I have also the same problems

    – Hardik Makwana
    1 hour ago

















4















I have work on Custom Module.
In Our Module I had use



<event name="catalog_product_save_after">
<observer name="add_custom_option" instance="NamespaceModulenameObserverAddCustomOption" />
</event>


In observer i Had Generate Product Custom Option Programmatically



 $product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogModelProductOption')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
//$product->save();



i have use this code for generate Product custom Option.




//$product->save();




i had comment this code because it provide me Error




No Such Entity




After saving Product.



Product Options are generated Successfully in Product But Not Display in Front-end



I had Run All Commands



  • setup:upgrade

  • setup:static-content:deploy -f

  • indexer:reindex

  • cache:flush

But Custom Option Not Appears in Front-end



But When i have save product second time after saving product the Options are Appears in Front-end Without need Run any Commands.




I Need Solution to save Product One time and Get Product Option Front End




Is This Possible ?










share|improve this question






















  • I have also the same problems

    – Hardik Makwana
    1 hour ago













4












4








4








I have work on Custom Module.
In Our Module I had use



<event name="catalog_product_save_after">
<observer name="add_custom_option" instance="NamespaceModulenameObserverAddCustomOption" />
</event>


In observer i Had Generate Product Custom Option Programmatically



 $product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogModelProductOption')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
//$product->save();



i have use this code for generate Product custom Option.




//$product->save();




i had comment this code because it provide me Error




No Such Entity




After saving Product.



Product Options are generated Successfully in Product But Not Display in Front-end



I had Run All Commands



  • setup:upgrade

  • setup:static-content:deploy -f

  • indexer:reindex

  • cache:flush

But Custom Option Not Appears in Front-end



But When i have save product second time after saving product the Options are Appears in Front-end Without need Run any Commands.




I Need Solution to save Product One time and Get Product Option Front End




Is This Possible ?










share|improve this question














I have work on Custom Module.
In Our Module I had use



<event name="catalog_product_save_after">
<observer name="add_custom_option" instance="NamespaceModulenameObserverAddCustomOption" />
</event>


In observer i Had Generate Product Custom Option Programmatically



 $product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogModelProductOption')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
//$product->save();



i have use this code for generate Product custom Option.




//$product->save();




i had comment this code because it provide me Error




No Such Entity




After saving Product.



Product Options are generated Successfully in Product But Not Display in Front-end



I had Run All Commands



  • setup:upgrade

  • setup:static-content:deploy -f

  • indexer:reindex

  • cache:flush

But Custom Option Not Appears in Front-end



But When i have save product second time after saving product the Options are Appears in Front-end Without need Run any Commands.




I Need Solution to save Product One time and Get Product Option Front End




Is This Possible ?







magento2 event-observer custom-options catalog-product






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Bhavesh MagentoBhavesh Magento

1168




1168












  • I have also the same problems

    – Hardik Makwana
    1 hour ago

















  • I have also the same problems

    – Hardik Makwana
    1 hour ago
















I have also the same problems

– Hardik Makwana
1 hour ago





I have also the same problems

– Hardik Makwana
1 hour ago










2 Answers
2






active

oldest

votes


















1














You can try using a Product Repository MagentoCatalogApiProductCustomOptionRepositoryInterface



Like this:



$product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogApiProductCustomOptionRepositoryInterface')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
$product->save();






share|improve this answer

























  • it is not working and read My Question $product->save() provide me Error No Such Entity

    – Bhavesh Magento
    58 mins ago











  • updated it using ProductCustomOptionRepositoryInterface , using it, save() will work without error

    – magefms
    52 mins ago



















1














Save Product Using ProductRepositoryInterface :-



$option = $this->_objectManager->create(MagentoCatalogModelProductOption::class)
->setProductId($_product->getId())
->setStoreId($_product->getStoreId())
->addData($arrayOption);
$option->save();
$product->addOption($option);
$productRepo = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$productRepo->save($product);





share|improve this answer























  • try this.......

    – Rk Rathod
    29 mins ago











  • it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]

    – Bhavesh Magento
    just now











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%2f273928%2fmagento-2-we-need-to-save-product-two-time-after-generating-custom-option-prog%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can try using a Product Repository MagentoCatalogApiProductCustomOptionRepositoryInterface



Like this:



$product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogApiProductCustomOptionRepositoryInterface')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
$product->save();






share|improve this answer

























  • it is not working and read My Question $product->save() provide me Error No Such Entity

    – Bhavesh Magento
    58 mins ago











  • updated it using ProductCustomOptionRepositoryInterface , using it, save() will work without error

    – magefms
    52 mins ago
















1














You can try using a Product Repository MagentoCatalogApiProductCustomOptionRepositoryInterface



Like this:



$product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogApiProductCustomOptionRepositoryInterface')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
$product->save();






share|improve this answer

























  • it is not working and read My Question $product->save() provide me Error No Such Entity

    – Bhavesh Magento
    58 mins ago











  • updated it using ProductCustomOptionRepositoryInterface , using it, save() will work without error

    – magefms
    52 mins ago














1












1








1







You can try using a Product Repository MagentoCatalogApiProductCustomOptionRepositoryInterface



Like this:



$product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogApiProductCustomOptionRepositoryInterface')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
$product->save();






share|improve this answer















You can try using a Product Repository MagentoCatalogApiProductCustomOptionRepositoryInterface



Like this:



$product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption)
$isHasOptions = $product->getTypeInstance()->hasOptions($product);

$option = MagentoFrameworkAppObjectManager::getInstance()
->create('MagentoCatalogApiProductCustomOptionRepositoryInterface')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);

$this->customoptionOperation($option, 'save');
$product->addOption($option);
$product->save();







share|improve this answer














share|improve this answer



share|improve this answer








edited 56 mins ago

























answered 1 hour ago









magefmsmagefms

3,0252629




3,0252629












  • it is not working and read My Question $product->save() provide me Error No Such Entity

    – Bhavesh Magento
    58 mins ago











  • updated it using ProductCustomOptionRepositoryInterface , using it, save() will work without error

    – magefms
    52 mins ago


















  • it is not working and read My Question $product->save() provide me Error No Such Entity

    – Bhavesh Magento
    58 mins ago











  • updated it using ProductCustomOptionRepositoryInterface , using it, save() will work without error

    – magefms
    52 mins ago

















it is not working and read My Question $product->save() provide me Error No Such Entity

– Bhavesh Magento
58 mins ago





it is not working and read My Question $product->save() provide me Error No Such Entity

– Bhavesh Magento
58 mins ago













updated it using ProductCustomOptionRepositoryInterface , using it, save() will work without error

– magefms
52 mins ago






updated it using ProductCustomOptionRepositoryInterface , using it, save() will work without error

– magefms
52 mins ago














1














Save Product Using ProductRepositoryInterface :-



$option = $this->_objectManager->create(MagentoCatalogModelProductOption::class)
->setProductId($_product->getId())
->setStoreId($_product->getStoreId())
->addData($arrayOption);
$option->save();
$product->addOption($option);
$productRepo = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$productRepo->save($product);





share|improve this answer























  • try this.......

    – Rk Rathod
    29 mins ago











  • it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]

    – Bhavesh Magento
    just now















1














Save Product Using ProductRepositoryInterface :-



$option = $this->_objectManager->create(MagentoCatalogModelProductOption::class)
->setProductId($_product->getId())
->setStoreId($_product->getStoreId())
->addData($arrayOption);
$option->save();
$product->addOption($option);
$productRepo = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$productRepo->save($product);





share|improve this answer























  • try this.......

    – Rk Rathod
    29 mins ago











  • it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]

    – Bhavesh Magento
    just now













1












1








1







Save Product Using ProductRepositoryInterface :-



$option = $this->_objectManager->create(MagentoCatalogModelProductOption::class)
->setProductId($_product->getId())
->setStoreId($_product->getStoreId())
->addData($arrayOption);
$option->save();
$product->addOption($option);
$productRepo = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$productRepo->save($product);





share|improve this answer













Save Product Using ProductRepositoryInterface :-



$option = $this->_objectManager->create(MagentoCatalogModelProductOption::class)
->setProductId($_product->getId())
->setStoreId($_product->getStoreId())
->addData($arrayOption);
$option->save();
$product->addOption($option);
$productRepo = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$productRepo->save($product);






share|improve this answer












share|improve this answer



share|improve this answer










answered 51 mins ago









Rk RathodRk Rathod

1,579214




1,579214












  • try this.......

    – Rk Rathod
    29 mins ago











  • it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]

    – Bhavesh Magento
    just now

















  • try this.......

    – Rk Rathod
    29 mins ago











  • it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]

    – Bhavesh Magento
    just now
















try this.......

– Rk Rathod
29 mins ago





try this.......

– Rk Rathod
29 mins ago













it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]

– Bhavesh Magento
just now





it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]

– Bhavesh Magento
just now

















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%2f273928%2fmagento-2-we-need-to-save-product-two-time-after-generating-custom-option-prog%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

ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу