Skip to content

Instantly share code, notes, and snippets.

@caseydentinger
Created February 20, 2013 18:44
Show Gist options
  • Save caseydentinger/4997972 to your computer and use it in GitHub Desktop.
Save caseydentinger/4997972 to your computer and use it in GitHub Desktop.
public function qoaKeyName ()
{
return 'quantity_on_orders_' . $this->id();
}
/**
* Quantity of this part's storefront product available for sale to the general public.
*/
public function quantityForSale ()
{
if (MEMCACHED_ENABLED === true) {
$cache = SparkCache::getInstance();
if (! $quantity = $cache->get($this->qoaKayName())) {
$quantity = $this->StorefrontProduct->products_physical_quantity
- $this->quantityOnOrders()
- $this->reservedQuantity();
$cache->set($this->qoaKeyName(), $quantity);
}
}
else {
$quantity = $this->StorefrontProduct->products_physical_quantity
- $this->quantityOnOrders()
- $this->reservedQuantity();
}
return $quantity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment