function getCMSFields() { $product = $this->Product(); $fields = new FieldSet(new TabSet('Root', new Tab('Main', new NumericField('Price'), new CheckboxField('AllowPurchase', _t("ProductVariation.ALLOWPURCHASE", 'Allow Purchase ?')), new TextField('InternalItemID', _t("ProductVariation.INTERNALITEMID", 'Internal Item ID')), new TextField('Description', _t("ProductVariation.DESCRIPTION", "Description (optional)")), new ImageField('Image')))); $types = $product->VariationAttributes(); if ($this->ID) { $purchased = $this->getPurchasedTotal(); $values = $this->AttributeValues(); foreach ($types as $type) { $field = $type->getDropDownField(); if ($field) { $value = $values->find('TypeID', $type->ID); if ($value) { $field->setValue($value->ID); if ($purchased) { $field = $field->performReadonlyTransformation(); $field->setName("Type{$type->ID}"); } } else { if ($purchased) { $field = new ReadonlyField("Type{$type->ID}", $type->Name, _t("ProductVariation.ALREADYPURCHASED", 'NOT SET (you can not select a value now because it has already been purchased).')); } else { $field->setEmptyString(''); } } } else { $field = new ReadonlyField("Type{$type->ID}", $type->Name, _t("ProductVariation.NOVALUESTOSELECT", 'No values to select')); } $fields->addFieldToTab('Root.Attributes', $field); } $fields->addFieldToTab('Root.Orders', new ComplexTableField($this, 'OrderItems', 'ProductVariation_OrderItem', array('Order.ID' => '#', 'Order.Created' => 'When', 'Order.Member.Name' => 'Member', 'Quantity' => 'Quantity', 'Total' => 'Total'), new FieldSet(), "\"BuyableID\" = '{$this->ID}'", "\"Created\" DESC")); } else { foreach ($types as $type) { $field = $type->getDropDownField(); $fields->addFieldToTab('Root.Attributes', $field); } } $this->extend('updateCMSFields', $fields); return $fields; }
/** * Standard SS method * @return FieldSet */ function getCMSFields() { //backup in case there are no products. if (Product::get()->count() == 0) { return parent::getCMSFields(); } $product = $this->Product(); $productField = new DropdownField('ProductID', _t("ProductVariation.PRODUCT", 'Product'), Product::get()->map('ID', 'Title')->toArray()); $productField->setEmptyString('(Select one)'); $fields = new FieldList(new TabSet('Root', new Tab('Main', $productField, $fullNameLinkField = ReadOnlyField::create('FullNameLink', _t("ProductVariation.FULLNAME", 'Full Name'), "<a href=\"" . $this->Link() . "\">" . $this->FullName . "</a>"), new NumericField('Price', _t("ProductVariation.PRICE", 'Price')), new CheckboxField('AllowPurchase', _t("ProductVariation.ALLOWPURCHASE", 'Allow Purchase ?'))), new Tab('Details', new TextField('InternalItemID', _t("ProductVariation.INTERNALITEMID", 'Internal Item ID')), new TextField('Description', _t("ProductVariation.DESCRIPTION", "Description (optional)"))), new Tab('Image', new Product_ProductImageUploadField('Image')))); $fullNameLinkField->dontEscape = true; if ($this->EcomConfig()->ProductsHaveWeight) { $fields->addFieldToTab('Root.Details', new NumericField('Weight', _t('ProductVariation.WEIGHT', 'Weight'))); } if ($this->EcomConfig()->ProductsHaveModelNames) { $fields->addFieldToTab('Root.Details', new TextField('Model', _t('ProductVariation.MODEL', 'Model'))); } if ($this->EcomConfig()->ProductsHaveQuantifiers) { $fields->addFieldToTab('Root.Details', new TextField('Quantifier', _t('ProductVariation.QUANTIFIER', 'Quantifier (e.g. per kilo, per month, per dozen, each)'))); } $fields->addFieldToTab('Root.Details', new ReadOnlyField('FullSiteTreeSort', _t('Product.FULLSITETREESORT', 'Full sort index'))); if ($product) { $types = $product->VariationAttributes(); if ($this->ID) { $hasBeenSold = $this->HasBeenSold(); $values = $this->AttributeValues(); foreach ($types as $type) { $field = $type->getDropDownField(); if ($field) { $value = $values->find('TypeID', $type->ID); if ($value) { $field->setValue($value->ID); if ($hasBeenSold) { $field = $field->performReadonlyTransformation(); $field->setName("Type{$type->ID}"); } } else { if ($hasBeenSold) { $field = new ReadonlyField("Type{$type->ID}", $type->Name, _t("ProductVariation.ALREADYPURCHASED", 'NOT SET (you can not select a value now because it has already been purchased).')); } else { $field->setEmptyString(''); } } } else { $field = new ReadonlyField("Type{$type->ID}", $type->Name, _t("ProductVariation.NOVALUESTOSELECT", 'No values to select')); } $fields->addFieldToTab('Root.Attributes', $field); } } else { foreach ($types as $type) { $field = $type->getDropDownField(); $fields->addFieldToTab('Root.Attributes', $field); } } } $fields->addFieldToTab('Root.Main', new LiteralField('AddToCartLink', "<p class=\"message good\"><a href=\"" . $this->AddLink() . "\">" . _t("Product.ADD_TO_CART", "add to cart") . "</a></p>")); $this->extend('updateCMSFields', $fields); return $fields; }