Source of file GiftVoucherProduct.php
Size: 1,866 Bytes - Last Modified: 2021-12-24T06:35:13+00:00
/var/www/docs.ssmods.com/process/src/src/Page/GiftVoucherProduct.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | <?php namespace SilverShop\Discounts\Page; use SilverShop\Discounts\Model\GiftVoucherOrderItem; use SilverShop\Page\Product; use SilverStripe\Forms\OptionsetField; use SilverStripe\Forms\TextField; /** * Gift voucher products, when purchased will send out a voucher code to the * customer via email. */ class GiftVoucherProduct extends Product { private static $db = [ 'VariableAmount' => 'Boolean', 'MinimumAmount' => 'Currency' ]; private static $singular_name = 'Gift Voucher'; private static $plural_name = 'Gift Vouchers'; private static $order_item = GiftVoucherOrderItem::class; private static $table_name = 'SilverShop_GiftVoucherProduct'; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab( 'Root.Pricing', new OptionsetField( 'VariableAmount', 'Price', [ 0 => 'Fixed', 1 => 'Allow customer to choose' ] ), 'BasePrice' ); $fields->addFieldsToTab( 'Root.Pricing', [ //text field, because of CMS js validation issue $minimumamount = new TextField('MinimumAmount', 'Minimum Amount') ] ); $fields->removeByName('CostPrice'); $fields->removeByName('Variations'); $fields->removeByName('Model'); return $fields; } public function canPurchase($member = null, $quantity = 1) { if (!self::config()->get('global_allow_purchase')) { return false; } if (!$this->dbObject('AllowPurchase')->getValue()) { return false; } if (!$this->isPublished()) { return false; } return true; } } |