Call to a member function toHtml() on null Magento 2Magento 2 : How to get product get images for thumbnail?Fatal error: Call to a member function create() on null in Magento 2Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch() | Store InformationFatal error: Call to a member functionMagento 2 Block error of Call to a member function create() on nullGet item collection by sku Magento 2Magento2: Fatal error: Uncaught Error: Call to a member function setProduct()Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch()Fatal error: Uncaught Error: Call to a member function setProductCollection() on boolean inFatal Error: 'Uncaught Error: Call to a member function setCustomPrice() on boolean magento 2.3Uncaught Error: Call to a member function dispatch() on null ViewElementAbstractBlock.php on line 652
A STL-like vector implementation in C++
Can humans ever directly see a few photons at a time? Can a human see a single photon?
Why do all the teams that I have worked with always finish a sprint without completion of all the stories?
Hand soldering SMD 1206 components
Do I have any obligations to my PhD supervisor's requests after I have graduated?
Sci fi short story, robot city that nags people about health
What is the origin of Scooby-Doo's name?
What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?
Find the C-factor of a vote
Did Karl Marx ever use any example that involved cotton and dollars to illustrate the way capital and surplus value were generated?
How do I turn off a repeating trade?
What does "play with your toy’s toys" mean?
Trainee keeps missing deadlines for independent learning
C-152 carb heat on before landing in hot weather?
Long term BTC investing
Can we put equal sign after aggregate functions in sql?
How does Powershell create fake drive labels in Windows?
First-year PhD giving a talk among well-established researchers in the field
Does this Wild Magic result affect the sorcerer or just other creatures?
Archery in modern conflicts
Interaction between Leyline of Anticipation and Teferi, Time Raveler
How does a blind passenger not die, if driver becomes unconscious
Where can I find a database of galactic spectra?
How to make clear to people I don't want to answer their "Where are you from?" question?
Call to a member function toHtml() on null Magento 2
Magento 2 : How to get product get images for thumbnail?Fatal error: Call to a member function create() on null in Magento 2Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch() | Store InformationFatal error: Call to a member functionMagento 2 Block error of Call to a member function create() on nullGet item collection by sku Magento 2Magento2: Fatal error: Uncaught Error: Call to a member function setProduct()Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch()Fatal error: Uncaught Error: Call to a member function setProductCollection() on boolean inFatal Error: 'Uncaught Error: Call to a member function setCustomPrice() on boolean magento 2.3Uncaught Error: Call to a member function dispatch() on null ViewElementAbstractBlock.php on line 652
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to show Product Collection in .phtml file of custom module
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>
in this line i am getting error as
Fatal error: Uncaught Error: Call to a member function toHtml() on
null
anyone please help
i got product Collection By Product ID
$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);
return $this;
magento2 php
add a comment |
I am trying to show Product Collection in .phtml file of custom module
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>
in this line i am getting error as
Fatal error: Uncaught Error: Call to a member function toHtml() on
null
anyone please help
i got product Collection By Product ID
$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);
return $this;
magento2 php
$block->getImage($_item, $image)
returns null. that's what the exception tells you
– Philipp Sander
Jun 14 at 11:28
add getImage() function code
– Rk Rathod
Jun 14 at 11:34
can u place that code??
– Waqar Ali
Jun 14 at 11:36
check my answer
– Rk Rathod
Jun 14 at 11:44
add a comment |
I am trying to show Product Collection in .phtml file of custom module
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>
in this line i am getting error as
Fatal error: Uncaught Error: Call to a member function toHtml() on
null
anyone please help
i got product Collection By Product ID
$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);
return $this;
magento2 php
I am trying to show Product Collection in .phtml file of custom module
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>
in this line i am getting error as
Fatal error: Uncaught Error: Call to a member function toHtml() on
null
anyone please help
i got product Collection By Product ID
$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);
return $this;
magento2 php
magento2 php
edited Jun 14 at 12:00
Aasim Goriya
3,2371 gold badge11 silver badges43 bronze badges
3,2371 gold badge11 silver badges43 bronze badges
asked Jun 14 at 11:21
Waqar AliWaqar Ali
10711 bronze badges
10711 bronze badges
$block->getImage($_item, $image)
returns null. that's what the exception tells you
– Philipp Sander
Jun 14 at 11:28
add getImage() function code
– Rk Rathod
Jun 14 at 11:34
can u place that code??
– Waqar Ali
Jun 14 at 11:36
check my answer
– Rk Rathod
Jun 14 at 11:44
add a comment |
$block->getImage($_item, $image)
returns null. that's what the exception tells you
– Philipp Sander
Jun 14 at 11:28
add getImage() function code
– Rk Rathod
Jun 14 at 11:34
can u place that code??
– Waqar Ali
Jun 14 at 11:36
check my answer
– Rk Rathod
Jun 14 at 11:44
$block->getImage($_item, $image)
returns null. that's what the exception tells you– Philipp Sander
Jun 14 at 11:28
$block->getImage($_item, $image)
returns null. that's what the exception tells you– Philipp Sander
Jun 14 at 11:28
add getImage() function code
– Rk Rathod
Jun 14 at 11:34
add getImage() function code
– Rk Rathod
Jun 14 at 11:34
can u place that code??
– Waqar Ali
Jun 14 at 11:36
can u place that code??
– Waqar Ali
Jun 14 at 11:36
check my answer
– Rk Rathod
Jun 14 at 11:44
check my answer
– Rk Rathod
Jun 14 at 11:44
add a comment |
1 Answer
1
active
oldest
votes
.phtml file
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>
getImage() Function in Block File
<?php
namespace VendorModuleBlock;
class file_name extends Template
protected $imageBuilder;
public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)
$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);
public function getImage($product, $imageId, $attributes = [])
return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();
thank you its working but i am getting an image small
– Waqar Ali
Jun 14 at 11:50
which type image you get ?
– Rk Rathod
Jun 14 at 11:51
image size is very small i
– Waqar Ali
Jun 14 at 11:55
please attach screenshot
– Rk Rathod
Jun 14 at 11:56
1
magento.stackexchange.com/a/234745/72911 check this
– Rk Rathod
Jun 14 at 12:03
|
show 5 more comments
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%2f278388%2fcall-to-a-member-function-tohtml-on-null-magento-2%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
.phtml file
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>
getImage() Function in Block File
<?php
namespace VendorModuleBlock;
class file_name extends Template
protected $imageBuilder;
public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)
$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);
public function getImage($product, $imageId, $attributes = [])
return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();
thank you its working but i am getting an image small
– Waqar Ali
Jun 14 at 11:50
which type image you get ?
– Rk Rathod
Jun 14 at 11:51
image size is very small i
– Waqar Ali
Jun 14 at 11:55
please attach screenshot
– Rk Rathod
Jun 14 at 11:56
1
magento.stackexchange.com/a/234745/72911 check this
– Rk Rathod
Jun 14 at 12:03
|
show 5 more comments
.phtml file
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>
getImage() Function in Block File
<?php
namespace VendorModuleBlock;
class file_name extends Template
protected $imageBuilder;
public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)
$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);
public function getImage($product, $imageId, $attributes = [])
return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();
thank you its working but i am getting an image small
– Waqar Ali
Jun 14 at 11:50
which type image you get ?
– Rk Rathod
Jun 14 at 11:51
image size is very small i
– Waqar Ali
Jun 14 at 11:55
please attach screenshot
– Rk Rathod
Jun 14 at 11:56
1
magento.stackexchange.com/a/234745/72911 check this
– Rk Rathod
Jun 14 at 12:03
|
show 5 more comments
.phtml file
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>
getImage() Function in Block File
<?php
namespace VendorModuleBlock;
class file_name extends Template
protected $imageBuilder;
public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)
$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);
public function getImage($product, $imageId, $attributes = [])
return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();
.phtml file
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>
getImage() Function in Block File
<?php
namespace VendorModuleBlock;
class file_name extends Template
protected $imageBuilder;
public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)
$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);
public function getImage($product, $imageId, $attributes = [])
return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();
edited Jun 14 at 12:01
Aasim Goriya
3,2371 gold badge11 silver badges43 bronze badges
3,2371 gold badge11 silver badges43 bronze badges
answered Jun 14 at 11:44
Rk RathodRk Rathod
2,3703 silver badges16 bronze badges
2,3703 silver badges16 bronze badges
thank you its working but i am getting an image small
– Waqar Ali
Jun 14 at 11:50
which type image you get ?
– Rk Rathod
Jun 14 at 11:51
image size is very small i
– Waqar Ali
Jun 14 at 11:55
please attach screenshot
– Rk Rathod
Jun 14 at 11:56
1
magento.stackexchange.com/a/234745/72911 check this
– Rk Rathod
Jun 14 at 12:03
|
show 5 more comments
thank you its working but i am getting an image small
– Waqar Ali
Jun 14 at 11:50
which type image you get ?
– Rk Rathod
Jun 14 at 11:51
image size is very small i
– Waqar Ali
Jun 14 at 11:55
please attach screenshot
– Rk Rathod
Jun 14 at 11:56
1
magento.stackexchange.com/a/234745/72911 check this
– Rk Rathod
Jun 14 at 12:03
thank you its working but i am getting an image small
– Waqar Ali
Jun 14 at 11:50
thank you its working but i am getting an image small
– Waqar Ali
Jun 14 at 11:50
which type image you get ?
– Rk Rathod
Jun 14 at 11:51
which type image you get ?
– Rk Rathod
Jun 14 at 11:51
image size is very small i
– Waqar Ali
Jun 14 at 11:55
image size is very small i
– Waqar Ali
Jun 14 at 11:55
please attach screenshot
– Rk Rathod
Jun 14 at 11:56
please attach screenshot
– Rk Rathod
Jun 14 at 11:56
1
1
magento.stackexchange.com/a/234745/72911 check this
– Rk Rathod
Jun 14 at 12:03
magento.stackexchange.com/a/234745/72911 check this
– Rk Rathod
Jun 14 at 12:03
|
show 5 more comments
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%2f278388%2fcall-to-a-member-function-tohtml-on-null-magento-2%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
$block->getImage($_item, $image)
returns null. that's what the exception tells you– Philipp Sander
Jun 14 at 11:28
add getImage() function code
– Rk Rathod
Jun 14 at 11:34
can u place that code??
– Waqar Ali
Jun 14 at 11:36
check my answer
– Rk Rathod
Jun 14 at 11:44