How to remove Upsell Products programatically and what is setPosition The Next CEO of Stack Overflowmagento2 loading upsell productsset related/upsell products programatically only works for 1 productMagento 2: Product repository's getList() method doesn't retrieve recent itemsRe-save all products in Magento2 - Weird error has forced me to manually resave products to get configurable options to show up on frontendLoad products without category associationImported image roles are lost on update in Magento 2Magento 2 getPriceInfo returns the same price for every product in collectionMagento 2.2 - Cannot update attribute valueshow to import upsell products magento 2?How to add image roles store-wise to already added image programmatically
Where do students learn to solve polynomial equations these days?
INSERT to a table from a database to other (same SQL Server) using Dynamic SQL
Does Germany produce more waste than the US?
Newlines in BSD sed vs gsed
Won the lottery - how do I keep the money?
Math-accent symbol over parentheses enclosing accented symbol (amsmath)
0 rank tensor vs 1D vector
I want to delete every two lines after 3rd lines in file contain very large number of lines :
Why do airplanes bank sharply to the right after air-to-air refueling?
Why didn't Khan get resurrected in the Genesis Explosion?
What connection does MS Office have to Netscape Navigator?
Prepend last line of stdin to entire stdin
Should I tutor a student who I know has cheated on their homework?
Find non-case sensitive string in a mixed list of elements?
Poetry, calligrams and TikZ/PStricks challenge
Easy to read palindrome checker
WOW air has ceased operation, can I get my tickets refunded?
Why is information "lost" when it got into a black hole?
How is this set of matrices closed under multiplication?
Why the difference in type-inference over the as-pattern in two similar function definitions?
Is there always a complete, orthogonal set of unitary matrices?
Chain wire methods together in Lightning Web Components
Is wanting to ask what to write an indication that you need to change your story?
How to get from Geneva Airport to Metabief, Doubs, France by public transport?
How to remove Upsell Products programatically and what is setPosition
The Next CEO of Stack Overflowmagento2 loading upsell productsset related/upsell products programatically only works for 1 productMagento 2: Product repository's getList() method doesn't retrieve recent itemsRe-save all products in Magento2 - Weird error has forced me to manually resave products to get configurable options to show up on frontendLoad products without category associationImported image roles are lost on update in Magento 2Magento 2 getPriceInfo returns the same price for every product in collectionMagento 2.2 - Cannot update attribute valueshow to import upsell products magento 2?How to add image roles store-wise to already added image programmatically
first at all, I'm totally a newby if it regards Magento 2.
I have a PHP script which I run on the command prompt using: php <program-name>
What this script does is assign Upsell products programatically.
Hereunder an excerpt:
First, I create the link and push to $linkData array;
$productLink = $obj->create('MagentoCatalogApiDataProductLinkInterface')
->setSku($productToUpdate->getSku())
->setLinkedProductSku($productToAdd->getSku())
->setPosition(0)
->setLinkType('upsell');
$linkData[] = $productLink;
After all productLink's are created, I update the upsell products:
$productFinalUpdate = $productRepository->get($productToUpdate->getSku());
$productFinalUpdate->setProductLinks($linkData);
$productRepository->save($productFinalUpdate);
What I'm trying to do is removing all upsell products before reassigning them.
However, I have no clue about the following:
How can I remove all upsell products of a product from my program?
What I tried is this:
Check for a method 'unsetProductLinks' or 'removeProductLinks', but no luck
$productFinalUpdate->setProductLinks(null);
$productFinalUpdate->setProductLinks([$anEmptyArray]);
What is the setPosition() doing exactly?
When I assign 0, 1, 2, 3, 4, it doesn't work with there are no upsell products allready assigned. When I assign 0, it adds the upsell products, but only two of them appear in admin weird enough.
Thanks!
magento2
add a comment |
first at all, I'm totally a newby if it regards Magento 2.
I have a PHP script which I run on the command prompt using: php <program-name>
What this script does is assign Upsell products programatically.
Hereunder an excerpt:
First, I create the link and push to $linkData array;
$productLink = $obj->create('MagentoCatalogApiDataProductLinkInterface')
->setSku($productToUpdate->getSku())
->setLinkedProductSku($productToAdd->getSku())
->setPosition(0)
->setLinkType('upsell');
$linkData[] = $productLink;
After all productLink's are created, I update the upsell products:
$productFinalUpdate = $productRepository->get($productToUpdate->getSku());
$productFinalUpdate->setProductLinks($linkData);
$productRepository->save($productFinalUpdate);
What I'm trying to do is removing all upsell products before reassigning them.
However, I have no clue about the following:
How can I remove all upsell products of a product from my program?
What I tried is this:
Check for a method 'unsetProductLinks' or 'removeProductLinks', but no luck
$productFinalUpdate->setProductLinks(null);
$productFinalUpdate->setProductLinks([$anEmptyArray]);
What is the setPosition() doing exactly?
When I assign 0, 1, 2, 3, 4, it doesn't work with there are no upsell products allready assigned. When I assign 0, it adds the upsell products, but only two of them appear in admin weird enough.
Thanks!
magento2
add a comment |
first at all, I'm totally a newby if it regards Magento 2.
I have a PHP script which I run on the command prompt using: php <program-name>
What this script does is assign Upsell products programatically.
Hereunder an excerpt:
First, I create the link and push to $linkData array;
$productLink = $obj->create('MagentoCatalogApiDataProductLinkInterface')
->setSku($productToUpdate->getSku())
->setLinkedProductSku($productToAdd->getSku())
->setPosition(0)
->setLinkType('upsell');
$linkData[] = $productLink;
After all productLink's are created, I update the upsell products:
$productFinalUpdate = $productRepository->get($productToUpdate->getSku());
$productFinalUpdate->setProductLinks($linkData);
$productRepository->save($productFinalUpdate);
What I'm trying to do is removing all upsell products before reassigning them.
However, I have no clue about the following:
How can I remove all upsell products of a product from my program?
What I tried is this:
Check for a method 'unsetProductLinks' or 'removeProductLinks', but no luck
$productFinalUpdate->setProductLinks(null);
$productFinalUpdate->setProductLinks([$anEmptyArray]);
What is the setPosition() doing exactly?
When I assign 0, 1, 2, 3, 4, it doesn't work with there are no upsell products allready assigned. When I assign 0, it adds the upsell products, but only two of them appear in admin weird enough.
Thanks!
magento2
first at all, I'm totally a newby if it regards Magento 2.
I have a PHP script which I run on the command prompt using: php <program-name>
What this script does is assign Upsell products programatically.
Hereunder an excerpt:
First, I create the link and push to $linkData array;
$productLink = $obj->create('MagentoCatalogApiDataProductLinkInterface')
->setSku($productToUpdate->getSku())
->setLinkedProductSku($productToAdd->getSku())
->setPosition(0)
->setLinkType('upsell');
$linkData[] = $productLink;
After all productLink's are created, I update the upsell products:
$productFinalUpdate = $productRepository->get($productToUpdate->getSku());
$productFinalUpdate->setProductLinks($linkData);
$productRepository->save($productFinalUpdate);
What I'm trying to do is removing all upsell products before reassigning them.
However, I have no clue about the following:
How can I remove all upsell products of a product from my program?
What I tried is this:
Check for a method 'unsetProductLinks' or 'removeProductLinks', but no luck
$productFinalUpdate->setProductLinks(null);
$productFinalUpdate->setProductLinks([$anEmptyArray]);
What is the setPosition() doing exactly?
When I assign 0, 1, 2, 3, 4, it doesn't work with there are no upsell products allready assigned. When I assign 0, it adds the upsell products, but only two of them appear in admin weird enough.
Thanks!
magento2
magento2
edited yesterday
Raj Mohan R
1467
1467
asked 2 days ago
Sander PhamSander Pham
1216
1216
add a comment |
add a comment |
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
);
);
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%2f267874%2fhow-to-remove-upsell-products-programatically-and-what-is-setposition%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
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%2f267874%2fhow-to-remove-upsell-products-programatically-and-what-is-setposition%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