public function onBeforeDelete() { parent::onBeforeDelete(); //make sure that if we delete this option group, we reassign the group's option items to the 'None' group. $items = OptionItem::get()->filter(array('ProductOptionGroupID' => $this->ID)); if (isset($items)) { $noneGroup = OptionGroup::get()->filter(array('Title' => 'Options'))->first(); foreach ($items as $item) { $item->ProductOptionGroupID = $noneGroup->ID; $item->write(); } } }
public function updateCMSFields(FieldList $fields) { // set TabSet names to avoid spaces from camel case $fields->addFieldToTab('Root', new TabSet('FoxyStripe', 'FoxyStripe')); // settings tab $fields->addFieldsToTab('Root.FoxyStripe.Settings', array(HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3), LiteralField::create('DetailsIntro', _t('FoxyStripeSiteConfig.DetailsIntro', '<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank">FoxyCart store settings</a>.')), TextField::create('StoreName')->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Sub Domain'))->setDescription(_t('FoxyStripeSiteConfig.StoreNameDescription', 'the sub domain for your FoxyCart store')), HeaderField::create('AdvanceHeader', _t('FoxyStripeSiteConfig.AdvancedHeader', 'Advanced Settings'), 3), LiteralField::create('AdvancedIntro', _t('FoxyStripeSiteConfig.AdvancedIntro', '<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">FoxyCart advanced store settings</a>.</p>')), ReadonlyField::create('DataFeedLink', _t('FoxyStripeSiteConfig.DataFeedLink', 'FoxyCart DataFeed URL'), self::getDataFeedLink())->setDescription(_t('FoxyStripeSiteConfig.DataFeedLinkDescription', 'copy/paste to FoxyCart')), CheckboxField::create('CartValidation')->setTitle(_t('FoxyStripeSiteConfig.CartValidation', 'Enable Cart Validation'))->setDescription(_t('FoxyStripeSiteConfig.CartValidationDescription', 'You must <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures#use_cart_validation" target="_blank">enable cart validation</a> in the FoxyCart admin.')), ReadonlyField::create('StoreKey')->setTitle(_t('FoxyStripeSiteConfig.StoreKey', 'FoxyCart API Key'))->setDescription(_t('FoxyStripeSiteConfig.StoreKeyDescription', 'copy/paste to FoxyCart')), ReadonlyField::create('SSOLink', _t('FoxyStripeSiteConfig.SSOLink', 'Single Sign On URL'), self::getSSOLink())->setDescription(_t('FoxyStripeSiteConfig.SSOLinkDescription', 'copy/paste to FoxyCart')))); // configuration warning if (FoxyCart::store_name_warning() !== null) { $fields->insertBefore(LiteralField::create("StoreSubDomainHeaderWarning", _t('FoxyStripeSiteConfig.StoreSubDomainHeadingWarning', "<p class=\"message error\">Store sub-domain must be entered in the <a href=\"/admin/settings/\">site settings</a></p>")), 'StoreDetails'); } // products tab $fields->addFieldsToTab('Root.FoxyStripe.Products', array(HeaderField::create('ProductHeader', _t('FoxyStripeSiteConfig.ProductHeader', 'Products'), 3), CheckboxField::create('MultiGroup')->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups'))->setDescription(_t('FoxyStripeSiteConfig.MultiGroupDescription', 'Allows products to be shown in multiple Product Groups')), HeaderField::create('ProductGroupHD', _t('FoxyStripeSiteConfig.ProductGroupHD', 'Product Groups'), 3), NumericField::create('ProductLimit')->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page'))->setDescription(_t('FoxyStripeSiteConfig.ProductLimitDescription', 'Number of Products to show per page on a Product Group')), HeaderField::create('ProductQuantityHD', _t('FoxyStripeSiteConfig.ProductQuantityHD', 'Product Form Max Quantity'), 3), NumericField::create('MaxQuantity')->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity'))->setDescription(_t('FoxyStripeSiteConfig.MaxQuantityDescription', 'Sets max quantity for product form dropdown (add to cart form - default 10)')))); // categories tab $fields->addFieldsToTab('Root.FoxyStripe.Categories', array(HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3), LiteralField::create('CategoryDescrip', _t('FoxyStripeSiteConfig.CategoryDescrip', '<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be accomplished by product options alone, including category specific coupon codes, shipping and handling fees, and email receipts. <a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank">Learn More</a></p><p>Categories you\'ve created in FoxyStripe must also be created in your <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" target="_blank">FoxyCart Categories</a> admin panel.</p>')), GridField::create('ProductCategory', _t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'), ProductCategory::get(), GridFieldConfig_RecordEditor::create()))); // option groups tab $fields->addFieldsToTab('Root.FoxyStripe.Groups', array(HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3), LiteralField::create('OptionGroupsDescrip', _t('FoxyStripeSiteConfig.OptionGroupsDescrip', '<p>Product Option Groups allow you to name a set of product options.</p>')), GridField::create('OptionGroup', _t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'), OptionGroup::get(), GridFieldConfig_RecordEditor::create()))); }
public function getCMSFields() { $fields = FieldList::create(new Tabset('Root', new Tab('Main'), new Tab('Modifiers'))); // set variables from Product $productID = $this->ProductID != 0 ? $this->ProductID : Session::get('CMSMain.currentPage'); $product = ProductPage::get()->byID($productID); $parentPrice = $product->obj('Price')->Nice(); $parentWeight = $product->Weight; $parentCode = $product->Code; // ProductOptionGroup Dropdown field w/ add new $groups = function () { return OptionGroup::get()->map()->toArray(); }; $groupFields = singleton('OptionGroup')->getCMSFields(); $groupField = DropdownField::create('ProductOptionGroupID', _t("OptionItem.Group", "Group"), $groups())->setEmptyString('')->setDescription(_t('OptionItem.GroupDescription', 'Name of this group of options. Managed in <a href="admin/settings">Settings > FoxyStripe > Option Groups</a>')); if (class_exists('QuickAddNewExtension')) { $groupField->useAddNew('OptionGroup', $groups, $groupFields); } $fields->addFieldsToTab('Root.Main', array(HeaderField::create('DetailsHD', _t("OptionItem.DetailsHD", "Product Option Details"), 2), Textfield::create('Title')->setTitle(_t("OptionItem.Title", "Product Option Name")), CheckboxField::create('Available')->setTitle(_t("OptionItem.Available", "Available for purchase"))->setDescription(_t('OptionItem.AvailableDescription', "If unchecked, will disable this option in the drop down menu")), $groupField)); $fields->addFieldsToTab('Root.Modifiers', array(HeaderField::create('ModifyHD', _t('OptionItem.ModifyHD', 'Product Option Modifiers'), 2), HeaderField::create('WeightHD', _t('OptionItem.WeightHD', 'Modify Weight'), 3), NumericField::create('WeightModifier')->setTitle(_t('OptionItem.WeightModifier', 'Weight')), DropdownField::create('WeightModifierAction', _t('OptionItem.WeightModifierAction', 'Weight Modification'), array('Add' => _t('OptionItem.WeightAdd', "Add to Base Weight ({weight})", 'Add to weight', array('weight' => $parentWeight)), 'Subtract' => _t('OptionItem.WeightSubtract', "Subtract from Base Weight ({weight})", 'Subtract from weight', array('weight' => $parentWeight)), 'Set' => _t('OptionItem.WeightSet', 'Set as a new Weight')))->setEmptyString('')->setDescription(_t('OptionItem.WeightDescription', 'Does weight modify or replace base weight?')), HeaderField::create('PriceHD', _t('OptionItem.PriceHD', 'Modify Price'), 3), CurrencyField::create('PriceModifier')->setTitle(_t('OptionItem.PriceModifier', 'Price')), DropdownField::create('PriceModifierAction', _t('OptionItem.PriceModifierAction', 'Price Modification'), array('Add' => _t('OptionItem.PriceAdd', "Add to Base Price ({price})", 'Add to price', array('price' => $parentPrice)), 'Subtract' => _t('OptionItem.PriceSubtract', "Subtract from Base Price ({price})", 'Subtract from price', array('price' => $parentPrice)), 'Set' => _t('OptionItem.PriceSet', 'Set as a new Price')))->setEmptyString('')->setDescription(_t('OptionItem.PriceDescription', 'Does price modify or replace base price?')), HeaderField::create('CodeHD', _t('OptionItem.CodeHD', 'Modify Code'), 3), TextField::create('CodeModifier')->setTitle(_t('OptionItem.CodeModifier', 'Code')), DropdownField::create('CodeModifierAction', _t('OptionItem.CodeModifierAction', 'Code Modification'), array('Add' => _t('OptionItem.CodeAdd', "Add to Base Code ({code})", 'Add to code', array('code' => $parentCode)), 'Subtract' => _t('OptionItem.CodeSubtract', 'Subtract from Base Code ({code})', 'Subtract from code', array('code' => $parentCode)), 'Set' => _t('OptionItem.CodeSet', 'Set as a new Code')))->setEmptyString('')->setDescription(_t('OptionItem.CodeDescription', 'Does code modify or replace base code?')))); /* // Cateogry Dropdown field w/ add new // removed until relevance determined $categories = function(){ return ProductCategory::get()->map()->toArray(); }; // to do - have OptionItem category override set ProductPage category if selected: issue #155 $categoryField = DropdownField::create('CategoryID', 'Category', $categories()) ->setEmptyString('') ->setDescription('Categories can be managed in <a href="admin/settings">Settings > FoxyStripe > Categories</a>'); if (class_exists('QuickAddNewExtension')) $categoryField->useAddNew('ProductCategory', $categories); $fields->insertAfter($categoryField, 'ProductOptionGroupID'); */ // allow CMS fields to be extended $this->extend('getCMSFields', $fields); return $fields; }
function testOptionItemDeletion() { $this->logInWithPermission('ADMIN'); $optionGroup = OptionGroup::get()->first() ? OptionGroup::get()->first() : OptionGroup::create(); if ($optionGroup->ID == 0) { $optionGroup->Title = 'Size'; $optionGroup->write(); } $option = $this->objFromFixture('OptionItem', 'small'); $option->ProductOptionGroupID = $optionGroup->ID; $option->write(); $optionID = $option->ID; $this->assertTrue($option->canDelete()); $this->logOut(); $this->logInWithPermission('Product_CANCRUD'); $this->assertTrue($option->canDelete()); $option->delete(); $this->assertFalse(in_array($optionID, OptionItem::get()->column('ID'))); }
/** * @return CompositeField */ protected function getProductOptionSet() { $assignAvailable = function ($self) { $this->extend('updateFoxyStripePurchaseForm', $form); $self->Available = $self->getAvailability() ? true : false; }; $options = $this->product->ProductOptions(); $groupedOptions = new GroupedList($options); $groupedBy = $groupedOptions->groupBy('ProductOptionGroupID'); $optionsSet = CompositeField::create(); foreach ($groupedBy as $id => $set) { $group = OptionGroup::get()->byID($id); $title = $group->Title; $name = preg_replace('/\\s/', '_', $title); $set->each($assignAvailable); $disabled = array(); $fullOptions = array(); foreach ($set as $item) { $fullOptions[ProductPage::getGeneratedValue($this->product->Code, $group->Title, $item->getGeneratedValue(), 'value')] = $item->getGeneratedTitle(); if (!$item->Availability) { array_push($disabled, ProductPage::getGeneratedValue($this->product->Code, $group->Title, $item->getGeneratedValue(), 'value')); } } $optionsSet->push($dropdown = DropdownField::create($name, $title, $fullOptions)->setTitle($title)); $dropdown->setDisabledItems($disabled); } $optionsSet->addExtraClass('foxycartOptionsContainer'); return $optionsSet; }
public function PurchaseForm() { $config = SiteConfig::current_site_config(); $assignAvailable = function ($self) { $self->Available = $self->getAvailability() ? true : false; }; $fields = FieldList::create(); $data = $this->data(); $hiddenTitle = $data->ReceiptTitle ? htmlspecialchars($data->ReceiptTitle) : htmlspecialchars($data->Title); $code = $data->Code; if ($data->Available) { $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'name', $hiddenTitle))->setValue($hiddenTitle)); $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'category', $data->Category()->Code))->setValue($data->Category()->Code)); $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'code', $data->Code))->setValue($data->Code)); $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'product_id', $data->ID))->setValue($data->ID)); $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'price', $data->Price))->setValue($data->Price)); //can't override id $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'weight', $data->Weight))->setValue($data->Weight)); if ($this->DiscountTitle && $this->ProductDiscountTiers()->exists()) { $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'discount_quantity_percentage', $data->getDiscountFieldValue()))->setValue($data->getDiscountFieldValue())); } if ($this->PreviewImage()->Exists()) { $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'image', $data->PreviewImage()->PaddedImage(80, 80)->absoluteURL))->setValue($data->PreviewImage()->PaddedImage(80, 80)->absoluteURL)); } $options = $data->ProductOptions(); $groupedOptions = new GroupedList($options); $groupedBy = $groupedOptions->groupBy('ProductOptionGroupID'); $optionsSet = CompositeField::create(); foreach ($groupedBy as $id => $set) { $group = OptionGroup::get()->byID($id); $title = $group->Title; $name = preg_replace('/\\s/', '_', $title); $set->each($assignAvailable); $disabled = array(); $fullOptions = array(); foreach ($set as $item) { $fullOptions[ProductPage::getGeneratedValue($data->Code, $group->Title, $item->getGeneratedValue(), 'value')] = $item->getGeneratedTitle(); if (!$item->Availability) { array_push($disabled, ProductPage::getGeneratedValue($data->Code, $group->Title, $item->getGeneratedValue(), 'value')); } } $optionsSet->push($dropdown = DropdownField::create($name, $title, $fullOptions)->setTitle($title)); $dropdown->setDisabledItems($disabled); } $optionsSet->addExtraClass('foxycartOptionsContainer'); $fields->push($optionsSet); $quantityMax = $config->MaxQuantity ? $config->MaxQuantity : 10; $count = 1; $quantity = array(); while ($count <= $quantityMax) { $countVal = ProductPage::getGeneratedValue($data->Code, 'quantity', $count, 'value'); $quantity[$countVal] = $count; $count++; } $fields->push(DropdownField::create('quantity', 'Quantity', $quantity)); $fields->push(HeaderField::create('submitPrice', '$' . $data->Price, 4)); $actions = FieldList::create($submit = FormAction::create('', _t('ProductForm.AddToCart', 'Add to Cart'))); $submit->setAttribute('name', ProductPage::getGeneratedValue($code, 'Submit', _t('ProductForm.AddToCart', 'Add to Cart'))); if (!$config->StoreName || $config->StoreName == '' || !isset($config->StoreName)) { $submit->setAttribute('Disabled', true); } $this->extend('updatePurchaseFormFields', $fields); } else { $fields->push(HeaderField::create('submitPrice', 'Currently Out of Stock'), 4); $actions = FieldList::create(); } $form = Form::create($this, 'PurchaseForm', $fields, $actions); $form->setAttribute('action', FoxyCart::FormActionURL()); $form->disableSecurityToken(); $this->extend('updatePurchaseForm', $form); return $form; }