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;








1















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();?>









share|improve this question
























  • 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

















1















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();?>









share|improve this question
























  • 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













1












1








1


1






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();?>









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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










2 Answers
2






active

oldest

votes


















0














use above code in phtml file:-



<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>





share|improve this answer























  • 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


















0














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 />';




?>





share|improve this answer

























  • 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











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
);



);













draft saved

draft discarded


















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









0














use above code in phtml file:-



<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>





share|improve this answer























  • 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















0














use above code in phtml file:-



<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>





share|improve this answer























  • 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













0












0








0







use above code in phtml file:-



<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>





share|improve this answer













use above code in phtml file:-



<?php echo $this->getLayout()->createBlock("MagentoCatalogBlockProductProductListUpsell")->setTemplate("Magento_Catalog::product/list/items.phtml")->toHtml();?>






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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













0














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 />';




?>





share|improve this answer

























  • 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















0














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 />';




?>





share|improve this answer

























  • 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













0












0








0







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 />';




?>





share|improve this answer















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 />';




?>






share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?