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
Entering the UK as a British citizen who is a Canadian permanent resident
How to distinguish PICTURE OF ME and PICTURE OF MINE in Chinese?
What kind of SATA connector is this?
What's tha name for when you write multiple voices on same staff? And are there any cons?
return tuple of uncopyable objects
Why are solar panels kept tilted?
Why was Thor doubtful about his worthiness to Mjolnir?
Are rated cable ampacities per conductor or per circuit?
Determine the slope and write the Cartesian equation of the line.
Quote from Leibniz
How do employ ' ("prime") in math mode at the correct depth?
Is there anything special about -1 (0xFFFFFFFF) regarding ADC?
High Memory Utilization in Juniper ACX2100
What is the largest number of identical satellites launched together?
Why do I get two different answers when solving for arclength?
Non-deterministic Finite Automata | Sipser Example 1.16
correct spelling of "carruffel" (fuzz, hustle, all that jazz)
What makes "quality" analog AV cables better than cheap cables?
Why do the lights go out when someone enters the dining room on this ship?
How can dragons propel their breath attacks to a long distance
How can a layman easily get the consensus view of what academia *thinks* about a subject?
Tikz draw contour without some edges, and fill
Anabelian geometry ~ higher category theory
How i can place a block anywhere in Store
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;
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
add a comment |
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
I have also the same problems
– Hardik Makwana
May 9 at 5:19
add a comment |
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
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
magento2 event-observer custom-options catalog-product
asked May 9 at 5:15
Bhavesh MagentoBhavesh Magento
1169
1169
I have also the same problems
– Hardik Makwana
May 9 at 5:19
add a comment |
I have also the same problems
– Hardik Makwana
May 9 at 5:19
I have also the same problems
– Hardik Makwana
May 9 at 5:19
I have also the same problems
– Hardik Makwana
May 9 at 5:19
add a comment |
2 Answers
2
active
oldest
votes
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();
it is not working and read My Question $product->save() provide me Error No Such Entity
– Bhavesh Magento
May 9 at 5:50
updated it usingProductCustomOptionRepositoryInterface
, using it, save() will work without error
– magefms
May 9 at 5:56
No it is not working it will provide me Error [ screencast.com/t/Xp8XahLTV ]
– Bhavesh Magento
May 9 at 7:03
which Magento version you are using?
– magefms
May 9 at 7:30
i have use magento 2.3.1
– Bhavesh Magento
May 9 at 7:37
|
show 1 more comment
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);
try this.......
– Rk Rathod
May 9 at 6:19
it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]
– Bhavesh Magento
May 9 at 6:49
Page Not Found in your screenshot
– Rk Rathod
May 9 at 6:56
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
it is not working and read My Question $product->save() provide me Error No Such Entity
– Bhavesh Magento
May 9 at 5:50
updated it usingProductCustomOptionRepositoryInterface
, using it, save() will work without error
– magefms
May 9 at 5:56
No it is not working it will provide me Error [ screencast.com/t/Xp8XahLTV ]
– Bhavesh Magento
May 9 at 7:03
which Magento version you are using?
– magefms
May 9 at 7:30
i have use magento 2.3.1
– Bhavesh Magento
May 9 at 7:37
|
show 1 more comment
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();
it is not working and read My Question $product->save() provide me Error No Such Entity
– Bhavesh Magento
May 9 at 5:50
updated it usingProductCustomOptionRepositoryInterface
, using it, save() will work without error
– magefms
May 9 at 5:56
No it is not working it will provide me Error [ screencast.com/t/Xp8XahLTV ]
– Bhavesh Magento
May 9 at 7:03
which Magento version you are using?
– magefms
May 9 at 7:30
i have use magento 2.3.1
– Bhavesh Magento
May 9 at 7:37
|
show 1 more comment
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();
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();
edited May 9 at 5:53
answered May 9 at 5:42
magefmsmagefms
3,0502630
3,0502630
it is not working and read My Question $product->save() provide me Error No Such Entity
– Bhavesh Magento
May 9 at 5:50
updated it usingProductCustomOptionRepositoryInterface
, using it, save() will work without error
– magefms
May 9 at 5:56
No it is not working it will provide me Error [ screencast.com/t/Xp8XahLTV ]
– Bhavesh Magento
May 9 at 7:03
which Magento version you are using?
– magefms
May 9 at 7:30
i have use magento 2.3.1
– Bhavesh Magento
May 9 at 7:37
|
show 1 more comment
it is not working and read My Question $product->save() provide me Error No Such Entity
– Bhavesh Magento
May 9 at 5:50
updated it usingProductCustomOptionRepositoryInterface
, using it, save() will work without error
– magefms
May 9 at 5:56
No it is not working it will provide me Error [ screencast.com/t/Xp8XahLTV ]
– Bhavesh Magento
May 9 at 7:03
which Magento version you are using?
– magefms
May 9 at 7:30
i have use magento 2.3.1
– Bhavesh Magento
May 9 at 7:37
it is not working and read My Question $product->save() provide me Error No Such Entity
– Bhavesh Magento
May 9 at 5:50
it is not working and read My Question $product->save() provide me Error No Such Entity
– Bhavesh Magento
May 9 at 5:50
updated it using
ProductCustomOptionRepositoryInterface
, using it, save() will work without error– magefms
May 9 at 5:56
updated it using
ProductCustomOptionRepositoryInterface
, using it, save() will work without error– magefms
May 9 at 5:56
No it is not working it will provide me Error [ screencast.com/t/Xp8XahLTV ]
– Bhavesh Magento
May 9 at 7:03
No it is not working it will provide me Error [ screencast.com/t/Xp8XahLTV ]
– Bhavesh Magento
May 9 at 7:03
which Magento version you are using?
– magefms
May 9 at 7:30
which Magento version you are using?
– magefms
May 9 at 7:30
i have use magento 2.3.1
– Bhavesh Magento
May 9 at 7:37
i have use magento 2.3.1
– Bhavesh Magento
May 9 at 7:37
|
show 1 more comment
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);
try this.......
– Rk Rathod
May 9 at 6:19
it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]
– Bhavesh Magento
May 9 at 6:49
Page Not Found in your screenshot
– Rk Rathod
May 9 at 6:56
add a comment |
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);
try this.......
– Rk Rathod
May 9 at 6:19
it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]
– Bhavesh Magento
May 9 at 6:49
Page Not Found in your screenshot
– Rk Rathod
May 9 at 6:56
add a comment |
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);
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);
answered May 9 at 5:57
Rk RathodRk Rathod
1,714214
1,714214
try this.......
– Rk Rathod
May 9 at 6:19
it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]
– Bhavesh Magento
May 9 at 6:49
Page Not Found in your screenshot
– Rk Rathod
May 9 at 6:56
add a comment |
try this.......
– Rk Rathod
May 9 at 6:19
it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]
– Bhavesh Magento
May 9 at 6:49
Page Not Found in your screenshot
– Rk Rathod
May 9 at 6:56
try this.......
– Rk Rathod
May 9 at 6:19
try this.......
– Rk Rathod
May 9 at 6:19
it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]
– Bhavesh Magento
May 9 at 6:49
it will provide Me Error No such Entity [screencast.com/t/hZhbqSSinL]
– Bhavesh Magento
May 9 at 6:49
Page Not Found in your screenshot
– Rk Rathod
May 9 at 6:56
Page Not Found in your screenshot
– Rk Rathod
May 9 at 6:56
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I have also the same problems
– Hardik Makwana
May 9 at 5:19