public function feature_product() { check_admin_referer('wp_ajax_shopp_feature_product'); if (empty($_GET['feature'])) { die('0'); } $Product = new ProductSummary((int) $_GET['feature']); if (empty($Product->product)) { die('0'); } $Product->featured = 'on' == $Product->featured ? 'off' : 'on'; $Product->save(); echo $Product->featured; exit; }
/** * Updates the featured setting of a set of products * * @author Jonathan Davis * @since 1.2 * * @param array $ids Set of product IDs to update * @param string $setting Either 'on' or 'off' * @return boolean **/ static function featureset($ids, $setting) { if (empty($ids) || !is_array($ids)) { return false; } $settings = array('on', 'off'); if (!in_array($setting, $settings)) { return false; } foreach ($ids as $id) { $Product = new ProductSummary((int) $id); $Product->featured = $setting; $Product->save(); } return true; }
/** * shopp_product_variant_set_stock - adjust stock or set stock level on a variant. The stock level effects low stock warning thresholds. * * @api * @since 1.2 * * @param int/Price $variant (required) The priceline id to set stock/stock level on, or the Price object to change. If Price object is specified, the object will be returned, but not saved to the database. * @param int $stock (optional default=0) The stock number to adjust/set the level to. * @param string $action (optional default=adjust) 'adjust' to set the variant stock without setting the stock level, 'restock' to set both the variant stock and stock level * @param string $context (optional default:variant) enforces the priceline is a 'product','variant', or 'addon' * @return bool/Price false on failure, true if Price saved, else the modified Price object. **/ function shopp_product_variant_set_stock($variant = false, $stock = 0, $action = 'adjust', $context = 'variant') { $context = 'variant' == $context ? 'variation' : $context; $save = true; if (is_object($variant) && is_a($variant, 'ShoppPrice')) { $Price = $variant; $save = false; } else { if (false == $variant) { shopp_debug(__FUNCTION__ . " failed: Variant id required."); return false; } $Price = new ShoppPrice($variant); if (empty($Price->id) || $Price->context != $context) { shopp_debug(__FUNCTION__ . " failed: No such {$context} with id {$variant}."); } } $hadstock = $Price->stock; $stocklevel = $Price->stocked; $Price->stock = $stock; if ('restock' == $action) { $Price->modified = 0; $Price->stocked = $stock; } if ($save) { ProductSummary::rebuild($Price->product); do_action('shopp_stock_product', $stock, $Price, $hadstock, $stocklevel); return $Price->save(); } return $Price; }