Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Excluding Products Without Image Rate Topic   - - - - -

 
  • Tice
  • Newbie
  • Members
  • Join Date: 10-Dec 17
  • 14 posts

Posted 14 March 2018 - 04:14 PM #1

if (Registry::get('settings.General.inventory_tracking') == 'Y' && // FIXME? Registry in model
        Registry::get('settings.General.show_out_of_stock_products') == 'N' &&
        $params['area'] == 'C'
    ) {
        $condition .= db_quote(
            ' AND (CASE products.tracking' .
            '   WHEN ?s THEN inventory.amount > products.min_stock' .
            '   WHEN ?s THEN products.amount > products.min_stock' .
            '   ELSE 1' .
            ' END)',
            ProductTracking::TRACK_WITH_OPTIONS,
            ProductTracking::TRACK_WITHOUT_OPTIONS
        );
    }

The above is an excerpt from fn.catalog.php in which I exclude products from being shown if they don't have more than a database-specified stock value. How would I access the other databases for images and image links in order to effectively prevent products without images from being displayed?



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10551 posts

Posted 14 March 2018 - 06:30 PM #2

You should use the 'get_product_data_pre' hook and adjust the JOINs to use an INNER JOIN for the product image links.

Alternatively, you can use the get_product_data_post hook to check the data and return an empty array if your conditions aren't met. But you will have wasted an expensive DB query.  But it's a lot easier to get right! :-)  

 

You should NOT be modifying core files for these changes.  It will only cause you upgrade headaches in the future.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 17267 posts

Posted 15 March 2018 - 06:42 AM #3

Just check cscart_images_links table with object_id = PRODUCT_ID and object_type = 'product'

 

If image_id or detailed_id parameters. At least one of them should not be empty


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Tice
  • Newbie
  • Members
  • Join Date: 10-Dec 17
  • 14 posts

Posted 19 March 2018 - 05:12 PM #4

Just check cscart_images_links table with object_id = PRODUCT_ID and object_type = 'product'

 

If image_id or detailed_id parameters. At least one of them should not be empty

Like this?

$condition .= db_quote(
            ' AND (CASE products.tracking' .
            '   WHEN ?s THEN inventory.amount > products.min_stock' .
            '   WHEN ?s THEN products.amount > products.min_stock' .
			'   WHEN ?s THEN (SELECT ?:images_links.image_id FROM ?:images_links WHERE ?:images_links.object_id=products.product_id AND ?:images_links.object_type = "product") != 0' .
			'   WHEN ?s THEN (SELECT ?:images_links.detailed_id FROM ?:images_links WHERE ?:images_links.object_id=products.product_id AND ?:images_links.object_type = "product") != 0' .
            '   ELSE 1' .
            ' END)',
            ProductTracking::TRACK_WITH_OPTIONS,
            ProductTracking::TRACK_WITHOUT_OPTIONS
        );


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10551 posts

Posted 19 March 2018 - 08:16 PM #5

Not sure I'd use selects for your conditions (pretty expensive requiring full table scans for each).  Suggest an INNER JOIN on the ?:images_links table with the conditions part of the JOIN to only have producta returned where ?:images_links.image_id AND ?:images_links.detailed_id are not both zero.  I.e. something similar to:

$join = "INNER JOIN ?:images_links AS il ON il.object_id = ?:products.product_id AND il.object_type = 'product' AND (il.image_id != 0 OR il.detailed_id != 0)";

 

Just an example, not tested or validated in any particular use case.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.