Filter product with Ajax and return Json Array from a controller to show in a phtml fileHow to create the an ajax call to return spConfig json with product sku (product options)pass data from phtml file to controllerReturn bool gives error “Invalid return type” for Ajax ControllerRetreive and return response from controller in magento2Magento 1.9.3.3 - How do you return a JSON array from a controller to ajaxMagento2, need help with ajax return data processing from controller which is string of html tagsMagento 2 - Send form data to Controller using AJAX and return Result to PHTMLreturn array of json after call ajax magento 1.9.3.xreturn phtml file content in ajax response in magento2Return as json instead of Html from controller renderlayout

TeX Gyre Pagella Math Integral sign much too small

What are these round pads on the bottom of a PCB?

Hexagonal Grid Filling

Do Monks gain the 9th level Unarmored Movement benefit when wearing armor or using a shield?

Double underlining a result in a system of equations with calculation steps on the right side

Is it a Munchausen Number?

What dice to use in a game that revolves around triangles?

Why did they wait for Quill to arrive?

Did the IBM System/4 Pi computer have radiation-hardened versions for Skylab and Shuttle?

Row vectors and column vectors (Mathematica vs Matlab)

Is it a good idea to copy a trader when investing?

Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1

What's the "magic similar to the Knock spell" referenced in the Dungeon of the Mad Mage adventure?

Can the president of the United States be guilty of insider trading?

What is the status of the three crises in the history of mathematics?

Is it safe to keep the GPU on 100% utilization for a very long time?

How long can fsck take on a 30 TB volume?

Why does the electron wavefunction not collapse within atoms at room temperature in gas, liquids or solids due to decoherence?

Can a planet still function with a damaged moon?

Why is valarray so slow on VS2015?

Publishing an article in a journal without a related degree

How can I test a shell script in a "safe environment" to avoid harm to my computer?

Ugin's Conjurant vs. un-preventable damage

Does STATISTICS IO output include Version Store reads?



Filter product with Ajax and return Json Array from a controller to show in a phtml file


How to create the an ajax call to return spConfig json with product sku (product options)pass data from phtml file to controllerReturn bool gives error “Invalid return type” for Ajax ControllerRetreive and return response from controller in magento2Magento 1.9.3.3 - How do you return a JSON array from a controller to ajaxMagento2, need help with ajax return data processing from controller which is string of html tagsMagento 2 - Send form data to Controller using AJAX and return Result to PHTMLreturn array of json after call ajax magento 1.9.3.xreturn phtml file content in ajax response in magento2Return as json instead of Html from controller renderlayout






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Is it possible to return an array from a controller or from a block function to the phtml file?



<?php

namespace MnuhellFormSearchAttributesControllerIndex;

use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkRegistry;
use MagentoFrameworkViewResultPageFactory;


class Search extends Action


/**
* @var PageFactory
*/
protected $_resultPageFactory;

protected $_resultJsonFactory;

protected $_coreRegistry;


public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $_resultJsonFactory, Registry $_coreRegistry)

$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $_resultJsonFactory;
$this->_coreRegistry = $_coreRegistry;
parent::__construct($context);


public function execute()



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();

$minPrice = $this->getRequest()->getParam('minPrice');
$maxPrice = $this->getRequest()->getParam('maxPrice');
$minQty = $this->getRequest()->getParam('minQty');
$maxQty = $this->getRequest()->getParam('maxQty');
//$category = $this->getRequest()->getParam('category');

if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty == "undefined" AND $maxQty == "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice and prec.value < $maxPrice
group by cat.entity_id ";


$result = $connection->fetchAll($sql);


if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty != "undefined" AND $maxQty != "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice AND prec.value < $maxPrice
AND stock.qty > $minQty group by cat.entity_id";

$result = $connection->fetchAll($sql);


$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2 group by cat.entity_id";

$result = $connection->fetchAll($sql);

$resultJson = $this->_resultJsonFactory->create($result);

$collection = $resultJson->setData($result);

return $collection;





How I can return collection array json in a phtml file?



Thanks!!










share|improve this question
























  • check this stackoverflow.com/questions/38220376/…

    – magefms
    2 days ago

















1















Is it possible to return an array from a controller or from a block function to the phtml file?



<?php

namespace MnuhellFormSearchAttributesControllerIndex;

use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkRegistry;
use MagentoFrameworkViewResultPageFactory;


class Search extends Action


/**
* @var PageFactory
*/
protected $_resultPageFactory;

protected $_resultJsonFactory;

protected $_coreRegistry;


public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $_resultJsonFactory, Registry $_coreRegistry)

$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $_resultJsonFactory;
$this->_coreRegistry = $_coreRegistry;
parent::__construct($context);


public function execute()



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();

$minPrice = $this->getRequest()->getParam('minPrice');
$maxPrice = $this->getRequest()->getParam('maxPrice');
$minQty = $this->getRequest()->getParam('minQty');
$maxQty = $this->getRequest()->getParam('maxQty');
//$category = $this->getRequest()->getParam('category');

if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty == "undefined" AND $maxQty == "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice and prec.value < $maxPrice
group by cat.entity_id ";


$result = $connection->fetchAll($sql);


if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty != "undefined" AND $maxQty != "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice AND prec.value < $maxPrice
AND stock.qty > $minQty group by cat.entity_id";

$result = $connection->fetchAll($sql);


$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2 group by cat.entity_id";

$result = $connection->fetchAll($sql);

$resultJson = $this->_resultJsonFactory->create($result);

$collection = $resultJson->setData($result);

return $collection;





How I can return collection array json in a phtml file?



Thanks!!










share|improve this question
























  • check this stackoverflow.com/questions/38220376/…

    – magefms
    2 days ago













1












1








1








Is it possible to return an array from a controller or from a block function to the phtml file?



<?php

namespace MnuhellFormSearchAttributesControllerIndex;

use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkRegistry;
use MagentoFrameworkViewResultPageFactory;


class Search extends Action


/**
* @var PageFactory
*/
protected $_resultPageFactory;

protected $_resultJsonFactory;

protected $_coreRegistry;


public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $_resultJsonFactory, Registry $_coreRegistry)

$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $_resultJsonFactory;
$this->_coreRegistry = $_coreRegistry;
parent::__construct($context);


public function execute()



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();

$minPrice = $this->getRequest()->getParam('minPrice');
$maxPrice = $this->getRequest()->getParam('maxPrice');
$minQty = $this->getRequest()->getParam('minQty');
$maxQty = $this->getRequest()->getParam('maxQty');
//$category = $this->getRequest()->getParam('category');

if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty == "undefined" AND $maxQty == "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice and prec.value < $maxPrice
group by cat.entity_id ";


$result = $connection->fetchAll($sql);


if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty != "undefined" AND $maxQty != "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice AND prec.value < $maxPrice
AND stock.qty > $minQty group by cat.entity_id";

$result = $connection->fetchAll($sql);


$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2 group by cat.entity_id";

$result = $connection->fetchAll($sql);

$resultJson = $this->_resultJsonFactory->create($result);

$collection = $resultJson->setData($result);

return $collection;





How I can return collection array json in a phtml file?



Thanks!!










share|improve this question
















Is it possible to return an array from a controller or from a block function to the phtml file?



<?php

namespace MnuhellFormSearchAttributesControllerIndex;

use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkControllerResultJsonFactory;
use MagentoFrameworkRegistry;
use MagentoFrameworkViewResultPageFactory;


class Search extends Action


/**
* @var PageFactory
*/
protected $_resultPageFactory;

protected $_resultJsonFactory;

protected $_coreRegistry;


public function __construct(Context $context, PageFactory $resultPageFactory, JsonFactory $_resultJsonFactory, Registry $_coreRegistry)

$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $_resultJsonFactory;
$this->_coreRegistry = $_coreRegistry;
parent::__construct($context);


public function execute()



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();

$minPrice = $this->getRequest()->getParam('minPrice');
$maxPrice = $this->getRequest()->getParam('maxPrice');
$minQty = $this->getRequest()->getParam('minQty');
$maxQty = $this->getRequest()->getParam('maxQty');
//$category = $this->getRequest()->getParam('category');

if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty == "undefined" AND $maxQty == "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice and prec.value < $maxPrice
group by cat.entity_id ";


$result = $connection->fetchAll($sql);


if($minPrice != "undefined" AND $maxPrice != "undefined" AND $minQty != "undefined" AND $maxQty != "undefined")

$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2
AND prec.value > $minPrice AND prec.value < $maxPrice
AND stock.qty > $minQty group by cat.entity_id";

$result = $connection->fetchAll($sql);


$sql = "SELECT cat.entity_id, cat1.value, count(prod.entity_id) AS totals FROM catalog_category_entity as cat
LEFT JOIN catalog_category_entity_varchar as cat1 ON cat.entity_id = cat1.entity_id
INNER JOIN catalog_category_product as catprod ON catprod.category_id = cat.entity_id
INNER JOIN catalog_product_entity as prod ON prod.entity_id = catprod.product_id
LEFT JOIN catalog_product_entity_decimal as prec on prec.entity_id = prod.entity_id
LEFT JOIN cataloginventory_stock_item AS stock ON stock.product_id = prod.entity_id
where children_count > 0 and cat1.attribute_id = 45 and cat.entity_id > 2 group by cat.entity_id";

$result = $connection->fetchAll($sql);

$resultJson = $this->_resultJsonFactory->create($result);

$collection = $resultJson->setData($result);

return $collection;





How I can return collection array json in a phtml file?



Thanks!!







magento2 product ajax filter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









magefms

3,0152629




3,0152629










asked May 6 at 4:52









manuelvillagrdomanuelvillagrdo

62




62












  • check this stackoverflow.com/questions/38220376/…

    – magefms
    2 days ago

















  • check this stackoverflow.com/questions/38220376/…

    – magefms
    2 days ago
















check this stackoverflow.com/questions/38220376/…

– magefms
2 days ago





check this stackoverflow.com/questions/38220376/…

– magefms
2 days ago










0






active

oldest

votes












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%2f273470%2ffilter-product-with-ajax-and-return-json-array-from-a-controller-to-show-in-a-ph%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f273470%2ffilter-product-with-ajax-and-return-json-array-from-a-controller-to-show-in-a-ph%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

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form