Source of file GroupExtension.php
Size: 3,876 Bytes - Last Modified: 2021-12-23T10:21:36+00:00
/var/www/docs.ssmods.com/process/src/src/Model/Customer/GroupExtension.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | <?php namespace SilverCart\Model\Customer; use SilverCart\Admin\Forms\GridField\GridFieldConfig_RelationEditor; use SilverCart\Admin\Forms\AlertInfoField; use SilverCart\Model\Customer\Customer; use SilverCart\Model\Payment\PaymentMethod; use SilverCart\Model\Shipment\ShippingMethod; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TextField; use SilverStripe\Forms\GridField\GridField; use SilverStripe\ORM\DataExtension; use SilverStripe\Security\Group; /** * Decorates the Group class for additional functionality. * * @package SilverCart * @subpackage Model_Customer * @author Sebastian Diel <sdiel@pixeltricks.de> * @since 26.09.2017 * @copyright 2017 pixeltricks GmbH * @license see license file in modules root directory * * @property Group $owner Owner */ class GroupExtension extends DataExtension { /** * DB attributes * * @var string[] */ private static $db = [ 'Pricetype' => 'Enum("---,gross,net","---")' ]; /** * Belongs many many relations * * @var string[] */ private static $belongs_many_many = [ 'PaymentMethods' => PaymentMethod::class, 'ShippingMethods' => ShippingMethod::class, ]; /** * Grant API access on this item. * * @var bool */ private static $api_access = true; /** * Adds or removes GUI elements for the backend editing mask. * * @param FieldList $fields The original FieldList * * @return void */ public function updateCMSFields(FieldList $fields) : void { $fields->addFieldToTab('Root.Members', TextField::create('Code', Group::singleton()->fieldLabel('Code'))); if ($this->owner->exists()) { $fields->findOrMakeTab('Root.ShippingMethods', $this->owner->fieldLabel('ShippingMethods')); $fields->addFieldToTab("Root.ShippingMethods", AlertInfoField::create('ShippingMethodsInfo', $this->owner->fieldLabel('ShippingMethodsInfoContent'), $this->owner->fieldLabel('ShippingMethodsInfoTitle'))); $fields->addFieldToTab("Root.ShippingMethods", GridField::create('ShippingMethods', $this->owner->fieldLabel('ShippingMethods'), $this->owner->ShippingMethods(), GridFieldConfig_RelationEditor::create())); } $enumValues = $this->owner->dbObject('Pricetype')->enumValues(); $i18nSource = []; foreach ($enumValues as $value => $label) { $i18nSource[$value] = _t(Customer::class . '.' . strtoupper($label), $label); } $pricetypeField = DropdownField::create('Pricetype', $this->owner->fieldLabel('Pricetype'), $i18nSource, $this->owner->Pricetype); $fields->addFieldToTab("Root.Members", $pricetypeField, 'Members'); } /** * Updates the field labels * * @param array &$labels The original labels * * @return void */ public function updateFieldLabels(&$labels) : void { $labels = array_merge($labels, [ 'Pricetype' => _t(GroupExtension::class . '.PRICETYPE', 'Pricetype'), 'PaymentMethods' => PaymentMethod::singleton()->plural_name(), 'ShippingMethods' => ShippingMethod::singleton()->plural_name(), 'ShippingMethodsInfoContent' => _t(GroupExtension::class . '.ShippingMethodsInfoContent', 'The shipping methods listed below are bound to this customer group and can only be chosen by customers belonging to this group. Shipping methods can be related to multiple customer groups, so this customer group might not be the only group with the permission to use the listed shipping methods.'), 'ShippingMethodsInfoTitle' => _t(GroupExtension::class . '.ShippingMethodsInfoTitle', 'Shipping methods bound to this customer group.'), ]); } } |