Skip to content

Instantly share code, notes, and snippets.

@cgi-caesar
Created October 30, 2017 12:24
Show Gist options
  • Save cgi-caesar/898c8f9da251c387ae4134ad7d20874e to your computer and use it in GitHub Desktop.
Save cgi-caesar/898c8f9da251c387ae4134ad7d20874e to your computer and use it in GitHub Desktop.
Exclude certain products from shopping cart directory
<?php
Am_Di::getInstance()->productTable->customFields()->add(new Am_CustomFieldCheckbox('cart_exclude', 'Exclude from Shopping Cart'));
Am_Di::getInstance()->hook->add('cartGetProductsQuery', function(Am_Event $e) {
/* @var $q Am_Query */
$q = $e->getQuery();
$q->leftJoin('?_data', 'd', "d.`table` = 'product' AND d.`key` = 'cart_exclude' AND d.`id` = p.product_id");
$q->addWhere('d.`value` IS NULL OR d.`value`<>1');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment