/** * @param array $source */ public function setSource($source) { $controller = Controller::curr(); $code = $controller->data()->Code; $updated = []; if (is_array($source) && !empty($source)) { foreach ($source as $key => $val) { $updated[ProductPage::getGeneratedValue($code, $this->getName(), $key, 'value')] = $val; } } $this->source = $updated; return $this; }
public function testProductDiscountTierDeletion() { $this->logInWithPermission('ADMIN'); $discount = ProductPage::get()->first(); $tier = $this->objFromFixture('ProductDiscountTier', 'fiveforten'); $tier->ProductPageID = $discount->ID; $tier->write(); $tierID = $tier->ID; $this->logOut(); $this->logInWithPermission('Product_CANCRUD'); $tier->delete(); $this->assertTrue(!ProductDiscountTier::get()->byID($tierID)); $this->logOut(); }
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; }
public function parseOrderDetails($orders, $transaction) { // remove previous OrderDetails so we don't end up with duplicates foreach ($transaction->Details() as $detail) { $detail->delete(); } foreach ($orders->transactions->transaction as $order) { // Associate ProductPages, Options, Quanity with Order foreach ($order->transaction_details->transaction_detail as $product) { $OrderDetail = OrderDetail::create(); // set Quantity $OrderDetail->Quantity = (int) $product->product_quantity; // set calculated price (after option modifiers) $OrderDetail->Price = (double) $product->product_price; // Find product via product_id custom variable foreach ($product->transaction_detail_options->transaction_detail_option as $productID) { if ($productID->product_option_name == 'product_id') { $OrderProduct = ProductPage::get()->filter('ID', (int) $productID->product_option_value)->First(); // if product could be found, then set Option Items if ($OrderProduct) { // set ProductID $OrderDetail->ProductID = $OrderProduct->ID; // loop through all Product Options foreach ($product->transaction_detail_options->transaction_detail_option as $option) { $OptionItem = OptionItem::get()->filter(array('ProductID' => (string) $OrderProduct->ID, 'Title' => (string) $option->product_option_value))->First(); if ($OptionItem) { $OrderDetail->Options()->add($OptionItem); // modify product price if ($priceMod = $option->price_mod) { $OrderDetail->Price += $priceMod; } } } } } // associate with this order $OrderDetail->OrderID = $transaction->ID; // extend OrderDetail parsing, allowing for recording custom fields from FoxyCart $this->extend('handleOrderItem', $decrypted, $product, $OrderDetail); // write $OrderDetail->write(); } } } }
public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->CategoryID) { $default = ProductCategory::get()->filter(array('Code' => 'DEFAULT'))->first(); $this->CategoryID = $default->ID; } //update many_many lists when multi-group is on if (SiteConfig::current_site_config()->MultiGroup) { $holders = $this->ProductHolders(); $product = ProductPage::get()->byID($this->ID); if (isset($product->ParentID)) { $origParent = $product->ParentID; } else { $origParent = null; } $currentParent = $this->ParentID; if ($origParent != $currentParent) { if ($holders->find('ID', $origParent)) { $holders->removeByID($origParent); } } $holders->add($currentParent); } $title = ltrim($this->Title); $title = rtrim($title); $this->Title = $title; }
<?php include_once 'html.php'; include '_pageClass/HomePage.php'; include '_pageClass/ProductPage.php'; include '_pageClass/CategoryPage.php'; include '_pageClass/CategoriesPage.php'; switch ($currentPage) { case 'home-page': $obj = new HomePage(); $module = $obj->module(); break; case 'product-page': $obj = new ProductPage(); $module = $obj->module($params); break; case 'category-page': $obj = new CategoryPage(); $module = $obj->module($params, $catType); break; case 'categories-page': $obj = new CategoriesPage(); $module = $obj->module($params, $catType); break; } $data['current-page'] = $currentPage; if ($currentPage == 'product-page') { $data['product-detail'] = $module['productDetail']; $data['spin-content'] = $module['spinContent']; } $seoTags = $module['seoTags'];
/** * Products function. * * @access public * @return array */ public function ProductList($limit = 10) { $config = SiteConfig::current_site_config(); if ($config->ProductLimit > 0) { $limit = $config->ProductLimit; } if ($config->MultiGroup) { $entries = $this->Products()->sort('SortOrder'); } else { $filter = '"ParentID" = ' . $this->ID; // Build a list of all IDs for ProductGroups that are children $holderIDs = $this->ProductGroupIDs(); // If no ProductHolders, no ProductPages. So return false if ($holderIDs) { // Otherwise, do the actual query if ($filter) { $filter .= ' OR '; } $filter .= '"ParentID" IN (' . implode(',', $holderIDs) . ")"; } $order = '"SiteTree"."Title" ASC'; $entries = ProductPage::get()->where($filter); } $list = new PaginatedList($entries, Controller::curr()->request); $list->setPageLength($limit); return $list; }
/** * @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; }
/** * * */ protected function createProducts() { $this->alterationMessage("================================================ CREATING PRODUCTS ================================================", "show"); $productsCompleted = array(); foreach ($this->csv as $row) { if (!isset($productsCompleted[$row["ProductTitle"]])) { $filterArray = array("Title" => $row["ProductTitle"], "InternalItemID" => $row["ProductInternalItemID"]); $product = ProductPage::get()->filterAny($filterArray)->first(); if ($product && $product->ParentID) { $this->defaultProductParentID = $product->ParentID; } elseif (!$this->defaultProductParentID) { $this->defaultProductParentID = ProductGroup::get()->first()->ID; } if (!$product) { $product = ProductPage::create($filterArray); $product->MenuTitle = $row["ProductTitle"]; $this->alterationMessage("Creating Product: " . $row["ProductTitle"], "created"); } else { $this->alterationMessage("Product: " . $row["ProductTitle"] . " already exists"); } if (!$product->ParentID) { $product->ParentID = $this->defaultProductParentID; } $product->Title = $row["ProductTitle"]; $product->InternalItemID = $row["ProductInternalItemID"]; if ($this->forreal) { $this->addMoreProduct($product, $row); $product->write("Stage"); if ($product->IsPublished()) { $product->Publish('Stage', 'Live'); } } $productsCompleted[$row["ProductTitle"]] = $product->ID; $this->data[$product->ID] = array("Product" => $product, "VariationRows" => array()); } } $this->alterationMessage("================================================", "show"); }