Magento 2 : set product image programaticallyProducts not showing in frontendStoreviews not showing the same product image after importset product status programaticallymagento 2: set product image urlMagento 2: Product Import Error - Product Type is invalid or not supported. Duplicates found in column names [SOLVED]Set product image size?Magento 2: How to programatically mark product image as hidden from product page?Magento 2 : Upload product image programaticallyMagento 2: Add a product to the cart programmaticallyProgramatically Product Save with Image
Why does putting a dot after the URL remove login information?
Why is the Vasa Museum in Stockholm so Popular?
Which genus do I use for neutral expressions in German?
I am considering a visit to a Nevada brothel. What should I say at the US border?
Find a text string in a file and output only the rest of the text that follows it?
Can chords be inferred from melody alone?
Plato and the knowledge of the forms
What is the German idiom or expression for when someone is being hypocritical against their own teachings?
Make a living as a math programming freelancer?
Can a Hogwarts student refuse the Sorting Hat's decision?
Does the length of a password for Wi-Fi affect speed?
How to approach protecting my code as a research assistant? Should I be worried in the first place?
Can I enter Switzerland with only my London Driver's License?
How does LIDAR avoid getting confused in an environment being scanned by hundreds of other LIDAR?
What are the function of EM and EN spaces?
How to realistically deal with a shield user?
Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?
How to make attic easier to traverse?
In MTG, was there ever a five-color deck that worked well?
How to check a file was encrypted (really & correctly)
What does the ISO setting for mechanical 35mm film cameras actually do?
How do I deal with large amout missing values in a data set without dropping them?
Is there a way to improve my grade after graduation?
…down the primrose path
Magento 2 : set product image programatically
Products not showing in frontendStoreviews not showing the same product image after importset product status programaticallymagento 2: set product image urlMagento 2: Product Import Error - Product Type is invalid or not supported. Duplicates found in column names [SOLVED]Set product image size?Magento 2: How to programatically mark product image as hidden from product page?Magento 2 : Upload product image programaticallyMagento 2: Add a product to the cart programmaticallyProgramatically Product Save with Image
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to upload a product along with product image, please suggest how to set path or upload image for a product.
here is my code
try
$_product->setName($product["name"]);
$_product->setTypeId('simple');
$_product->setAttributeSetId(4);
$_product->setSku($product["sku"]);
$_product->setWebsiteIds(array(1));
$_product->setVisibility(4);
$_product->setDescription($product["description"]);
$_product->setPrice($product["price"]);
$tmpDir = $this->getMediaDirTmpDir();
$this->file->checkAndCreateFolder($tmpDir);
$newFileName = $tmpDir . baseName($imageUrl);
$result = $this->file->read($imageUrl, $newFileName);
if ($result)
/** add saved file to the $product gallery */
$_product->setMediaGallery(array('images'=>array (),'values'=>array ()));
$_product->addImageToMediaGallery(how to set path, what to do,array('image', 'small_image', 'thumbnail'), true, $visible);
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => $product['stockstatus'], //Stock Availability
'qty' => $product['quantity']
)
);
$_product->save();
catch(Exception $e)
echo $e->getMessage();
magento2 product product-images
add a comment |
I want to upload a product along with product image, please suggest how to set path or upload image for a product.
here is my code
try
$_product->setName($product["name"]);
$_product->setTypeId('simple');
$_product->setAttributeSetId(4);
$_product->setSku($product["sku"]);
$_product->setWebsiteIds(array(1));
$_product->setVisibility(4);
$_product->setDescription($product["description"]);
$_product->setPrice($product["price"]);
$tmpDir = $this->getMediaDirTmpDir();
$this->file->checkAndCreateFolder($tmpDir);
$newFileName = $tmpDir . baseName($imageUrl);
$result = $this->file->read($imageUrl, $newFileName);
if ($result)
/** add saved file to the $product gallery */
$_product->setMediaGallery(array('images'=>array (),'values'=>array ()));
$_product->addImageToMediaGallery(how to set path, what to do,array('image', 'small_image', 'thumbnail'), true, $visible);
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => $product['stockstatus'], //Stock Availability
'qty' => $product['quantity']
)
);
$_product->save();
catch(Exception $e)
echo $e->getMessage();
magento2 product product-images
i am suggesting you please try this in test script from root folder and hard code the image path first, if it works then do it dynamically next stackoverflow.com/questions/40259303/…
– Nagaraju Kasa
Aug 14 '17 at 9:36
i did but always gotimage does not exist
this error
– Jay Kapoor
Aug 14 '17 at 9:44
add a comment |
I want to upload a product along with product image, please suggest how to set path or upload image for a product.
here is my code
try
$_product->setName($product["name"]);
$_product->setTypeId('simple');
$_product->setAttributeSetId(4);
$_product->setSku($product["sku"]);
$_product->setWebsiteIds(array(1));
$_product->setVisibility(4);
$_product->setDescription($product["description"]);
$_product->setPrice($product["price"]);
$tmpDir = $this->getMediaDirTmpDir();
$this->file->checkAndCreateFolder($tmpDir);
$newFileName = $tmpDir . baseName($imageUrl);
$result = $this->file->read($imageUrl, $newFileName);
if ($result)
/** add saved file to the $product gallery */
$_product->setMediaGallery(array('images'=>array (),'values'=>array ()));
$_product->addImageToMediaGallery(how to set path, what to do,array('image', 'small_image', 'thumbnail'), true, $visible);
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => $product['stockstatus'], //Stock Availability
'qty' => $product['quantity']
)
);
$_product->save();
catch(Exception $e)
echo $e->getMessage();
magento2 product product-images
I want to upload a product along with product image, please suggest how to set path or upload image for a product.
here is my code
try
$_product->setName($product["name"]);
$_product->setTypeId('simple');
$_product->setAttributeSetId(4);
$_product->setSku($product["sku"]);
$_product->setWebsiteIds(array(1));
$_product->setVisibility(4);
$_product->setDescription($product["description"]);
$_product->setPrice($product["price"]);
$tmpDir = $this->getMediaDirTmpDir();
$this->file->checkAndCreateFolder($tmpDir);
$newFileName = $tmpDir . baseName($imageUrl);
$result = $this->file->read($imageUrl, $newFileName);
if ($result)
/** add saved file to the $product gallery */
$_product->setMediaGallery(array('images'=>array (),'values'=>array ()));
$_product->addImageToMediaGallery(how to set path, what to do,array('image', 'small_image', 'thumbnail'), true, $visible);
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => $product['stockstatus'], //Stock Availability
'qty' => $product['quantity']
)
);
$_product->save();
catch(Exception $e)
echo $e->getMessage();
magento2 product product-images
magento2 product product-images
asked Aug 14 '17 at 9:31
Jay KapoorJay Kapoor
3034 silver badges22 bronze badges
3034 silver badges22 bronze badges
i am suggesting you please try this in test script from root folder and hard code the image path first, if it works then do it dynamically next stackoverflow.com/questions/40259303/…
– Nagaraju Kasa
Aug 14 '17 at 9:36
i did but always gotimage does not exist
this error
– Jay Kapoor
Aug 14 '17 at 9:44
add a comment |
i am suggesting you please try this in test script from root folder and hard code the image path first, if it works then do it dynamically next stackoverflow.com/questions/40259303/…
– Nagaraju Kasa
Aug 14 '17 at 9:36
i did but always gotimage does not exist
this error
– Jay Kapoor
Aug 14 '17 at 9:44
i am suggesting you please try this in test script from root folder and hard code the image path first, if it works then do it dynamically next stackoverflow.com/questions/40259303/…
– Nagaraju Kasa
Aug 14 '17 at 9:36
i am suggesting you please try this in test script from root folder and hard code the image path first, if it works then do it dynamically next stackoverflow.com/questions/40259303/…
– Nagaraju Kasa
Aug 14 '17 at 9:36
i did but always got
image does not exist
this error– Jay Kapoor
Aug 14 '17 at 9:44
i did but always got
image does not exist
this error– Jay Kapoor
Aug 14 '17 at 9:44
add a comment |
1 Answer
1
active
oldest
votes
Simply add this code after product price (No need another code for upload image)
$imagePath = "D:imagesample.jpg"; // path of the image
$_product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), true, false);
$_product->save();
what a stupid answer :)
– HaFiz Umer
Jul 15 at 12:21
is the same path of all the words system ?
– HaFiz Umer
Jul 15 at 12:27
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%2f189042%2fmagento-2-set-product-image-programatically%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
Simply add this code after product price (No need another code for upload image)
$imagePath = "D:imagesample.jpg"; // path of the image
$_product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), true, false);
$_product->save();
what a stupid answer :)
– HaFiz Umer
Jul 15 at 12:21
is the same path of all the words system ?
– HaFiz Umer
Jul 15 at 12:27
add a comment |
Simply add this code after product price (No need another code for upload image)
$imagePath = "D:imagesample.jpg"; // path of the image
$_product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), true, false);
$_product->save();
what a stupid answer :)
– HaFiz Umer
Jul 15 at 12:21
is the same path of all the words system ?
– HaFiz Umer
Jul 15 at 12:27
add a comment |
Simply add this code after product price (No need another code for upload image)
$imagePath = "D:imagesample.jpg"; // path of the image
$_product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), true, false);
$_product->save();
Simply add this code after product price (No need another code for upload image)
$imagePath = "D:imagesample.jpg"; // path of the image
$_product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), true, false);
$_product->save();
edited Oct 22 '17 at 15:44
sv3n
10.2k6 gold badges25 silver badges57 bronze badges
10.2k6 gold badges25 silver badges57 bronze badges
answered Oct 22 '17 at 13:10
Israt Jahan SimuIsrat Jahan Simu
91 bronze badge
91 bronze badge
what a stupid answer :)
– HaFiz Umer
Jul 15 at 12:21
is the same path of all the words system ?
– HaFiz Umer
Jul 15 at 12:27
add a comment |
what a stupid answer :)
– HaFiz Umer
Jul 15 at 12:21
is the same path of all the words system ?
– HaFiz Umer
Jul 15 at 12:27
what a stupid answer :)
– HaFiz Umer
Jul 15 at 12:21
what a stupid answer :)
– HaFiz Umer
Jul 15 at 12:21
is the same path of all the words system ?
– HaFiz Umer
Jul 15 at 12:27
is the same path of all the words system ?
– HaFiz Umer
Jul 15 at 12:27
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%2f189042%2fmagento-2-set-product-image-programatically%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 am suggesting you please try this in test script from root folder and hard code the image path first, if it works then do it dynamically next stackoverflow.com/questions/40259303/…
– Nagaraju Kasa
Aug 14 '17 at 9:36
i did but always got
image does not exist
this error– Jay Kapoor
Aug 14 '17 at 9:44