public function setup() { parent::setUp(); PriceCache::inst()->disable(); ShoppingCart::singleton()->clear(); $this->p1 = $this->objFromFixture('Product', 'p1'); $this->p1->publish('Stage', 'Live'); $this->p2 = $this->objFromFixture('Product', 'p2'); $this->p2->publish('Stage', 'Live'); $this->p4 = $this->objFromFixture('Product', 'p4'); $this->p4->publish('Stage', 'Live'); $this->v1 = $this->objFromFixture('ProductVariation', 'p4v1'); }
function setUp() { parent::setUp(); PriceCache::inst()->disable(); }
/** * Collects any other sources of applicable discounts, leaving * room for extension from other sources. * * NOTE: This method can be called from HasPromotion or sellingPrice * so we use the price cache. IF the price cache ever became persistent * we would want to stop using it in that way because it would probably * be slower to serialize all those objects than would be worth it. * * @param $obj [optional] * @return array */ protected function collectParentPromoSources($obj = null) { if (!$obj) { $obj = $this->getOwner(); } // try the cache $sources = PriceCache::inst()->get($obj, 'PromoSources'); if ($sources !== false) { return $sources; } // if not found look everything up if ($obj->hasMethod('getParentPromoSources')) { return PriceCache::inst()->set($obj, 'PromoSources', $obj->getParentPromoSources()); } else { $sources = array(); if ($obj instanceof ProductVariation) { $p = $obj->Product(); if ($p && $p->exists() && $p->hasExtension('HasPromotionalPricing')) { $sources[] = $p; } $sources = array_merge($sources, $this->collectParentPromoSources($p)); } if ($obj instanceof Product) { $cats = $obj->ProductCategories()->toArray(); if ($obj->ParentID) { $cats[] = $obj->Parent(); } foreach ($cats as $cat) { if ($cat && $cat->exists() && $cat->hasExtension('HasPromotionalPricing')) { $sources[] = $cat; } $sources = array_merge($sources, $this->collectParentPromoSources($cat)); } } if ($obj instanceof ProductCategory) { if ($obj->ParentID) { $p = $obj->Parent(); if ($p && $p->exists() && $p->hasExtension('HasPromotionalPricing')) { $sources[] = $p; } $sources = array_merge($sources, $this->collectParentPromoSources($p)); } } return PriceCache::inst()->set($obj, 'PromoSources', $sources); } }
/** * @param $price */ public function updateSellingPrice(&$price) { if (!PriceCache::inst()->fetch($this->owner, 'Group', $price)) { $levels = self::get_levels(); $member = Member::currentUser(); if (count($levels) > 0 && $member) { // if there is a logged in member and multiple levels, check them uot $groups = $member->Groups()->column('Code'); foreach ($groups as $code) { // if the group we're looking at has it's own price field, // and the price is lower than the current price, update it if (isset($levels[$code])) { $field = $levels[$code]; $altPrice = $this->getOwner()->getField($field); if ($altPrice > 0 && $altPrice < $price) { $price = $altPrice; } } } } PriceCache::inst()->set($this->owner, 'Group', $price); } }