Page 1 of 2
Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 5:41 pm
by loop
Hi all
I have a Filter Product Filter in index.php and i would like to load with jquery only the products, when Filtering, so if i select "Sony" as a Brand, i like without a pager reload to show sony products. (with page reload everything works as expected)
So in my external file (/ext/scripts/ajax_filter.php) i want to make the HTML Code to show.
Code: Select all
if($_POST['jquery_action'] == "show_products"){
$listing_sql = "SELECT p.products_id, p.products_price, p.verfuegbarkeit, p.energie_label, p.energie_label_image, p.products_tax_class_id, p.products_image, p.products_ordered, p.products_date_added, p2c.categories_id, pd.products_name, m.manufacturers_id,m.manufacturers_name,cd.categories_name,p.verfuegbarkeit AS in_stock FROM products p INNER JOIN products_description pd ON p.products_id = pd.products_id INNER JOIN products_to_categories p2c ON p.products_id = p2c.products_id INNER JOIN categories_description cd ON p2c.categories_id = cd.categories_id LEFT JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id AND (m.manufacturers_id = '83' OR m.manufacturers_id = '172') and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '2' and cd.language_id = '2' and p2c.categories_id = '22' ORDER BY products_bestseller DESC";
ob_start();
include $GLOBALS['Template']->map(DIR_FS_CATALOG . 'includes/modules/content/index_products/cm_ip_product_listing_v2.php');
$_POST['html'] = ob_get_clean();
}
echo json_encode($_POST);
but this does not work, as i get alot errors with undefined variables:
Code: Select all
<b>Notice</b>: Undefined variable: content_width in <b>/mnt/lamp-www-data/beta_shop/includes/modules/content/index_products/templates/tpl_cm_ip_product_listing_v2.php</b> on line <b>1</b><br />
cm-ip-product-listing">
<br />
<b>Notice</b>: Undefined variable: num_list in <b>/mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing.php</b> on line <b>13</b><br />
<br />
<b>Warning</b>: Division by zero in <b>/mnt/lamp-www-data/beta_shop/includes/system/versioned/1.0.8.4/split_page_results.php</b> on line <b>66</b><br />
what do i miss? can somebody point me in the right direction? Thank you in advance!
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 6:45 pm
by ecartz
$num_list is the number of products to show per page. $content_width is a number from 1 to 12. You could just set it to MODULE_CONTENT_IP_PRODUCT_LISTING_CONTENT_WIDTH
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 6:57 pm
by loop
hi ecartz, i did this already, but this is not the only error
Code: Select all
<div class="col-sm-12 cm-ip-product-listing">
<div class="contentText">
<div class="card mb-2 card-body alert-filters">
<ul class="nav">
<li class="nav-item dropdown">
<a href="#" class="nav-link text-dark dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Sort By <span class="caret"></span></a>
<div class="dropdown-menu">
<br />
<b>Notice</b>: Undefined variable: column_list in <b>/mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing.php</b> on line <b>44</b><br />
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing.php</b> on line <b>44</b><br />
</div>
</li>
</ul>
</div>
<div class="row pt-2"><br />
<b>Notice</b>: Undefined variable: category_tree in <b>/mnt/lamp-www-data/beta_shop/templates/override/includes/components/product_card.php</b> on line <b>8</b><br />
<br />
<b>Fatal error</b>: Uncaught Error: Call to a member function find_path() on null in /mnt/lamp-www-data/beta_shop/templates/override/includes/components/product_card.php:8
Stack trace:
#0 /mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing.php(78): include()
#1 /mnt/lamp-www-data/beta_shop/includes/modules/content/index_products/templates/tpl_cm_ip_product_listing_v2.php(2): include('/mnt/lamp-www-d...')
#2 /mnt/lamp-www-data/beta_shop/ext/scripts/ajax_filter.php(220): include('/mnt/lamp-www-d...')
#3 {main}
thrown in <b>/mnt/lamp-www-data/beta_shop/templates/override/includes/components/product_card.php</b> on line <b>8</b><br />
i'm probably missing something in the my external ajax script, as there are these errors....maybe i have to include something which is "normaly" in the product_listing.php available?
or something is not good with this idea:
Code: Select all
$num_list = 24;
ob_start();
include $GLOBALS['Template']->map(DIR_FS_CATALOG . 'includes/modules/content/index_products/cm_ip_product_listing_v2.php');
$_POST['html'] = ob_get_clean();
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 7:29 pm
by ecartz
If you change $category_tree to Guarantor::ensure_global('category_tree') that error will go away.
My guess would be that you are not setting the category_tree when you filter. But you have a custom product card that requires the category tree.
The other possibility would be that you aren't including application_top.php.
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 7:46 pm
by loop
you are right, i changed the line and the error is gone and i'm a step further...
(application_top.php is included ..)
Code: Select all
$content_width = '12';
$num_list = 24;
$listing_sql = "SELECT p.products_id, p.products_price, p.verfuegbarkeit, p.energie_label, p.energie_label_image, p.products_tax_class_id, p.products_image, p.products_ordered, p.products_date_added, p2c.categories_id, pd.products_name, m.manufacturers_id,m.manufacturers_name,cd.categories_name,p.verfuegbarkeit AS in_stock FROM products p INNER JOIN products_description pd ON p.products_id = pd.products_id INNER JOIN products_to_categories p2c ON p.products_id = p2c.products_id INNER JOIN categories_description cd ON p2c.categories_id = cd.categories_id LEFT JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id AND (m.manufacturers_id = '83' OR m.manufacturers_id = '172') and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '2' and cd.language_id = '2' and p2c.categories_id = '22' ORDER BY products_bestseller DESC";
/* $_GET['action'] = "super_filter";
$_GET['current_category_id']=22;
$_GET['manufacturers_filter_id_arr']=83; */
ob_start();
include $Template->map(DIR_FS_CATALOG . 'includes/modules/content/index_products/cm_ip_product_listing_v2.php');
$_POST['html'] = ob_get_clean();
if i put the $listing_sql before the product_listing.php include it work, but this was only for testing and i don't get it why i receive errors, as soon as i delete this line.
$listing_sql should be created in the cm_ip_product_listing_v2.php, any ideas?
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 8:27 pm
by ecartz
loop wrote: ↑Thu Mar 03, 2022 7:46 pm
$listing_sql should be created in the cm_ip_product_listing_v2.php, any ideas?
You aren't calling cm_ip_product_listing_v2.php -- that would look like
Code: Select all
(new cm_ip_product_listing_v2())->execute();
Assuming that it is the same as the regular one.
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 8:40 pm
by loop
I really do not get on here, sorry very much! You're certainly right that I do not explicitly this (also did not know that one must, thought that makes the ->map itself
i tried it like this and on every other places in the ext script, but the error with the missing listing is still there.
<b>Notice</b>: Undefined variable: listing_sql in <b>/mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing.php</b> on line <b>13</b><br />
Code: Select all
$_GET['action'] = "super_filter";
$_GET['current_category_id']=22;
$_GET['manufacturers_filter_id_arr[]']=83;
ob_start();
include $Template->map(DIR_FS_CATALOG . 'includes/modules/content/index_products/cm_ip_product_listing_v2.php');
(new cm_ip_product_listing_v2())->execute();
$_POST['html'] = ob_get_clean();
Again sorry for the trouble and I appreciate your help insanely!
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 8:50 pm
by ecartz
Delete
Code: Select all
include $Template->map(DIR_FS_CATALOG . 'includes/modules/content/index_products/cm_ip_product_listing_v2.php');
As the cm_ip_product_listing already does that part. If that makes it missing entirely, then put that line last in the execute method.
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 8:59 pm
by loop
after deleting the line, all errors are gone, but also the html (so its gone entirely as you wrote...) i'm ashamed but i don't understand what you mean with "then put that line last in the execute method."
you mean i should place it in cm_ip_product_listing_v2.php in the function execute? (i don't think so, but if i do that, i have the product_listing twice on my page once at the top and one at the normal place... and the error about the missing <b>Notice</b>: Undefined variable: listing_sql in <b>/mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing.php</b> on line <b>13</b><br /> after executing the jquey is still here)
my full ext/script is at the moment:
Code: Select all
chdir('../../');
require('includes/application_top.php');
$navigation->remove_current_page();
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {
die(':-\\');
}
}
if($_POST['jquery_action'] == "show_products"){
$content_width = '12';
$num_list = 24;
$_GET['action'] = "super_filter";
$_GET['current_category_id']=22;
$_GET['manufacturers_filter_id_arr[]']=83;
ob_start();
(new cm_ip_product_listing_v2())->execute();
$_POST['html'] = ob_get_clean();
}
echo json_encode($_POST);
Re: Trying to dynamic load cm_ip_product_listing.php
Posted: Thu Mar 03, 2022 10:11 pm
by ecartz
loop wrote: ↑Thu Mar 03, 2022 8:59 pm
you mean i should place it in cm_ip_product_listing_v2.php in the function execute?
Yes. If it's appearing twice, then find the other place and remove it from there. Perhaps
Code: Select all
$tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
include 'includes/modules/content/cm_template.php';
Or something more complicated like
Code: Select all
if (Request::get_page() === 'ext/scripts/ajax_filter.php') {
include $GLOBALS['Template']->map(DIR_FS_CATALOG . 'includes/modules/content/index_products/cm_ip_product_listing_v2.php');
} else {
$tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
include 'includes/modules/content/cm_template.php';
}