Magento2: Calling upsell block from phtml is not working.Pass Data From PHTML To Block ControllerCalling to custom block from cms page display blank pagecalling block from another blockMagento 2.0.x - Insert block in to the product pageMagento2 rewrite block not workingReview form in pop-up not saving datacall other layout and block in custom phtmlmagento 2 block function not calling my phtmlCalling block from phtml gives an error [Solved]Magento2: Block not created from controller
Can you make an identity from this product?
How to avoid typing 'git' at the begining of every Git command
Are polynomials with the same roots identical?
What is the color of artificial intelligence?
Can a human be transformed into a Mind Flayer?
Write a function that checks if a string starts with or contains something
What aircraft was used as Air Force One for the flight between Southampton and Shannon?
Why does smartdiagram replace the Greek letter xi by a number?
LED not blinking when using a transistor
Do you have to have figures when playing D&D?
Who voices the small round football sized demon in Good Omens?
Did Apple bundle a specific monitor with the Apple II+ for schools?
Electricity free spaceship
Math cases align being colored as a table
Should I put programming books I wrote a few years ago on my resume?
Possible runaway argument using circuitikz
Derivative of a double integral over a circular region
2019 gold coins to share
Getting UPS Power from One Room to Another
Can we completely replace inheritance using strategy pattern and dependency injection?
Please figure out this Pan digital Prince
Why do radiation hardened IC packages often have long leads?
Grep Match and extract
How to publish items after pipeline is finished?
Magento2: Calling upsell block from phtml is not working.
Pass Data From PHTML To Block ControllerCalling to custom block from cms page display blank pagecalling block from another blockMagento 2.0.x - Insert block in to the product pageMagento2 rewrite block not workingReview form in pop-up not saving datacall other layout and block in custom phtmlmagento 2 block function not calling my phtmlCalling block from phtml gives an error [Solved]Magento2: Block not created from controller
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want get up-sell product block. when I am working with XML script block is working. but when I am trying to this in .phtml file it's showing nothing .I do not what is wrong with .phtml and XML data is working good .
step1: For xml this code working good
<block class="MagentoCatalogBlockProductProductListUpsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml" after="product.info.media.video">
<arguments>
<argument name="type" xsi:type="string">upsell</argument>
</arguments>
</block>
Step:2 for .phtml file this code is showing blank
<?php echo $block->getLayout()->createBlock('MagentoCatalogBlockProductProductListUpsell')->setTemplate('Magento_Catalog::product/list/items.phtml')->toHtml();?>
magento-2.1 blocks custom-block
add a comment |
I want get up-sell product block. when I am working with XML script block is working. but when I am trying to this in .phtml file it's showing nothing .I do not what is wrong with .phtml and XML data is working good .
step1: For xml this code working good
<block class="MagentoCatalogBlockProductProductListUpsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml" after="product.info.media.video">
<arguments>
<argument name="type" xsi:type="string">upsell</argument>
</arguments>
</block>
Step:2 for .phtml file this code is showing blank
<?php echo $block->getLayout()->createBlock('MagentoCatalogBlockProductProductListUpsell')->setTemplate('Magento_Catalog::product/list/items.phtml')->toHtml();?>
magento-2.1 blocks custom-block
use $this instead of $block,
– Prasanta Hatui
Jun 9 '17 at 10:03
@ Prasanta Hatui @ No luck it's not working, I do not why it's happen , code is good becouse if i call other template instead of itmes.phtml it's working
– sanjay
Jun 9 '17 at 10:09
add a comment |
I want get up-sell product block. when I am working with XML script block is working. but when I am trying to this in .phtml file it's showing nothing .I do not what is wrong with .phtml and XML data is working good .
step1: For xml this code working good
<block class="MagentoCatalogBlockProductProductListUpsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml" after="product.info.media.video">
<arguments>
<argument name="type" xsi:type="string">upsell</argument>
</arguments>
</block>
Step:2 for .phtml file this code is showing blank
<?php echo $block->getLayout()->createBlock('MagentoCatalogBlockProductProductListUpsell')->setTemplate('Magento_Catalog::product/list/items.phtml')->toHtml();?>
magento-2.1 blocks custom-block
I want get up-sell product block. when I am working with XML script block is working. but when I am trying to this in .phtml file it's showing nothing .I do not what is wrong with .phtml and XML data is working good .
step1: For xml this code working good
<block class="MagentoCatalogBlockProductProductListUpsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml" after="product.info.media.video">
<arguments>
<argument name="type" xsi:type="string">upsell</argument>
</arguments>
</block>
Step:2 for .phtml file this code is showing blank
<?php echo $block->getLayout()->createBlock('MagentoCatalogBlockProductProductListUpsell')->setTemplate('Magento_Catalog::product/list/items.phtml')->toHtml();?>
magento-2.1 blocks custom-block
magento-2.1 blocks custom-block
edited Jun 9 '17 at 9:59
Prasanta Hatui
1,4781514
1,4781514
asked Jun 9 '17 at 9:48
sanjaysanjay
112313
112313
use $this instead of $block,
– Prasanta Hatui
Jun 9 '17 at 10:03
@ Prasanta Hatui @ No luck it's not working, I do not why it's happen , code is good becouse if i call other template instead of itmes.phtml it's working
– sanjay
Jun 9 '17 at 10:09
add a comment |
use $this instead of $block,
– Prasanta Hatui
Jun 9 '17 at 10:03
@ Prasanta Hatui @ No luck it's not working, I do not why it's happen , code is good becouse if i call other template instead of itmes.phtml it's working
– sanjay
Jun 9 '17 at 10:09
use $this instead of $block,
– Prasanta Hatui
Jun 9 '17 at 10:03
use $this instead of $block,
– Prasanta Hatui
Jun 9 '17 at 10:03
@ Prasanta Hatui @ No luck it's not working, I do not why it's happen , code is good becouse if i call other template instead of itmes.phtml it's working
– sanjay
Jun 9 '17 at 10:09
@ Prasanta Hatui @ No luck it's not working, I do not why it's happen , code is good becouse if i call other template instead of itmes.phtml it's working
– sanjay
Jun 9 '17 at 10:09
add a comment |
2 Answers
2
active
oldest
votes
use above code in phtml file:-
<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>
what is new in this code
– sanjay
Jun 9 '17 at 9:56
Jagriti Joshi@No luck it's not working
– sanjay
Jun 9 '17 at 10:08
add a comment |
We can not call upsell block this way from phtml file. Because upsell products are associated with a product.
It will working fine when calling from xml because it retuns upsell products for current product.
If you want to get upsell products from current product then you can try below code:
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$currentProduct = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product');//get current product
if ($currentProduct)
$upSellProducts = $currentProduct->getUpSellProducts();
if (!empty($upSellProducts))
echo '<h3>UpSell Products</h3>';
foreach ($upSellProducts as $upSellProduct)
$productId = $upSellProduct->getId();
$product = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
echo $product->getName().'<br />';
echo $product->getSku().'<br />';
echo $product->getProductUrl().'<br />';
echo $product->getImage().'<br />';
?>
Exception #0 (Exception): Notice: Undefined property: MagentoProductVideoBlockProductViewGalleryInterceptor::$frameworkViewLayout in /opt/lampp/htdocs/daydaybag/vendor/magento/framework/View/TemplateEngine/Php.php on line 110
– sanjay
Jun 9 '17 at 10:29
this error showing after used this
– sanjay
Jun 9 '17 at 10:29
let me check the error
– Prasanta Hatui
Jun 9 '17 at 10:33
@@Prasanta Hatui @you there?
– sanjay
Jun 9 '17 at 12:07
@@Prasanta Hatui @you answer is older . I have used this but this code only return data , does not result default product data
– sanjay
Jun 9 '17 at 12:40
|
show 4 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%2f178231%2fmagento2-calling-upsell-block-from-phtml-is-not-working%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
use above code in phtml file:-
<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>
what is new in this code
– sanjay
Jun 9 '17 at 9:56
Jagriti Joshi@No luck it's not working
– sanjay
Jun 9 '17 at 10:08
add a comment |
use above code in phtml file:-
<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>
what is new in this code
– sanjay
Jun 9 '17 at 9:56
Jagriti Joshi@No luck it's not working
– sanjay
Jun 9 '17 at 10:08
add a comment |
use above code in phtml file:-
<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>
use above code in phtml file:-
<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>
answered Jun 9 '17 at 9:54
Jagriti JoshiJagriti Joshi
374
374
what is new in this code
– sanjay
Jun 9 '17 at 9:56
Jagriti Joshi@No luck it's not working
– sanjay
Jun 9 '17 at 10:08
add a comment |
what is new in this code
– sanjay
Jun 9 '17 at 9:56
Jagriti Joshi@No luck it's not working
– sanjay
Jun 9 '17 at 10:08
what is new in this code
– sanjay
Jun 9 '17 at 9:56
what is new in this code
– sanjay
Jun 9 '17 at 9:56
Jagriti Joshi@No luck it's not working
– sanjay
Jun 9 '17 at 10:08
Jagriti Joshi@No luck it's not working
– sanjay
Jun 9 '17 at 10:08
add a comment |
We can not call upsell block this way from phtml file. Because upsell products are associated with a product.
It will working fine when calling from xml because it retuns upsell products for current product.
If you want to get upsell products from current product then you can try below code:
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$currentProduct = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product');//get current product
if ($currentProduct)
$upSellProducts = $currentProduct->getUpSellProducts();
if (!empty($upSellProducts))
echo '<h3>UpSell Products</h3>';
foreach ($upSellProducts as $upSellProduct)
$productId = $upSellProduct->getId();
$product = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
echo $product->getName().'<br />';
echo $product->getSku().'<br />';
echo $product->getProductUrl().'<br />';
echo $product->getImage().'<br />';
?>
Exception #0 (Exception): Notice: Undefined property: MagentoProductVideoBlockProductViewGalleryInterceptor::$frameworkViewLayout in /opt/lampp/htdocs/daydaybag/vendor/magento/framework/View/TemplateEngine/Php.php on line 110
– sanjay
Jun 9 '17 at 10:29
this error showing after used this
– sanjay
Jun 9 '17 at 10:29
let me check the error
– Prasanta Hatui
Jun 9 '17 at 10:33
@@Prasanta Hatui @you there?
– sanjay
Jun 9 '17 at 12:07
@@Prasanta Hatui @you answer is older . I have used this but this code only return data , does not result default product data
– sanjay
Jun 9 '17 at 12:40
|
show 4 more comments
We can not call upsell block this way from phtml file. Because upsell products are associated with a product.
It will working fine when calling from xml because it retuns upsell products for current product.
If you want to get upsell products from current product then you can try below code:
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$currentProduct = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product');//get current product
if ($currentProduct)
$upSellProducts = $currentProduct->getUpSellProducts();
if (!empty($upSellProducts))
echo '<h3>UpSell Products</h3>';
foreach ($upSellProducts as $upSellProduct)
$productId = $upSellProduct->getId();
$product = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
echo $product->getName().'<br />';
echo $product->getSku().'<br />';
echo $product->getProductUrl().'<br />';
echo $product->getImage().'<br />';
?>
Exception #0 (Exception): Notice: Undefined property: MagentoProductVideoBlockProductViewGalleryInterceptor::$frameworkViewLayout in /opt/lampp/htdocs/daydaybag/vendor/magento/framework/View/TemplateEngine/Php.php on line 110
– sanjay
Jun 9 '17 at 10:29
this error showing after used this
– sanjay
Jun 9 '17 at 10:29
let me check the error
– Prasanta Hatui
Jun 9 '17 at 10:33
@@Prasanta Hatui @you there?
– sanjay
Jun 9 '17 at 12:07
@@Prasanta Hatui @you answer is older . I have used this but this code only return data , does not result default product data
– sanjay
Jun 9 '17 at 12:40
|
show 4 more comments
We can not call upsell block this way from phtml file. Because upsell products are associated with a product.
It will working fine when calling from xml because it retuns upsell products for current product.
If you want to get upsell products from current product then you can try below code:
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$currentProduct = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product');//get current product
if ($currentProduct)
$upSellProducts = $currentProduct->getUpSellProducts();
if (!empty($upSellProducts))
echo '<h3>UpSell Products</h3>';
foreach ($upSellProducts as $upSellProduct)
$productId = $upSellProduct->getId();
$product = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
echo $product->getName().'<br />';
echo $product->getSku().'<br />';
echo $product->getProductUrl().'<br />';
echo $product->getImage().'<br />';
?>
We can not call upsell block this way from phtml file. Because upsell products are associated with a product.
It will working fine when calling from xml because it retuns upsell products for current product.
If you want to get upsell products from current product then you can try below code:
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$currentProduct = $objectManager->get('MagentoFrameworkRegistry')->registry('current_product');//get current product
if ($currentProduct)
$upSellProducts = $currentProduct->getUpSellProducts();
if (!empty($upSellProducts))
echo '<h3>UpSell Products</h3>';
foreach ($upSellProducts as $upSellProduct)
$productId = $upSellProduct->getId();
$product = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
echo $product->getName().'<br />';
echo $product->getSku().'<br />';
echo $product->getProductUrl().'<br />';
echo $product->getImage().'<br />';
?>
edited Jun 9 '17 at 12:26
answered Jun 9 '17 at 10:23
Prasanta HatuiPrasanta Hatui
1,4781514
1,4781514
Exception #0 (Exception): Notice: Undefined property: MagentoProductVideoBlockProductViewGalleryInterceptor::$frameworkViewLayout in /opt/lampp/htdocs/daydaybag/vendor/magento/framework/View/TemplateEngine/Php.php on line 110
– sanjay
Jun 9 '17 at 10:29
this error showing after used this
– sanjay
Jun 9 '17 at 10:29
let me check the error
– Prasanta Hatui
Jun 9 '17 at 10:33
@@Prasanta Hatui @you there?
– sanjay
Jun 9 '17 at 12:07
@@Prasanta Hatui @you answer is older . I have used this but this code only return data , does not result default product data
– sanjay
Jun 9 '17 at 12:40
|
show 4 more comments
Exception #0 (Exception): Notice: Undefined property: MagentoProductVideoBlockProductViewGalleryInterceptor::$frameworkViewLayout in /opt/lampp/htdocs/daydaybag/vendor/magento/framework/View/TemplateEngine/Php.php on line 110
– sanjay
Jun 9 '17 at 10:29
this error showing after used this
– sanjay
Jun 9 '17 at 10:29
let me check the error
– Prasanta Hatui
Jun 9 '17 at 10:33
@@Prasanta Hatui @you there?
– sanjay
Jun 9 '17 at 12:07
@@Prasanta Hatui @you answer is older . I have used this but this code only return data , does not result default product data
– sanjay
Jun 9 '17 at 12:40
Exception #0 (Exception): Notice: Undefined property: MagentoProductVideoBlockProductViewGalleryInterceptor::$frameworkViewLayout in /opt/lampp/htdocs/daydaybag/vendor/magento/framework/View/TemplateEngine/Php.php on line 110
– sanjay
Jun 9 '17 at 10:29
Exception #0 (Exception): Notice: Undefined property: MagentoProductVideoBlockProductViewGalleryInterceptor::$frameworkViewLayout in /opt/lampp/htdocs/daydaybag/vendor/magento/framework/View/TemplateEngine/Php.php on line 110
– sanjay
Jun 9 '17 at 10:29
this error showing after used this
– sanjay
Jun 9 '17 at 10:29
this error showing after used this
– sanjay
Jun 9 '17 at 10:29
let me check the error
– Prasanta Hatui
Jun 9 '17 at 10:33
let me check the error
– Prasanta Hatui
Jun 9 '17 at 10:33
@@Prasanta Hatui @you there?
– sanjay
Jun 9 '17 at 12:07
@@Prasanta Hatui @you there?
– sanjay
Jun 9 '17 at 12:07
@@Prasanta Hatui @you answer is older . I have used this but this code only return data , does not result default product data
– sanjay
Jun 9 '17 at 12:40
@@Prasanta Hatui @you answer is older . I have used this but this code only return data , does not result default product data
– sanjay
Jun 9 '17 at 12:40
|
show 4 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%2f178231%2fmagento2-calling-upsell-block-from-phtml-is-not-working%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
use $this instead of $block,
– Prasanta Hatui
Jun 9 '17 at 10:03
@ Prasanta Hatui @ No luck it's not working, I do not why it's happen , code is good becouse if i call other template instead of itmes.phtml it's working
– sanjay
Jun 9 '17 at 10:09