Source of file EcommerceCorporateGroupBuyableDecorator.php
Size: 2,662 Bytes - Last Modified: 2021-12-23T10:40:37+00:00
/var/www/docs.ssmods.com/process/src/code/dods/EcommerceCorporateGroupBuyableDecorator.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | <?php /** * adds functionality for buyables * * @author nicolaas */ class EcommerceCorporateGroupBuyableDecorator extends DataObjectDecorator { /** * If set to true, only approved customers can make purchases * @var Boolean $only_approved_customers_can_purchase */ protected static $only_approved_customers_can_purchase = true; public static function set_only_approved_customers_can_purchase($b) { self::$only_approved_customers_can_purchase = $b; } public static function get_only_approved_customers_can_purchase() { return self::$only_approved_customers_can_purchase; } /** * Is the current customer an approved member? * @return Boolean */ public function isApprovedCorporateCustomer() { if (!EcommerceCorporateGroupBuyableDecorator::get_only_approved_customers_can_purchase()) { return true; } $member = Member::currentUser(); if (!$member) { $member = new Member(); } return $member->isApprovedCorporateCustomer(); } /** * non-approved customers should not be able to see the price * Note that because it is an extension is actually returns an array!! * @param Currency | double * @return Double | NULL | Currency (object) */ public function updateCalculatedPrice($price) { if ($this->owner->isApprovedCorporateCustomer()) { return null; } if (is_object($price)) { $price->setValue(0); return $price; } return 0; } /** * non-approved customers should not be able to see the price * Note that because it is an extension is actually returns an array!! * @param Money | value $moneyObject * @return Double | NULL | Money (object) */ public function updateDisplayPrice($moneyObject) { if ($this->owner->isApprovedCorporateCustomer()) { return null; } if (is_object($moneyObject)) { $moneyObject->setValue(0); return $moneyObject; } return 0; } /** * non-approved customers should not be able to see the price * Note that because it is an extension is actually returns an array!! * @param Member $member * @return Boolean | NULL */ public function canPurchase($member = null) { if ($this->owner->isApprovedCorporateCustomer()) { //return null so that the original canPurchase is not affected. //MUST return null here return null; } return false; } } |