Post by scottyboyyy » Mon May 21, 2018 9:03 pm

I am trying to show my products twice on the category.tpl, once as standard with the limit and pagination. The other so it just shows every product in that category that is on special offer possibly still with pagination or just all the products that are on special offer.

I plan to have a tab / accordion style where you can click to see all products (limited to 10 per page with multiple pages) or all products on the one page that are on special offer (no limits).

There are possibly ways of doing this by filter but I would really like to get it to work separately within the category.php (controller). Or better still if I could get it to work together with the current array the products use (not sure if that would be possible to differentiate).

So far I have tried cloning the products data array in the controller to try and make it work on it's own without limit - the closest I can get is where it only shows the products on special offer from the current pagination.

Here is what I've got at the moment (currently php error message: Undefined index: special - from the category.tpl if statement):

Category.php (controller)

Code: Select all

  

    $data['specials'] = array();
            
    $filter_specials = array(
    'filter_category_id' => $category_id,
    'filter_filter'      => $filter,
    'sort'               => $sort,
    'start'              => ($page - 1) * $limit * 0,
    'limit'              => 10000
    );

    $specials = $this->model_catalog_product->getProducts($filter_specials);	
        
    foreach ($specials as $result) {
    $data['specials'][] = array(
    'product_id'  => $result['product_id'],
    'name'        => $result['name'],
    'price'       => $price,
    'special'     => $special,
     );
    }	

I have tried to mimic the results as result that the products use in the category.php.

Category.tpl:

Code: Select all

    <?php foreach ($specials as $product) { ?>
    <?php if ($product['special']) { ?>
    <?php echo $product['name']; ?></h4>
    <?php } ?>
    <?php } ?>

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by yodapt » Mon May 21, 2018 10:10 pm

Code: Select all

<?php foreach ($specials as $product) { ?>
    <?php echo $product['name']; ?></h4>
    <?php } ?>
.. and the error is gone. As for the rest, you have more work to do, to differenciate filters and pagination for both lists. What would the default filter influence anyway, both lists or just one?

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by scottyboyyy » Mon May 21, 2018 10:27 pm

yodapt wrote:
Mon May 21, 2018 10:10 pm

Code: Select all

<?php foreach ($specials as $product) { ?>
    <?php echo $product['name']; ?></h4>
    <?php } ?>
.. and the error is gone. As for the rest, you have more work to do, to differenciate filters and pagination for both lists. What would the default filter influence anyway, both lists or just one?
But then it says the same about the "name". Undefined index: name. It doesn't seem to detect my new specials array values or I am just unable to access them for the tpl through missing something or something isn't worded correctly. Any ideas?

As for removing the if special, I need that so that it doesn't show all products. I only want the special offer products to show.

I wouldn't use the default filter for either, the only thing I would eventually want to do is sort the specials by time / date added by default (so the newest special offers always at the top).

I have found something similar but for 1.5 and specials.tpl so I'm not sure how easy it would be to do this on 2.3.0.2 and category using a duplicate array for specials: viewtopic.php?t=25266

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by yodapt » Mon May 21, 2018 10:30 pm

Did you check that controller to see if that variable ($data['specials'] ) is being set somewhere? Maybe it's being re-defined down the file and you are actually dealing with another dataset.

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by scottyboyyy » Mon May 21, 2018 11:09 pm

yodapt wrote:
Mon May 21, 2018 10:30 pm
Did you check that controller to see if that variable ($data['specials'] ) is being set somewhere? Maybe it's being re-defined down the file and you are actually dealing with another dataset.
I'm setting it beside

Code: Select all

$data['products'] = array();
as

Code: Select all

$data['specials'] = array(); 
at the top of the controller. It isn't redefined anywhere else.

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by scottyboyyy » Mon May 21, 2018 11:22 pm

Code: Select all

 echo json_encode($specials);
Adding this to the controller the array is giving me:

Code: Select all

"[{\"product_id\":\"42\",\"name\":\"Apple Cinema 30"\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"30\",\"name\":\"Canon EOS 5D\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"47\",\"name\":\"HP LP3065\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"28\",\"name\":\"HTC Touch HD\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"40\",\"name\":\"iPhone\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"48\",\"name\":\"iPod Classic\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"43\",\"name\":\"MacBook\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"44\",\"name\":\"MacBook Air\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"29\",\"name\":\"Palm Treo Pro\",\"price\":\"$122.00\",\"special\":false},{\"product_id\":\"35\",\"name\":\"Product 8\",\"price\":\"$122.00\",\"special\":false}]"
I'm unsure why they are all set to false for special when many of those products do have special offers.

I think my other problem is possibly communicating with the tpl to extract the data into the for each loop. I have tried every combination I can think of but:

Code: Select all

<?php foreach ($specials as $product) { ?>
Is this right?

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by yodapt » Tue May 22, 2018 1:03 am

If it's set to false it's not being added from the model possibly, try dumping what comes out of the query.

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by scottyboyyy » Tue May 22, 2018 2:19 am

yodapt wrote:
Tue May 22, 2018 1:03 am
If it's set to false it's not being added from the model possibly, try dumping what comes out of the query.
Okay I got it working from that! Thanks a lot for your help!

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am
Who is online

Users browsing this forum: No registered users and 293 guests