Magento2: I am getting placeholder images in cron tab. Need to get correct images in cron
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am getting placeholder images in crontab.
Like this:
/pub/static/version1554967977/crontab/_view/en_US/Magento_Catalog/images/product/placeholder/.jpg;
This is wrong image.
How to get product image in cron tab?
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$imageHelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getFile())->resize(500, 500)->getUrl();
magento2 crontab
add a comment |
I am getting placeholder images in crontab.
Like this:
/pub/static/version1554967977/crontab/_view/en_US/Magento_Catalog/images/product/placeholder/.jpg;
This is wrong image.
How to get product image in cron tab?
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$imageHelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getFile())->resize(500, 500)->getUrl();
magento2 crontab
can you share the code that you are using?
– Shoaib Munir
Apr 18 at 5:31
1
Updated my question
– Shiwani
Apr 18 at 5:41
add a comment |
I am getting placeholder images in crontab.
Like this:
/pub/static/version1554967977/crontab/_view/en_US/Magento_Catalog/images/product/placeholder/.jpg;
This is wrong image.
How to get product image in cron tab?
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$imageHelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getFile())->resize(500, 500)->getUrl();
magento2 crontab
I am getting placeholder images in crontab.
Like this:
/pub/static/version1554967977/crontab/_view/en_US/Magento_Catalog/images/product/placeholder/.jpg;
This is wrong image.
How to get product image in cron tab?
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$imageHelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getFile())->resize(500, 500)->getUrl();
magento2 crontab
magento2 crontab
edited Apr 18 at 5:41
Shiwani
asked Apr 18 at 5:28
ShiwaniShiwani
619
619
can you share the code that you are using?
– Shoaib Munir
Apr 18 at 5:31
1
Updated my question
– Shiwani
Apr 18 at 5:41
add a comment |
can you share the code that you are using?
– Shoaib Munir
Apr 18 at 5:31
1
Updated my question
– Shiwani
Apr 18 at 5:41
can you share the code that you are using?
– Shoaib Munir
Apr 18 at 5:31
can you share the code that you are using?
– Shoaib Munir
Apr 18 at 5:31
1
1
Updated my question
– Shiwani
Apr 18 at 5:41
Updated my question
– Shiwani
Apr 18 at 5:41
add a comment |
2 Answers
2
active
oldest
votes
By using block factory you can create List
block object, and by List
block object you can get your image. Try code below
public function __construct(
...
MagentoCatalogModelProduct $productModel,
MagentoFrameworkViewElementBlockFactory $blockFactory)
{
$this->productModel = $productModel
$this->_blockFactory = $blockFactory;
}
In your function, use this:
$imageBlock = $this->_blockFactory->createBlock('MagentoCatalogBlockProductListProduct');
$product = $this->productModel->load($item->getProductId();
$imageType = 'category_page_grid';
$productImage = $imageBlock->getImage($product, $imageType);
$imageUrl = $productImage->getImageUrl();
$productImage = $imageBlock->getImage($product, $imageType); $product is productid right?
– Shiwani
Apr 18 at 6:18
no, the object of product that you have loaded
– Shoaib Munir
Apr 18 at 6:20
Need to get on the behalf of productids
– Shiwani
Apr 18 at 6:22
Updated my answer
– Shoaib Munir
Apr 18 at 6:26
1
Thanks for the reply. This is working in observer. But it's not working in crontab.
– Shiwani
Apr 18 at 8:09
|
show 1 more comment
This is my working code:
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
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%2f270567%2fmagento2-i-am-getting-placeholder-images-in-cron-tab-need-to-get-correct-image%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
By using block factory you can create List
block object, and by List
block object you can get your image. Try code below
public function __construct(
...
MagentoCatalogModelProduct $productModel,
MagentoFrameworkViewElementBlockFactory $blockFactory)
{
$this->productModel = $productModel
$this->_blockFactory = $blockFactory;
}
In your function, use this:
$imageBlock = $this->_blockFactory->createBlock('MagentoCatalogBlockProductListProduct');
$product = $this->productModel->load($item->getProductId();
$imageType = 'category_page_grid';
$productImage = $imageBlock->getImage($product, $imageType);
$imageUrl = $productImage->getImageUrl();
$productImage = $imageBlock->getImage($product, $imageType); $product is productid right?
– Shiwani
Apr 18 at 6:18
no, the object of product that you have loaded
– Shoaib Munir
Apr 18 at 6:20
Need to get on the behalf of productids
– Shiwani
Apr 18 at 6:22
Updated my answer
– Shoaib Munir
Apr 18 at 6:26
1
Thanks for the reply. This is working in observer. But it's not working in crontab.
– Shiwani
Apr 18 at 8:09
|
show 1 more comment
By using block factory you can create List
block object, and by List
block object you can get your image. Try code below
public function __construct(
...
MagentoCatalogModelProduct $productModel,
MagentoFrameworkViewElementBlockFactory $blockFactory)
{
$this->productModel = $productModel
$this->_blockFactory = $blockFactory;
}
In your function, use this:
$imageBlock = $this->_blockFactory->createBlock('MagentoCatalogBlockProductListProduct');
$product = $this->productModel->load($item->getProductId();
$imageType = 'category_page_grid';
$productImage = $imageBlock->getImage($product, $imageType);
$imageUrl = $productImage->getImageUrl();
$productImage = $imageBlock->getImage($product, $imageType); $product is productid right?
– Shiwani
Apr 18 at 6:18
no, the object of product that you have loaded
– Shoaib Munir
Apr 18 at 6:20
Need to get on the behalf of productids
– Shiwani
Apr 18 at 6:22
Updated my answer
– Shoaib Munir
Apr 18 at 6:26
1
Thanks for the reply. This is working in observer. But it's not working in crontab.
– Shiwani
Apr 18 at 8:09
|
show 1 more comment
By using block factory you can create List
block object, and by List
block object you can get your image. Try code below
public function __construct(
...
MagentoCatalogModelProduct $productModel,
MagentoFrameworkViewElementBlockFactory $blockFactory)
{
$this->productModel = $productModel
$this->_blockFactory = $blockFactory;
}
In your function, use this:
$imageBlock = $this->_blockFactory->createBlock('MagentoCatalogBlockProductListProduct');
$product = $this->productModel->load($item->getProductId();
$imageType = 'category_page_grid';
$productImage = $imageBlock->getImage($product, $imageType);
$imageUrl = $productImage->getImageUrl();
By using block factory you can create List
block object, and by List
block object you can get your image. Try code below
public function __construct(
...
MagentoCatalogModelProduct $productModel,
MagentoFrameworkViewElementBlockFactory $blockFactory)
{
$this->productModel = $productModel
$this->_blockFactory = $blockFactory;
}
In your function, use this:
$imageBlock = $this->_blockFactory->createBlock('MagentoCatalogBlockProductListProduct');
$product = $this->productModel->load($item->getProductId();
$imageType = 'category_page_grid';
$productImage = $imageBlock->getImage($product, $imageType);
$imageUrl = $productImage->getImageUrl();
edited Apr 18 at 6:26
answered Apr 18 at 5:53
Shoaib MunirShoaib Munir
2,61021031
2,61021031
$productImage = $imageBlock->getImage($product, $imageType); $product is productid right?
– Shiwani
Apr 18 at 6:18
no, the object of product that you have loaded
– Shoaib Munir
Apr 18 at 6:20
Need to get on the behalf of productids
– Shiwani
Apr 18 at 6:22
Updated my answer
– Shoaib Munir
Apr 18 at 6:26
1
Thanks for the reply. This is working in observer. But it's not working in crontab.
– Shiwani
Apr 18 at 8:09
|
show 1 more comment
$productImage = $imageBlock->getImage($product, $imageType); $product is productid right?
– Shiwani
Apr 18 at 6:18
no, the object of product that you have loaded
– Shoaib Munir
Apr 18 at 6:20
Need to get on the behalf of productids
– Shiwani
Apr 18 at 6:22
Updated my answer
– Shoaib Munir
Apr 18 at 6:26
1
Thanks for the reply. This is working in observer. But it's not working in crontab.
– Shiwani
Apr 18 at 8:09
$productImage = $imageBlock->getImage($product, $imageType); $product is productid right?
– Shiwani
Apr 18 at 6:18
$productImage = $imageBlock->getImage($product, $imageType); $product is productid right?
– Shiwani
Apr 18 at 6:18
no, the object of product that you have loaded
– Shoaib Munir
Apr 18 at 6:20
no, the object of product that you have loaded
– Shoaib Munir
Apr 18 at 6:20
Need to get on the behalf of productids
– Shiwani
Apr 18 at 6:22
Need to get on the behalf of productids
– Shiwani
Apr 18 at 6:22
Updated my answer
– Shoaib Munir
Apr 18 at 6:26
Updated my answer
– Shoaib Munir
Apr 18 at 6:26
1
1
Thanks for the reply. This is working in observer. But it's not working in crontab.
– Shiwani
Apr 18 at 8:09
Thanks for the reply. This is working in observer. But it's not working in crontab.
– Shiwani
Apr 18 at 8:09
|
show 1 more comment
This is my working code:
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
add a comment |
This is my working code:
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
add a comment |
This is my working code:
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
This is my working code:
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($item->getProductId());
$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();
$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
answered Apr 18 at 8:08
ShiwaniShiwani
619
619
add a comment |
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%2f270567%2fmagento2-i-am-getting-placeholder-images-in-cron-tab-need-to-get-correct-image%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
can you share the code that you are using?
– Shoaib Munir
Apr 18 at 5:31
1
Updated my question
– Shiwani
Apr 18 at 5:41