| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Dynamic\FoxyStripe\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Dynamic\FoxyStripe\Page\ProductPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\Control\Session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Forms\CheckboxField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Forms\CurrencyField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\Forms\DropdownField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SilverStripe\Forms\FieldList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SilverStripe\Forms\HeaderField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use SilverStripe\Forms\NumericField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use SilverStripe\Forms\TextField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use SilverStripe\ORM\DataObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use SilverStripe\ORM\ValidationResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use SilverStripe\Security\Permission; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * Class OptionItem. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class OptionItem extends DataObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private static $db = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         'Title' => 'Text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         'WeightModifier' => 'Int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         'CodeModifier' => 'Text', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         'PriceModifier' => 'Currency', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         'WeightModifierAction' => "Enum('Add,Subtract,Set','Add')", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         'CodeModifierAction' => "Enum('Add,Subtract,Set','Add')", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         'PriceModifierAction' => "Enum('Add,Subtract,Set','Add')", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         'Available' => 'Boolean', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         'SortOrder' => 'Int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     private static $has_one = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         'Product' => ProductPage::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         'ProductOptionGroup' => OptionGroup::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     private static $belongs_many_many = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         'OrderDetails' => OrderDetail::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     private static $defaults = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         'Available' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     private static $summary_fields = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         'Title' => 'Title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         'ProductOptionGroup.Title' => 'Group', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         'IsAvailable' => 'Available', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     private static $searchable_fields = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         'Title' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             'title' => 'Title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         'ProductOptionGroup.Title' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             'title' => 'Group', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     private static $default_sort = 'SortOrder'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     private static $table_name = 'FS_OptionItem'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return FieldList | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     public function getCMSFields() | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |         $fields = parent::getCMSFields(); | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         $fields->removeByName([ | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |             'OrderDetails', | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |             'SortOrder', | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |             'ProductID', | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |         // set variables from Product | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |         $productID = ($this->ProductID != 0) ? $this->ProductID : Session::get('CMSMain.currentPage'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |         $product = ProductPage::get()->byID($productID); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |         $parentPrice = $product->obj('Price')->Nice(); | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |         $parentWeight = $product->Weight; | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |         $parentCode = $product->Code; | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |         // ProductOptionGroup Dropdown field w/ add new | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         $groups = function () { | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |             return OptionGroup::get()->map()->toArray(); | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |         }; | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |         $groupFields = singleton(OptionGroup::class)->getCMSFields(); | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |         $groupField = DropdownField::create('ProductOptionGroupID', _t( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |             'OptionItem.Group', | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |             'Group' | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |         ), $groups()) | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |             ->setEmptyString('') | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |             ->setDescription(_t( | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |                 'OptionItem.GroupDescription', | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |                 'Name of this group of options. Managed in <a href="admin/settings"> | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |                         Settings > FoxyStripe > Option Groups | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |                         </a>' | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |             )); | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |         if (class_exists('QuickAddNewExtension')) { | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |             $groupField->useAddNew('OptionGroup', $groups, $groupFields); | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         $fields->addFieldsToTab('Root.Main', array( | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |             TextField::create('Title') | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |                 ->setTitle(_t('OptionItem.Title', 'Product Option Name')), | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |             CheckboxField::create('Available') | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |                 ->setTitle(_t('OptionItem.Available', 'Available for purchase')) | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |                 ->setDescription(_t( | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |                     'OptionItem.AvailableDescription', | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |                     'If unchecked, will disable this option in the drop down menu' | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |                 )), | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |             $groupField, | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |         )); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |         $fields->addFieldsToTab('Root.Modifiers', array( | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |             HeaderField::create('ModifyHD', _t( | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |                 'OptionItem.ModifyHD', | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |                 'Product Option Modifiers' | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |             ), 2), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             // Weight Modifier Fields | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |             HeaderField::create('WeightHD', _t('OptionItem.WeightHD', 'Modify Weight'), 3), | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |             NumericField::create('WeightModifier') | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |                 ->setTitle(_t('OptionItem.WeightModifier', 'Weight')), | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |             DropdownField::create( | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |                 'WeightModifierAction', | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |                 _t('OptionItem.WeightModifierAction', 'Weight Modification'), | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |                 array( | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |                     'Add' => _t( | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |                         'OptionItem.WeightAdd', | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |                         'Add to Base Weight ({weight})', | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |                         'Add to weight', | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |                         array('weight' => $parentWeight) | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |                     ), | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |                     'Subtract' => _t( | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |                         'OptionItem.WeightSubtract', | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |                         'Subtract from Base Weight ({weight})', | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |                         'Subtract from weight', | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |                         array('weight' => $parentWeight) | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |                     ), | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |                     'Set' => _t('OptionItem.WeightSet', 'Set as a new Weight'), | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |                 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |             )->setEmptyString('') | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |             ->setDescription(_t( | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |                 'OptionItem.WeightDescription', | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |                 'Does weight modify or replace base weight?' | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  |             )), | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |             // Price Modifier FIelds | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  |             HeaderField::create('PriceHD', _t('OptionItem.PriceHD', 'Modify Price'), 3), | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  |             CurrencyField::create('PriceModifier') | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  |                 ->setTitle(_t('OptionItem.PriceModifier', 'Price')), | 
            
                                                                        
                            
            
                                    
            
            
                | 182 |  |  |             DropdownField::create( | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  |                 'PriceModifierAction', | 
            
                                                                        
                            
            
                                    
            
            
                | 184 |  |  |                 _t('OptionItem.PriceModifierAction', 'Price Modification'), | 
            
                                                                        
                            
            
                                    
            
            
                | 185 |  |  |                 array( | 
            
                                                                        
                            
            
                                    
            
            
                | 186 |  |  |                     'Add' => _t( | 
            
                                                                        
                            
            
                                    
            
            
                | 187 |  |  |                         'OptionItem.PriceAdd', | 
            
                                                                        
                            
            
                                    
            
            
                | 188 |  |  |                         'Add to Base Price ({price})', | 
            
                                                                        
                            
            
                                    
            
            
                | 189 |  |  |                         'Add to price', | 
            
                                                                        
                            
            
                                    
            
            
                | 190 |  |  |                         array('price' => $parentPrice) | 
            
                                                                        
                            
            
                                    
            
            
                | 191 |  |  |                     ), | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  |                     'Subtract' => _t( | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  |                         'OptionItem.PriceSubtract', | 
            
                                                                        
                            
            
                                    
            
            
                | 194 |  |  |                         'Subtract from Base Price ({price})', | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  |                         'Subtract from price', | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  |                         array('price' => $parentPrice) | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |                     ), | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |                     'Set' => _t('OptionItem.PriceSet', 'Set as a new Price'), | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  |                 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |             )->setEmptyString('') | 
            
                                                                        
                            
            
                                    
            
            
                | 201 |  |  |             ->setDescription(_t('OptionItem.PriceDescription', 'Does price modify or replace base price?')), | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 203 |  |  |             // Code Modifier Fields | 
            
                                                                        
                            
            
                                    
            
            
                | 204 |  |  |             HeaderField::create('CodeHD', _t('OptionItem.CodeHD', 'Modify Code'), 3), | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  |             TextField::create('CodeModifier') | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  |                 ->setTitle(_t('OptionItem.CodeModifier', 'Code')), | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  |             DropdownField::create( | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  |                 'CodeModifierAction', | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  |                 _t('OptionItem.CodeModifierAction', 'Code Modification'), | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  |                 array( | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  |                     'Add' => _t( | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  |                         'OptionItem.CodeAdd', | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  |                         'Add to Base Code ({code})', | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  |                         'Add to code', | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  |                         array('code' => $parentCode) | 
            
                                                                        
                            
            
                                    
            
            
                | 216 |  |  |                     ), | 
            
                                                                        
                            
            
                                    
            
            
                | 217 |  |  |                     'Subtract' => _t( | 
            
                                                                        
                            
            
                                    
            
            
                | 218 |  |  |                         'OptionItem.CodeSubtract', | 
            
                                                                        
                            
            
                                    
            
            
                | 219 |  |  |                         'Subtract from Base Code ({code})', | 
            
                                                                        
                            
            
                                    
            
            
                | 220 |  |  |                         'Subtract from code', | 
            
                                                                        
                            
            
                                    
            
            
                | 221 |  |  |                         array('code' => $parentCode) | 
            
                                                                        
                            
            
                                    
            
            
                | 222 |  |  |                     ), | 
            
                                                                        
                            
            
                                    
            
            
                | 223 |  |  |                     'Set' => _t('OptionItem.CodeSet', 'Set as a new Code'), | 
            
                                                                        
                            
            
                                    
            
            
                | 224 |  |  |                 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 225 |  |  |             )->setEmptyString('') | 
            
                                                                        
                            
            
                                    
            
            
                | 226 |  |  |             ->setDescription(_t('OptionItem.CodeDescription', 'Does code modify or replace base code?')), | 
            
                                                                        
                            
            
                                    
            
            
                | 227 |  |  |         )); | 
            
                                                                        
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 229 |  |  |         /* | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 230 |  |  |         // Cateogry Dropdown field w/ add new | 
            
                                                                        
                            
            
                                    
            
            
                | 231 |  |  |         // removed until relevance determined | 
            
                                                                        
                            
            
                                    
            
            
                | 232 |  |  |         $categories = function(){ | 
            
                                                                        
                            
            
                                    
            
            
                | 233 |  |  |             return ProductCategory::get()->map()->toArray(); | 
            
                                                                        
                            
            
                                    
            
            
                | 234 |  |  |         }; | 
            
                                                                        
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 236 |  |  |         // to do - have OptionItem category override set ProductPage category if selected: issue #155 | 
            
                                                                        
                            
            
                                    
            
            
                | 237 |  |  |         $categoryField = DropdownField::create('CategoryID', 'Category', $categories()) | 
            
                                                                        
                            
            
                                    
            
            
                | 238 |  |  |             ->setEmptyString('') | 
            
                                                                        
                            
            
                                    
            
            
                | 239 |  |  |             ->setDescription('Categories can be managed in <a href="admin/settings"> | 
            
                                                                        
                            
            
                                    
            
            
                | 240 |  |  |                 Settings > FoxyStripe > Categories | 
            
                                                                        
                            
            
                                    
            
            
                | 241 |  |  |         </a>'); | 
            
                                                                        
                            
            
                                    
            
            
                | 242 |  |  |         if (class_exists('QuickAddNewExtension')) $categoryField->useAddNew('ProductCategory', $categories); | 
            
                                                                        
                            
            
                                    
            
            
                | 243 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 244 |  |  |         $fields->insertAfter($categoryField, 'ProductOptionGroupID'); | 
            
                                                                        
                            
            
                                    
            
            
                | 245 |  |  |         */ | 
            
                                                                        
                            
            
                                    
            
            
                | 246 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 247 |  |  |         return $fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |      * @return ValidationResult | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 | 4 |  |     public function validate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 | 4 |  |         $result = parent::validate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 | 4 |  |         if ($this->ProductOptionGroupID == 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |             $result->addError('Must set a Group prior to saving'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 | 4 |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * @param $oma | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      * @param bool $returnWithOnlyPlusMinus | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     public static function getOptionModifierActionSymbol($oma, $returnWithOnlyPlusMinus = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         switch ($oma) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |             case 'Subtract': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |                 $symbol = '-'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |             case 'Set': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |                 $symbol = ($returnWithOnlyPlusMinus) ? '' : ':'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |             default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |                 $symbol = '+'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         return $symbol; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |     public function getWeightModifierWithSymbol() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |         return self::getOptionModifierActionSymbol($this->WeightModifierAction).$this->WeightModifier; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |     public function getPriceModifierWithSymbol() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |         return self::getOptionModifierActionSymbol($this->PriceModifierAction).$this->PriceModifier; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |     public function getCodeModifierWithSymbol() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         return self::getOptionModifierActionSymbol($this->CodeModifierAction).$this->CodeModifier; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |     public function getProductOptionGroupTitle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         return $this->ProductOptionGroup()->Title; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |     public function getGeneratedValue() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         $modPrice = ($this->PriceModifier) ? (string) $this->PriceModifier : '0'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |         $modPriceWithSymbol = self::getOptionModifierActionSymbol($this->PriceModifierAction).$modPrice; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         $modWeight = ($this->WeightModifier) ? (string) $this->WeightModifier : '0'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |         $modWeight = self::getOptionModifierActionSymbol($this->WeightModifierAction).$modWeight; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         $modCode = self::getOptionModifierActionSymbol($this->CodeModifierAction).$this->CodeModifier; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |         return $this->Title.'{p'.$modPriceWithSymbol.'|w'.$modWeight.'|c'.$modCode.'}'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |      * @return mixed|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |     public function getGeneratedTitle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |         $modPrice = ($this->PriceModifier) ? (string) $this->PriceModifier : '0'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |         $title = $this->Title; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |         $title .= ($this->PriceModifier != 0) ? | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |             ': ('.self::getOptionModifierActionSymbol( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |                 $this->PriceModifierAction, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |                 $returnWithOnlyPlusMinus = true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |             ).'$'.$modPrice.')' : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |             ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |         return $title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |     public function getAvailability() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |         $available = ($this->Available == 1) ? true : false; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |         $this->extend('updateOptionAvailability', $available); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |         return $available; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |     public function getIsAvailable() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |         if ($this->getAvailability()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |             return 'yes'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |         return 'no'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |      * @param bool $member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 | 49 |  |     public function canView($member = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 | 49 |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |      * @param null $member | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |      * @return bool|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |     public function canEdit($member = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |         return Permission::check('Product_CANCRUD'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |      * @param null $member | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |      * @return bool|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 | 1 |  |     public function canDelete($member = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 | 1 |  |         return Permission::check('Product_CANCRUD'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |      * @param null $member | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |      * @return bool|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |     public function canCreate($member = null, $context = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |         return Permission::check('Product_CANCRUD'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 412 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 413 |  |  |  |