/**
  * returns the inital (all) products, based on the all the eligile products
  * for the page.
  *
  * This is THE pivotal method that probably changes for classes that
  * extend ProductGroup as here you can determine what products or other buyables are shown.
  *
  * The return from this method will then be sorted and filtered to product the final product list
  *
  * @return DataObjectSet | Null
  **/
 public function currentInitialProducts($extraFilter = null, $alternativeFilterKey = '')
 {
     $this->allProducts = parent::currentInitialProducts();
     if (!$extraFilter) {
         $dos = null;
         //do nothing - show all products
     } elseif ($extraFilter instanceof DataList) {
         $dos = $tagOrTags;
         //do nothing
     } elseif ($tagOrTags instanceof DataObject) {
         $dos = new ArrayList(array($tagOrTags));
     } elseif (is_array($extraFilter) || intval($extraFilter) == $extraFilter) {
         $dos = EcommerceProductTag::get()->filter(array("ID" => $extraFilter));
     } else {
         return null;
     }
     //add at least one product - albeit a fake one...
     $idArray = array();
     if ($dos && $dos->count()) {
         foreach ($dos as $do) {
             $products = $do->getManyManyComponents('Products');
             if ($products && $products->count()) {
                 $addedArray = $products->column("ID");
                 if (is_array($addedArray) && count($addedArray)) {
                     $idArray = array_merge($idArray, $addedArray);
                 }
             }
         }
     }
     if (count($idArray)) {
         $this->allProducts = $this->allProducts->filter(array("ID" => $idArray));
     }
     return $this->allProducts;
 }
 /**
  * Retrieve a set of products, based on the given parameters.
  * Add Parent Group Pages to diplay within list.
  *
  * Note that you can hide the "top level"
  * @return DataObjectSet | Null
  */
 public function currentFinalProducts($alternativeSort = null)
 {
     $products = parent::currentFinalProducts($alternativeSort);
     if ($products) {
         foreach ($products as $product) {
             $product->ParentSegments = null;
             if ($this->NumberOfLevelsToHide < 20) {
                 $segmentArray = array();
                 $item = $product;
                 while ($item && $item->ParentID) {
                     $item = ProductGroup::get()->byID($item->ParentID);
                     if ($item) {
                         $segmentArray[] = array("URLSegment" => $item->URLSegment, "ID" => $item->ID, "ClassName" => $item->ClassName, "Title" => $item->Title, "Link" => $item->Link());
                     }
                 }
                 if (count($segmentArray)) {
                     $product->ParentSegments = new ArrayList();
                     $segmentArray = array_reverse($segmentArray);
                     foreach ($segmentArray as $key => $segment) {
                         if ($key > $this->NumberOfLevelsToHide) {
                             $product->ParentSegments->push(new ArrayData($segment));
                         }
                     }
                 }
             }
         }
     }
     return $products;
 }
Example #3
0
 public function indexAction()
 {
     $group = $this->getRequest()->getParam('product_group');
     $Product = Product::getByGroupId($group);
     $Group = ProductGroup::getById($group);
     $this->view->Product = $Product;
     $this->view->Title = $Group->name;
     $this->view->headTitle($this->view->Title);
 }
 /**
  * SS standard method
  * @return FieldSet
  */
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     foreach (array('Images', 'ProductDisplay', 'OtherProductsShown') as $name) {
         $fields->removeByName($name);
     }
     $fields->addFieldToTab("Root.Content.ProductsPerLoad", new NumericField("NumberOfProductsPerPage", _t("ProductGroup.PRODUCTSPERPAGE", "Number of products per page")));
     return $fields;
 }
 public function deleteAction()
 {
     $Product = ProductGroup::getById($this->getRequest()->getParam('id'));
     if ($Product) {
         if ($this->getRequest()->isPost()) {
             $Product->delete();
             $this->Member->log('Nhóm sản phẩm: ' . $Product->name . '(' . $this->getRequest()->getParam('id') . ')', 'Xóa');
             My_Plugin_Libs::setSplash('Nhóm sản phẩm: <b>' . $Product->name . '</b> đã được xóa khỏi hệ thống.');
             $this->_redirect($this->_helper->url('index', 'productgroup', 'admin'));
         }
         $this->view->Product = $Product;
     }
 }
 function run($request)
 {
     $myProductGroup = ProductGroup::get()->first();
     $myProduct = Product::get()->first();
     $html = "\r\n\t\tPlease use the links below:\r\n\t\t<ul>\r\n\t\t\t<li><a href=\"/shoppingcart/debug/\" target=\"_debug\">debug cart</a></li>\r\n\t\t\t<li><a href=\"/shoppingcart/ajaxtest/?ajax=1\" target=\"_debug\">view cart response</a></li>";
     if ($myProductGroup) {
         $html .= "\r\n\t\t\t<li><a href=\"" . $myProductGroup->Link("debug") . "\" target=\"_debug\">debug product group</a></li>";
     }
     if ($myProduct) {
         $html .= "\r\n\t\t\t<li><a href=\"" . $myProduct->Link("debug") . "\" target=\"_debug\">debug product</a></li>";
     }
     $html .= "\r\n\t\t</ul>";
     DB::alteration_message("{$html}");
 }
 protected function checkField($fieldName, $acceptableValuesArray, $resetValue)
 {
     $faultyProductGroups = ProductGroup::get()->exclude(array($fieldName => $acceptableValuesArray));
     if ($faultyProductGroups->count()) {
         foreach ($faultyProductGroups as $faultyProductGroup) {
             $faultyProductGroup->{$fieldName} = $resetValue;
             $faultyProductGroup->writeToStage('Stage');
             $faultyProductGroup->publish('Stage', 'Live');
             DB::alteration_message("Reset {$fieldName} for " . $faultyProductGroup->Title, 'created');
         }
     } else {
         DB::alteration_message("Could not find any faulty records for ProductGroup.{$fieldName}");
     }
 }
 function run($request)
 {
     if (!DataObject::get_one('Product')) {
         if (!DataObject::get_one('ProductGroup')) {
             $productGroup1 = new ProductGroup();
             $productGroup1->Title = 'Products';
             $productGroup1->Content = "\r\n\t\t\t\t\t<p>This is the top level products page, it uses the <em>product group</em> page type, and it allows you to show your products checked as 'featured' on it. It also allows you to nest <em>product group</em> pages inside it.</p>\r\n\t\t\t\t\t<p>For example, you have a product group called 'DVDs', and inside you have more product groups like 'sci-fi', 'horrors' or 'action'.</p>\r\n\t\t\t\t\t<p>In this example we have setup a main product group (this page), with a nested product group containing 2 example products.</p>\r\n\t\t\t\t";
             $productGroup1->URLSegment = 'products';
             $productGroup1->writeToStage('Stage');
             $productGroup1->publish('Stage', 'Live');
             DB::alteration_message('Product group page \'Products\' created', 'created');
         }
         $content = '<p>This is a <em>product</em>. It\'s description goes into the Content field as a standard SilverStripe page would have it\'s content. This is an ideal place to describe your product.</p>';
         $page1 = new Product();
         $page1->Title = 'Example product';
         $page1->Content = $content . '<p>You may also notice that we have checked it as a featured product and it will be displayed on the main Products page.</p>';
         $page1->URLSegment = 'example-product';
         $page1->ParentID = $productGroup1->ID;
         $page1->Price = '15.00';
         $page1->FeaturedProduct = true;
         $page1->writeToStage('Stage');
         $page1->publish('Stage', 'Live');
         DB::alteration_message('Product page \'Example product\' created', 'created');
         $page2 = new Product();
         $page2->Title = 'Example product 2';
         $page2->Content = $content;
         $page2->URLSegment = 'example-product-2';
         $page2->ParentID = $productGroup1->ID;
         $page2->Price = '25.00';
         $page2->writeToStage('Stage');
         $page2->publish('Stage', 'Live');
         DB::alteration_message('Product page \'Example product 2\' created', 'created');
     } else {
         DB::alteration_message('No products created as they already exist.');
     }
 }
 /**
  * Automatically creates some ProductGroup pages in
  * the CMS when the database builds if there hasn't
  * been any set up yet.
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('ProductGroup')) {
         $page1 = new ProductGroup();
         $page1->Title = 'Products';
         $page1->Content = "\n\t\t\t\t<p>This is the top level products page, it uses the <em>product group</em> page type, and it allows you to show your products checked as 'featured' on it. It also allows you to nest <em>product group</em> pages inside it.</p>\n\t\t\t\t<p>For example, you have a product group called 'DVDs', and inside you have more product groups like 'sci-fi', 'horrors' or 'action'.</p>\n\t\t\t\t<p>In this example we have setup a main product group (this page), with a nested product group containing 2 example products.</p>\n\t\t\t";
         $page1->URLSegment = 'products';
         $page1->writeToStage('Stage');
         $page1->publish('Stage', 'Live');
         Database::alteration_message('Product group page \'Products\' created', 'created');
         $page2 = new ProductGroup();
         $page2->Title = 'Example product group';
         $page2->Content = '<p>This is a nested <em>product group</em> within the main <em>product group</em> page. You can add a paragraph here to describe what this product group is about, and what sort of products you can expect to find in it.</p>';
         $page2->URLSegment = 'example-product-group';
         $page2->ParentID = $page1->ID;
         $page2->writeToStage('Stage');
         $page2->publish('Stage', 'Live');
         Database::alteration_message('Product group page \'Example product group\' created', 'created');
     }
 }
 function setParent(&$obj, $val, $record)
 {
     $title = strtolower(Convert::raw2sql($val));
     if ($title) {
         if ($parentpage = DataObject::get_one('ProductGroup', "LOWER(\"Title\") = '{$title}'", '"Created" DESC')) {
             // find or create parent category, if provided
             $obj->ParentID = $parentpage->ID;
             $obj->write();
             $obj->writeToStage('Stage');
             $obj->publish('Stage', 'Live');
             //TODO: otherwise assign it to the first prodcut group found
         } elseif (self::$createnewproductgroups) {
             //create parent product group
             $pg = new ProductGroup();
             $pg->setTitle($title);
             $pg->ParentID = self::$parentpageid ? $parentpageid : 0;
             $pg->writeToStage('Stage');
             $pg->publish('Stage', 'Live');
             $obj->ParentID = $pg->ID;
             $obj->write();
             $obj->writeToStage('Stage');
             $obj->publish('Stage', 'Live');
         }
     }
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     $mainGroup = MerchantGroupDOD::get_main_group();
     if ($mainGroup && $this->MerchantGroupCode()) {
         if ($this->CanEditType != 'OnlyTheseUsers') {
             $this->writeToStage('Stage');
             $this->doPublish();
         }
     }
 }
Example #12
0
 public function getGroupRequestParameter()
 {
     return ProductGroup::getRequestParameterName();
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     $parent = DataObject::get_by_id("MerchantPage", $this->ParentID);
     $filter = '';
     if ($parent) {
         $products = DataObject::get('MerchantProduct', "\"ParentID\" = {$this->ParentID}");
         if ($products) {
             $products = implode(',', $products->map('ID', 'ID'));
             $filter = " AND \"ProductID\" NOT IN ({$products})";
         }
     }
     DB::query("DELETE FROM \"Product_ProductGroups\" WHERE \"ProductGroupID\" = {$this->ID}{$filter}");
 }
Example #14
0
 private function updatesimple($typic, $grtype, $result, &$info)
 {
     if ($typic == 2) {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid " . " FROM tmp_xml a WHERE a.user=" . Yii::app()->user->uid . " AND a.ctype=" . $typic;
     } else {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid," . " b.id AS g_id, b.ckey AS  g_key, b.cname AS g_name, b.lid as g_lid " . " FROM tmp_xml a LEFT JOIN  tmp_xml b ON a.cgr=b.ckey AND b.user=" . Yii::app()->user->uid . " AND b.ctype=" . $grtype . " WHERE a.user=" . Yii::app()->user->uid . " AND a.ctype=" . $typic;
     }
     $recs = Yii::app()->db->createCommand($sql)->query();
     //we got the records for tmp_xml table
     $i = 0;
     $j = 0;
     $jj = 0;
     if (count($recs) > 0) {
         foreach ($recs as $value) {
             $doprod = 0;
             $doprodid = 0;
             $edid = 0;
             if ($value['p_lid'] === null) {
                 if ($result[$value['p_id']] === null) {
                     $doprod = -1;
                     $doprodid = 1;
                 } else {
                     $edid = (int) $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 2;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 1;
                     }
                 }
             } else {
                 if ($result[$value['p_id']] === null) {
                     $doprod = $value['p_lid'];
                 } else {
                     $edid = $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 3;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 4;
                     }
                 }
             }
             $grid = 0;
             if ($doprod < 0) {
                 if ($typic != 2) {
                     if ($value['g_lid'] === null) {
                         if ($typic == 0) {
                             $prodid = ProductgroupId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         } else {
                             $prodid = CountryId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         }
                         if ($prodid === null) {
                             if ($typic == 0) {
                                 $group = new ProductGroup();
                                 $group->tnam = $value['g_name'];
                                 $group->save();
                                 $grid = $group->ckey;
                                 $groupid = new ProductgroupId();
                             } else {
                                 $group = new Country();
                                 $group->name = $value['g_name'];
                                 $group->save();
                                 $grid = $group->id;
                                 $groupid = new CountryId();
                             }
                             $groupid->ckey = $value['g_key'];
                             $groupid->db = 1;
                             $groupid->id = $grid;
                             $groupid->save();
                             $i++;
                         } else {
                             $grid = $prodid->id;
                         }
                     } else {
                         $grid = $value['g_lid'];
                     }
                 } else {
                     $grid = 1;
                 }
                 if ($grid > 0) {
                     if ($typic == 0) {
                         $prod = new Product();
                         $prod->tnam = $value['p_name'];
                         $prod->cgr = $grid;
                         $it = TmpXml::model()->find('ctype=:ctype AND ckey=:ckey AND user=:user', array(':ctype' => 10, ':ckey' => $value['p_key'], ':user' => Yii::app()->user->uid));
                         if ($it) {
                             $prod->it = (int) $it->cname;
                         }
                         $prod->save();
                         $grid = $prod->ckey;
                     } else {
                         if ($typic == 1) {
                             $prod = new Client();
                             $prod->name = $value['p_name'];
                             $prod->country_id = $grid;
                             $prod->save();
                             $grid = $prod->id;
                             $this->updateprop($value['p_key'], $grid);
                             $this->updatebank($value['p_key'], $grid);
                         } else {
                             $prod = new Department();
                             $prod->name = $value['p_name'];
                             $prod->save();
                             $grid = $prod->id;
                             $this->updatebank($value['p_key'], $grid, 0);
                         }
                     }
                     $j++;
                     if ($doprodid == 1) {
                         if ($typic == 0) {
                             $prodid = new ProductId();
                         } else {
                             if ($typic == 1) {
                                 $prodid = new ClientId();
                             } else {
                                 $prodid = new DepartmentId();
                             }
                         }
                         $prodid->ckey = $value['p_key'];
                         $prodid->db = 1;
                         $prodid->id = $grid;
                         $prodid->save();
                     } else {
                         if ($typic == 0) {
                             $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             if ($typic == 1) {
                                 $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             } else {
                                 $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             }
                         }
                         if (!($prodid === null)) {
                             $prodid->id = $grid;
                             $prodid->save();
                         }
                     }
                 }
             }
             if ($doprodid == 2) {
                 if ($typic == 0) {
                     $prodid = new ProductId();
                 } else {
                     if ($typic == 1) {
                         $prodid = new ClientId();
                     } else {
                         $prodid = new DepartmentId();
                     }
                 }
                 $prodid->ckey = $value['p_key'];
                 $prodid->db = 1;
                 $prodid->id = $edid;
                 $prodid->save();
             } else {
                 if ($doprodid == 3) {
                     if ($typic == 0) {
                         $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                     } else {
                         if ($typic == 1) {
                             $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         }
                     }
                     if (!($prodid === null)) {
                         $prodid->id = $edid;
                         $prodid->save();
                     }
                 }
             }
             if ($doprod > 0) {
                 if ($typic == 0) {
                     $prod = Product::model()->findByPk($doprod);
                     if (!($prod === null)) {
                         if ($prod->tnam != $value['p_name']) {
                             $prod->tnam = $value['p_name'];
                             $prod->save();
                             $jj = 0;
                         }
                     }
                 } else {
                     if ($typic == 1) {
                         $prod = Client::model()->findByPk($doprod);
                         if (!($prod === null)) {
                             if ($prod->name != $value['p_name']) {
                                 $prod->name = $value['p_name'];
                                 $prod->save();
                                 $jj = 0;
                             }
                             $this->updateprop($value['p_key'], $prod->id);
                             $this->updatebank($value['p_key'], $prod->id);
                         }
                     } else {
                         if (!($prop = DepartmentProp::model()->findByPk(array('id' => $doprod, '_key' => 'stop')))) {
                             $prod = Department::model()->findByPk($doprod);
                             if (!($prod === null)) {
                                 if ($prod->name != $value['p_name']) {
                                     $prod->name = $value['p_name'];
                                     $prod->save();
                                     $jj = 0;
                                 }
                             }
                             $this->updatebank($value['p_key'], $doprod, 0);
                         }
                     }
                 }
             }
         }
     }
     if ($typic == 0) {
         $info[] = 'Создано новых групп товаров:' . $i;
         $info[] = 'Создано новых товаров:' . $j;
         $info[] = 'Обновлено товаров:' . $jj;
     } else {
         if ($typic == 1) {
             $info[] = 'Создано новых групп клиентов:' . $i;
             $info[] = 'Создано новых клиентов:' . $j;
             $info[] = 'Обновлено клиентов:' . $jj;
         } else {
             $info[] = 'Создано новых фирм:' . $j;
             $info[] = 'Обновлено фирм:' . $jj;
         }
     }
     return;
 }
 /**
  *
  *
  */
 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");
 }
 /**
  * Provides a dataset of links for sorting products.
  */
 function SortLinks()
 {
     if (count(ProductGroup::get_sort_options()) <= 0) {
         return null;
     }
     $sort = isset($_GET['sortby']) ? Convert::raw2sql($_GET['sortby']) : "Title";
     $dos = new DataObjectSet();
     foreach (ProductGroup::get_sort_options() as $field => $name) {
         $current = $field == $sort ? 'current' : false;
         $dos->push(new ArrayData(array('Name' => $name, 'Link' => $this->Link() . "?sortby={$field}", 'Current' => $current)));
     }
     return $dos;
 }
Example #17
0
 private function setPG($id,$val,$prod=0) {
    $found=ProductgroupId::model()->findByPk(array('ckey'=>$val->par,'db'=>1));
     if($found)
     {
      if($prod==0)
          $pg= ProductGroup::model()->findByPk($id);
     else
          $pg= Product::model()->findByPk($id);
        if($pg)
          {
       if($prod!=0)
           $pg->it=(int)$val->it;
           $pg->cgr=$found->id;
           $pg->save();
          }
      }
 }
Example #18
0
 /**
  *
  * @param $action string
  * @param $productId int
  * @return nothing
  * @author Tremor
  */
 public function productAction($action, $productId = 0)
 {
     if (isset($productId) && !empty($productId) && !is_numeric($productId)) {
         return Redirect::to('admin/product');
     }
     switch ($action) {
         case 'add':
             $product = new Product();
             $product->save();
             $newId = $product->id;
             return Redirect::to('admin/product/' . $newId);
             break;
         case 'edit':
             $post = Input::except('_token');
             $sizeList = Input::only('size');
             $groupList = Input::only('group');
             // product
             $product = Product::find($productId);
             foreach ($post as $key => $val) {
                 if (isset($product->{$key})) {
                     $product->{$key} = $key == 'alias' ? camel_case($val) : $val;
                 }
             }
             $product->save();
             if (empty($product->alias)) {
                 $product->alias = camel_case($post['name']);
                 $product->save();
             }
             // product sizes
             if (!empty($sizeList['size'])) {
                 foreach ($sizeList['size'] as $key => $val) {
                     ProductSize::find($key)->update($val);
                 }
             }
             // product groups
             if (!empty($groupList['group'])) {
                 foreach ($groupList['group'] as $key => $val) {
                     ProductGroup::find($key)->update($val);
                 }
             }
             return Redirect::to('admin/product/' . $productId);
             break;
         case 'delete':
             $product = Product::find($productId);
             $product->delete();
             $productSizeList = ProductSize::where('product_id', $productId)->get();
             if ($productSizeList) {
                 foreach ($productSizeList as $size) {
                     $size->delete();
                 }
             }
             $productGroupList = ProductGroup::where('product_id', $productId)->get();
             if ($productGroupList) {
                 foreach ($productGroupList as $group) {
                     $group->delete();
                 }
             }
             break;
         case 'addPriceSize':
             $this->data['productSize'] = ProductSize::create(array('product_id' => $productId));
             $this->data['sizeList'] = Size::all();
             $answer['content'] = View::make('admin.product.priceSizeTr')->with($this->data)->render();
             return json_encode($answer);
             break;
         case 'removePriceSize':
             $priceSizeId = Input::get('priceSizeId', false);
             if ($priceSizeId != false) {
                 ProductSize::find($priceSizeId)->delete();
                 return json_encode($answer['true'] = true);
             }
             break;
         case 'addGroup':
             $this->data['productGroup'] = ProductGroup::create(array('product_id' => $productId));
             $this->data['groupList'] = Group::all();
             $answer['content'] = View::make('admin.product.groupTr')->with($this->data)->render();
             return json_encode($answer);
             break;
         case 'removeGroup':
             $groupId = Input::get('groupId', false);
             if ($groupId != false) {
                 ProductGroup::find($groupId)->delete();
                 return json_encode($answer['true'] = true);
             }
             break;
         default:
             break;
     }
     return Redirect::to('admin/product');
 }
    private function collateexamplepages()
    {
        $this->addExamplePages(0, "Checkout page", CheckoutPage::get()->First());
        $this->addExamplePages(0, "Order Confirmation page", OrderConfirmationPage::get()->First());
        $this->addExamplePages(0, "Cart page (review cart without checkout)", CartPage::get()->where("ClassName = 'CartPage'")->First());
        $this->addExamplePages(0, "Account page", AccountPage::get()->First());
        //$this->addExamplePages(1, "Donation page", AnyPriceProductPage::get()->First());
        $this->addExamplePages(1, "Products that can not be sold", Product::get()->where("\"AllowPurchase\" = 0 AND ClassName = 'Product'")->First());
        $this->addExamplePages(1, "Product group with short product display template", ProductGroup::get()->where("\"DisplayStyle\" = 'Short'")->First());
        $this->addExamplePages(1, "Product group with medium length product display template", ProductGroup::get()->where("\"DisplayStyle\" = ''")->First());
        $this->addExamplePages(1, "Product group with more detail product display template", ProductGroup::get()->where("\"DisplayStyle\" = 'MoreDetail'")->First());
        //$this->addExamplePages(1, "Quick Add page", AddToCartPage::get()->first());
        //$this->addExamplePages(1, "Shop by Tag page ", ProductGroupWithTags::get()->first());
        $this->addExamplePages(2, "Delivery options (add product to cart first)", CheckoutPage::get()->First());
        $this->addExamplePages(2, "Taxes (NZ based GST - add product to cart first)", CheckoutPage::get()->first());
        $this->addExamplePages(2, "Discount Coupon (try <i>AAA</i>)", CheckoutPage::get()->First());
        $this->addExamplePages(4, "Products with zero price", Product::get()->where("\"Price\" = 0 AND ClassName = 'Product'")->First());
        //$this->addExamplePages(5, "Corporate Account Order page", AddUpProductsToOrderPage::get()->First());
        $html = '
		<h2>Some Interesting Features</h2>
		<p>
			Below are some features of this e-commerce application that may be of interest to you:
		</p>
		<ul>
			<li>customised search for users with search history graphs for admins</li>
			<li>ability to check-out with or without adding a password (creating an account)</li>
			<li>easy to use CMS</li>
			<li>very fast product listings, making extensive use of caching</li>
			<li>many ways to display products, allowing the content editor to set things like <i>products per page</i>, <i>product selctions</i>, <i>sorting orders</i></li>
			<li>multi-currency options and currency conversions</li>
			<li>step-by-step system for completed orders leading them from being submitted to archived via very steps.  This allows the admin to review orders where needed, add extra information, such as tracking codes for delivery, etc...</li>
			<li>code that is very easy to customise and adjust for your needs</li>
			<li>a ton of additional modules are available - you can add them directly to your e-commece install or use these as examples for building your own extensions </li>
			<li>geo-coding for addresses</li>
			<li>extensive developer assistance through various tools and personalised help</li>
		</ul>
		<h2>examples shown on this demo site</h2>';
        foreach ($this->examplePages as $key => $exampleGroups) {
            $html .= "<h3>" . $exampleGroups["Title"] . "</h3><ul>";
            foreach ($exampleGroups["List"] as $examplePages) {
                $html .= '<li><span class="exampleTitle">' . $examplePages["Title"] . '</span>' . $examplePages["List"] . '</li>';
            }
            $html .= "</ul>";
        }
        $html .= '
		<h2>API Access</h2>
		<p>
			E-commerce allows you to access its model using the built-in Silverstripe API.
			This is great for communication with third party applications.
			Access examples are listed below:
		</p>
		<ul>
			<li><a href="/api/v1/Order/">view all orders</a></li>
			<li><a href="/api/v1/Order/1">view order with ID = 1</a></li>
		</ul>
		<p>
			For more information on the restful server API, you can visit the modules home: <a href="https://github.com/silverstripe/silverstripe-restfulserver">https://github.com/silverstripe/silverstripe-restfulserver</a> to find out more on this topic.
		</p>
		';
        $featuresPage = Page::get()->where("URLSegment = 'features'")->First();
        $featuresPage->Content .= $html;
        $featuresPage->write();
        $featuresPage->Publish('Stage', 'Live');
        $featuresPage->flushCache();
    }
Example #20
0
 /**
  * Imports objects based on a specified CSV file in $_GET['FileName']
  */
 function import()
 {
     $FileName = $_GET['FileName'];
     $FileName = $_SERVER['DOCUMENT_ROOT'] . substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) - 18) . "/assets/" . $FileName;
     if (file_exists($FileName)) {
         $handle = fopen($FileName, 'r');
         if ($handle) {
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 $num = count($data);
                 $row++;
                 if ($row == 1) {
                     for ($c = 0; $c < $num; $c++) {
                         $ColumnHeaders[] = str_replace(' ', '', $data[$c]);
                         // Have to add code here to remove unsafe chars..
                     }
                 } else {
                     $Product = new Product();
                     for ($c = 0; $c < $num; $c++) {
                         $Product->{$ColumnHeaders}[$c] = trim($data[$c]);
                     }
                     $MainCategory = DataObject::get("ProductGroup", "URLSegment LIKE '" . $Product->generateURLSegment($Product->Category) . "'");
                     if (!$MainCategory) {
                         // if we can't find a main category, create all three sub
                         // categories, as they must be unique.
                         $ProductGroup = new ProductGroup();
                         $ProductGroup->Title = $Product->Category;
                         print_r("<ul><li>Created : {$ProductGroup->Title}</li>");
                         $ProductGroup->ParentID = 1;
                         $index = $ProductGroup->write();
                         $ProductGroup->flushCache();
                         if ($Product->SubCategory) {
                             $ChildProductGroup = new ProductGroup();
                             $ChildProductGroup->Title = $Product->SubCategory;
                             print_r("<ul><li>Created : {$ChildProductGroup->Title}</li>");
                             $ChildProductGroup->ClassName = "ProductGroup";
                             $ChildProductGroup->ParentID = $index;
                             $index = $ChildProductGroup->write();
                             $ChildProductGroup->flushCache();
                         }
                         if ($Product->SubCategory2) {
                             $NestedProductGroup = new ProductGroup();
                             $NestedProductGroup->Title = $Product->SubCategory2;
                             print_r("<ul><li>Created : {$NestedProductGroup->Title}</li>");
                             $NestedProductGroup->ClassName = "ProductGroup";
                             $NestedProductGroup->ParentID = $index;
                             $index = $NestedProductGroup->write();
                             $NestedProductGroup->flushCache();
                         }
                     } else {
                         // We've  found a main category. check if theres a second...
                         print_r("<ul><li>USING : {$MainCategory->Title}</li>");
                         $index = $MainCategory->ID;
                         $SubCategory = DataObject::get_one("ProductGroup", "URLSegment LIKE '" . $Product->generateURLSegment($Product->SubCategory) . "'");
                         if (!$SubCategory && $Product->SubCategory) {
                             $ChildProductGroup = new ProductGroup();
                             $ChildProductGroup->Title = $Product->SubCategory;
                             print_r("<ul><li>Created : {$ChildProductGroup->Title}</li>");
                             $ChildProductGroup->ClassName = "ProductGroup";
                             $ChildProductGroup->ParentID = $index;
                             $index = $ChildProductGroup->write();
                             $ChildProductGroup->flushCache();
                             if ($Product->SubCategory2) {
                                 $NestedProductGroup = new ProductGroup();
                                 $NestedProductGroup->Title = $Product->SubCategory2;
                                 print_r("<ul><li>{$NestedProductGroup->Title}</li>");
                                 $NestedProductGroup->ClassName = "ProductGroup";
                                 $NestedProductGroup->ParentID = $index;
                                 $index = $NestedProductGroup->write();
                                 $NestedProductGroup->flushCache();
                                 $index = $SubCategory2->ID;
                             }
                         } else {
                             if ($Product->SubCategory) {
                                 print_r("<ul><li>USING : {$SubCategory->Title}</li>");
                                 $index = $SubCategory->ID;
                                 $SubCategory2 = DataObject::get_one("ProductGroup", "URLSegment LIKE '" . $Product->generateURLSegment($Product->SubCategory2) . "'");
                                 if ($Product->SubCategory2) {
                                     $NestedProductGroup = new ProductGroup();
                                     $NestedProductGroup->Title = $Product->SubCategory2;
                                     print_r("<ul><li>{$NestedProductGroup->Title}</li>");
                                     $NestedProductGroup->ClassName = "ProductGroup";
                                     $NestedProductGroup->ParentID = $index;
                                     $index = $NestedProductGroup->write();
                                     $NestedProductGroup->flushCache();
                                     $index = $SubCategory2->ID;
                                 }
                             }
                         }
                     }
                     $MatchedProduct = DataObject::get_one("Product", "URLSegment LIKE '" . $Product->generateURLSegment($Product->Title) . "'");
                     if ($MatchedProduct) {
                         // create the new parents / assign many many
                         $MatchedProduct->ParentID = $index;
                         // create the new product
                         $MatchedProduct->write();
                         $MatchedProduct->flushCache();
                         print_r(" <h4>UPDATED</h4></ul></ul></ul><br/><br/>");
                     } else {
                         // save the new product
                         $Product->ParentID = $index;
                         $Product->write();
                         $Product->flushCache();
                         print_r(" <h4>New Product {$product->Title}</h4></ul></ul></ul><br/><br/>");
                     }
                 }
             }
             fclose($handle);
         } else {
             print_r("<h1>Error: Could not open file.</h1>");
         }
     } else {
         print_r("<h1>Error: Could not open file.</h1>");
     }
 }
Example #21
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return ProductGroup the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ProductGroup::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Order::set_receipt_subject("Shop Sale Information #%d");
Order::set_modifiers(array(), true);
Order::set_table_overview_fields(array('ID' => 'Order No', 'Created' => 'Created', 'FirstName' => 'First Name', 'Surname' => 'Surname', 'Total' => 'Total', 'Status' => 'Status'));
Order::set_maximum_ignorable_sales_payments_difference(0.01);
Order::set_order_id_start_number(0);
Order::set_cancel_before_payment(true);
Order::set_cancel_before_processing(false);
Order::set_cancel_before_sending(false);
Order::set_cancel_after_sending(false);
OrderForm::set_user_membership_optional(false);
OrderForm::set_force_membership(true);
OrderManipulation::set_allow_cancelling(false);
OrderManipulation::set_allow_paying(false);
// * * * PRODUCTS
ProductsAndGroupsModelAdmin::set_managed_models(array("Product", "ProductGroup", "ProductVariation", "ProductAttributeType"));
Product_Image::set_thumbnail_size(140, 100);
Product_Image::set_content_image_width(200);
Product_Image::set_large_image_width(200);
ProductGroup::set_include_child_groups(true);
ProductGroup::set_must_have_price(true);
ProductGroup::set_sort_options(array('Title' => 'Alphabetical', 'Price' => 'Lowest Price'));
// * * * CHECKOUT
ExpiryDateField::set_short_months(true);
OrderFormWithoutShippingAddress::set_fixed_country_code(null);
OrderFormWithoutShippingAddress::set_postal_code_url("http://www.nzpost.co.nz/Cultures/en-NZ/OnlineTools/PostCodeFinder");
OrderFormWithoutShippingAddress::set_postal_code_label("find postcode");
OrderFormWithoutShippingAddress::set_login_invite_alternative_text('Please <a href="Security/login?BackURL=/">log in now</a> to retrieve your account details or create an account below.');
// * * * MEMBER
EcommerceRole::set_group_name("Shop Customers");
// * * * HELP
Product::set_global_allow_purchase(true);
 function doProductSearchForm($data, $form)
 {
     if (!$this->maximumNumberOfResults) {
         $this->maximumNumberOfResults = EcommerceConfig::get("ProductGroup", "maximum_number_of_products_to_list");
     }
     if (isset($data["DebugSearch"])) {
         $this->debug = $data["DebugSearch"] ? true : false;
     }
     if ($this->debug) {
         $this->debugOutput("<hr /><hr /><hr /><h2>Debugging Search Results</h2>");
     }
     //what is the baseclass?
     $baseClassName = $this->baseClassForBuyables;
     if (!$baseClassName) {
         $baseClassName = EcommerceConfig::get("ProductGroup", "base_buyable_class");
     }
     if (!$baseClassName) {
         user_error("Can not find {$baseClassName} (baseClassName)");
     }
     //basic get
     $searchableFields = $baseClassName::create()->stat('searchable_fields');
     $baseList = $baseClassName::get()->filter(array("ShowInSearch" => 1));
     $ecomConfig = EcommerceDBConfig::current_ecommerce_db_config();
     if ($ecomConfig->OnlyShowProductsThatCanBePurchased) {
         $baseList->filter(array("AllowPurchase" => 1));
     }
     $limitToCurrentSection = false;
     if (isset($data["SearchOnlyFieldsInThisSection"]) && $data["SearchOnlyFieldsInThisSection"]) {
         $limitToCurrentSection = true;
         if ($this->productsToSearch instanceof DataList) {
             $this->productsToSearch = $this->productsToSearch->map("ID", "ID")->toArray();
         }
         $baseList = $baseList->filter(array("ID" => $this->productsToSearch));
     }
     if (isset($data["MinimumPrice"]) && $data["MinimumPrice"]) {
         $baseList = $baseList->filter(array("Price:GreaterThanOrEqual" => floatval($data["MinimumPrice"])));
     }
     if (isset($data["MaximumPrice"]) && $data["MaximumPrice"]) {
         $baseList = $baseList->filter(array("Price:LessThanOrEqual" => floatval($data["MaximumPrice"])));
     }
     //defining some variables
     $isKeywordSearch = false;
     if ($this->debug) {
         $this->debugOutput("<hr /><h3>BASE LIST</h3><pre>" . str_replace($this->sqlWords, array_flip($this->sqlWords), $baseList->sql()) . "</pre>");
     }
     //KEYWORD SEARCH - only bother if we have any keywords and results at all ...
     if (isset($data["ShortKeyword"]) && !isset($data["Keyword"])) {
         $data["Keyword"] = $data["ShortKeyword"];
     }
     if (isset($data["Keyword"]) && ($keywordPhrase = $data["Keyword"])) {
         if ($baseList->count()) {
             if (strlen($keywordPhrase) > 1) {
                 $isKeywordSearch = true;
                 $this->resultArrayPos = 0;
                 $this->resultArray = array();
                 $keywordPhrase = Convert::raw2sql($keywordPhrase);
                 $keywordPhrase = strtolower($keywordPhrase);
                 SearchHistory::add_entry($keywordPhrase);
                 // 1) Exact search by code
                 $count = 0;
                 if ($this->debug) {
                     $this->debugOutput("<hr /><h2>SEARCH BY CODE</h2>");
                 }
                 if ($code = intval($keywordPhrase)) {
                     $list1 = $baseList->filter(array("InternalItemID" => $code));
                     $count = $list1->count();
                     if ($count == 1) {
                         if (!$this->debug) {
                             return $this->controller->redirect($list1->First()->Link());
                         }
                     } elseif ($count > 1) {
                         if ($this->addToResults($list1)) {
                             break;
                         }
                     }
                 }
                 if ($this->debug) {
                     $this->debugOutput("<h3>SEARCH BY CODE RESULT: {$count}</h3>");
                 }
                 // 2) Search of the entire keyword phrase and its replacements
                 $count = 0;
                 if ($this->debug) {
                     $this->debugOutput("<hr /><h3>FULL KEYWORD SEARCH</h3>");
                 }
                 if ($this->resultArrayPos <= $this->maximumNumberOfResults) {
                     //now we are going to look for synonyms
                     $words = explode(' ', trim(preg_replace('!\\s+!', ' ', $keywordPhrase)));
                     foreach ($words as $wordKey => $word) {
                         if ($this->debug) {
                             $this->debugOutput("checking for aliases of {$word}");
                         }
                         $replacements = SearchReplacement::get()->where("\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") = '{$word}' OR\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") LIKE '%,{$word}' OR\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") LIKE '{$word},%' OR\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") LIKE '%,{$word},%'");
                         if ($replacements->count()) {
                             $replacementsArray = $replacements->map('ID', 'Replace')->toArray();
                             if ($this->debug) {
                                 $this->debugOutput("found alias for {$word}");
                             }
                             foreach ($replacementsArray as $replacementWord) {
                                 $keywordPhrase = str_replace($word, $replacementWord, $keywordPhrase);
                             }
                         }
                     }
                     if ($this->debug) {
                         $this->debugOutput("<pre>WORD ARRAY: " . print_r($keywordPhrase, 1) . "</pre>");
                     }
                     //work out searches
                     $singleton = $baseClassName::create();
                     foreach ($this->extraBuyableFieldsToSearchFullText as $tempClassName => $fieldArrayTemp) {
                         if ($singleton instanceof $tempClassName) {
                             $fieldArray = $fieldArrayTemp;
                             break;
                         }
                     }
                     if ($this->debug) {
                         $this->debugOutput("<pre>FIELD ARRAY: " . print_r($fieldArray, 1) . "</pre>");
                     }
                     $searches = $this->getSearchArrays($keywordPhrase, $fieldArray);
                     //if($this->debug) { $this->debugOutput("<pre>SEARCH ARRAY: ".print_r($searches, 1)."</pre>");}
                     //we search exact matches first then other matches ...
                     foreach ($searches as $search) {
                         $list2 = $baseList->where($search);
                         $count = $list2->count();
                         if ($this->debug) {
                             $this->debugOutput("<p>{$search}: {$count}</p>");
                         }
                         if ($count == 1) {
                             if (!$this->debug) {
                                 return $this->controller->redirect($list2->First()->Link());
                             }
                         } elseif ($count > 1) {
                             if ($this->addToResults($list2)) {
                                 break;
                             }
                         }
                         if ($this->resultArrayPos > $this->maximumNumberOfResults) {
                             break;
                         }
                     }
                 }
                 if ($this->debug) {
                     $this->debugOutput("<h3>FULL KEYWORD SEARCH: {$count}</h3>");
                 }
                 if ($this->debug) {
                     $this->debugOutput("<hr /><h3>PRODUCT GROUP SEARCH</h3>");
                 }
                 // 3) Do the same search for Product Group names
                 $count = 0;
                 if ($limitToCurrentSection) {
                     //cant search other sections in this case...
                 } else {
                     $searches = $this->getSearchArrays($keywordPhrase);
                     if ($this->debug) {
                         $this->debugOutput("<pre>SEARCH ARRAY: " . print_r($searches, 1) . "</pre>");
                     }
                     foreach ($searches as $search) {
                         $productGroups = ProductGroup::get()->where($search)->filter(array("ShowInSearch" => 1));
                         $count = $productGroups->count();
                         //redirect if we find exactly one match and we have no matches so far...
                         if ($count == 1 && !$this->resultArrayPos) {
                             if (!$this->debug) {
                                 return $this->controller->redirect($productGroups->First()->Link());
                             }
                         } elseif ($count) {
                             foreach ($productGroups as $productGroup) {
                                 //we add them like this because we like to keep them in order!
                                 if (!in_array($productGroup->ID, $this->productGroupIDs)) {
                                     $this->productGroupIDs[] = $productGroup->ID;
                                 }
                             }
                         }
                     }
                     if ($this->debug) {
                         $this->debugOutput("<h3>PRODUCT GROUP SEARCH: {$count}</h3>");
                     }
                 }
             }
         }
     }
     if (!$isKeywordSearch) {
         $this->addToResults($baseList);
     }
     $redirectToPage = null;
     //if no specific section is being searched then we redirect to search page:
     if (!$limitToCurrentSection) {
         $redirectToPage = ProductGroupSearchPage::get()->first();
     }
     if (!$redirectToPage) {
         // for section specific search,
         // redirect to the specific section (basically where we came from)
         $redirectToPage = $this->controller->dataRecord;
     }
     if ($this->debug) {
         $this->debugOutput("<hr />" . "<h3>Previous Search Products: " . $redirectToPage->SearchResultsSessionVariable(false) . "</h3><p>" . print_r(Session::get($redirectToPage->SearchResultsSessionVariable(false)), 1) . "</p>" . "<h3>Previous Search Groups: " . $redirectToPage->SearchResultsSessionVariable(true) . "</h3><p>" . print_r(Session::get($redirectToPage->SearchResultsSessionVariable(true)), 1) . "</p>");
     }
     Session::set($redirectToPage->SearchResultsSessionVariable(false), implode(",", $this->resultArray));
     Session::set($redirectToPage->SearchResultsSessionVariable(true), implode(",", $this->productGroupIDs));
     Session::save();
     if ($this->debug) {
         $this->debugOutput("<hr />" . "<h3>SAVING Products to session: " . $redirectToPage->SearchResultsSessionVariable(false) . "</h3><p>" . print_r(explode(",", Session::get($redirectToPage->SearchResultsSessionVariable(false))), 1) . "</p>" . "<h3>SAVING Groups to session: " . $redirectToPage->SearchResultsSessionVariable(true) . "</h3><p>" . print_r(explode(",", Session::get($redirectToPage->SearchResultsSessionVariable(true))), 1) . "</p>");
     }
     $link = $redirectToPage->Link($this->controllerSearchResultDisplayMethod);
     if ($this->additionalGetParameters) {
         $link .= "?" . $this->additionalGetParameters;
     }
     if ($this->debug) {
         die($link);
     }
     $this->controller->redirect($link);
 }
 public function debug()
 {
     $html = EcommerceTaskDebugCart::debug_object($this);
     $html .= "<ul>";
     $html .= "<li><hr />Links<hr /></li>";
     $html .= "<li><b>Link:</b> <a href=\"" . $this->Link() . "\">" . $this->Link() . "</a></li>";
     $html .= "<li><b>Ajax Link:</b> <a href=\"" . $this->AjaxLink() . "\">" . $this->AjaxLink() . "</a></li>";
     $html .= "<li><b>AddVariations Link:</b> <a href=\"" . $this->AddVariationsLink() . "\">" . $this->AddVariationsLink() . "</a></li>";
     $html .= "<li><b>Add to Cart Link:</b> <a href=\"" . $this->AddLink() . "\">" . $this->AddLink() . "</a></li>";
     $html .= "<li><b>Increment Link:</b> <a href=\"" . $this->IncrementLink() . "\">" . $this->IncrementLink() . "</a></li>";
     $html .= "<li><b>Decrement Link:</b> <a href=\"" . $this->DecrementLink() . "\">" . $this->DecrementLink() . "</a></li>";
     $html .= "<li><b>Remove Link:</b> <a href=\"" . $this->RemoveAllLink() . "\">" . $this->RemoveLink() . "</a></li>";
     $html .= "<li><b>Remove All Link:</b> <a href=\"" . $this->RemoveAllLink() . "\">" . $this->RemoveAllLink() . "</a></li>";
     $html .= "<li><b>Remove All and Edit Link:</b> <a href=\"" . $this->RemoveAllAndEditLink() . "\">" . $this->RemoveAllAndEditLink() . "</a></li>";
     $html .= "<li><b>Set Specific Quantity Item Link (e.g. 77):</b> <a href=\"" . $this->SetSpecificQuantityItemLink(77) . "\">" . $this->SetSpecificQuantityItemLink(77) . "</a></li>";
     $html .= "<li><hr />Cart<hr /></li>";
     $html .= "<li><b>Allow Purchase (DB Value):</b> " . $this->AllowPurchaseNice() . " </li>";
     $html .= "<li><b>Can Purchase (overal calculation):</b> " . ($this->canPurchase() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Shop Open:</b> " . ($this->EcomConfig() ? $this->EcomConfig()->ShopClosed ? "NO" : "YES" : "NO CONFIG") . " </li>";
     $html .= "<li><b>Extended Country Can Purchase:</b> " . ($this->extendedCan('canPurchaseByCountry', null) === null ? "no applicable" : ($this->extendedCan('canPurchaseByCountry', null) ? "CAN PURCHASE" : "CAN NOT PURCHASE")) . " </li>";
     $html .= "<li><b>Allow sales to this country (" . EcommerceCountry::get_country() . "):</b> " . (EcommerceCountry::allow_sales() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Class Name for OrderItem:</b> " . $this->classNameForOrderItem() . " </li>";
     $html .= "<li><b>Quantity Decimals:</b> " . $this->QuantityDecimals() . " </li>";
     $html .= "<li><b>Is In Cart:</b> " . ($this->IsInCart() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Has Been Sold:</b> " . ($this->HasBeenSold() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Calculated Price:</b> " . $this->CalculatedPrice() . " </li>";
     $html .= "<li><b>Calculated Price as Money:</b> " . $this->getCalculatedPriceAsMoney()->Nice() . " </li>";
     $html .= "<li><hr />Location<hr /></li>";
     $html .= "<li><b>Main Parent Group:</b> " . $this->MainParentGroup()->Title . "</li>";
     $html .= "<li><b>All Others Parent Groups:</b> " . ($this->AllParentGroups()->count() ? "<pre>" . print_r($this->AllParentGroups()->map()->toArray(), 1) . "</pre>" : "none") . "</li>";
     $html .= "<li><hr />Image<hr /></li>";
     $html .= "<li><b>Image:</b> " . ($this->BestAvailableImage() ? "<img src=" . $this->BestAvailableImage()->Link() . " />" : "no image") . " </li>";
     $productGroup = ProductGroup::get()->byID($this->ParentID);
     if ($productGroup) {
         $html .= "<li><hr />Product Example<hr /></li>";
         $html .= "<li><b>Product Group View:</b> <a href=\"" . $productGroup->Link() . "\">" . $productGroup->Title . "</a> </li>";
         $html .= "<li><b>Product Group Debug:</b> <a href=\"" . $productGroup->Link("debug") . "\">" . $productGroup->Title . "</a> </li>";
         $html .= "<li><b>Product Group Admin:</b> <a href=\"" . "/admin/pages/edit/show/" . $productGroup->ID . "\">" . $productGroup->Title . " Admin</a> </li>";
         $html .= "<li><b>Edit this Product:</b> <a href=\"" . "/admin/pages/edit/show/" . $this->ID . "\">" . $this->Title . " Admin</a> </li>";
     }
     $html .= "</ul>";
     return $html;
     $html .= "</ul>";
     return $html;
 }
 /**
  * After a search is conducted you may end up with a bunch
  * of recommended product groups. They will be returned here...
  * We sort the list in the order that it is provided.
  * @return DataList | Null (ProductGroups)
  */
 public function SearchResultsChildGroups()
 {
     $groupArray = explode(",", Session::get($this->SearchResultsSessionVariable($isForGroup = true)));
     if (is_array($groupArray) && count($groupArray)) {
         $sortStatement = $this->createSortStatementFromIDArray($groupArray, "ProductGroup");
         return ProductGroup::get()->filter(array("ID" => $groupArray, "ShowInSearch" => 1))->sort($sortStatement);
     }
     return null;
 }
 function __construct($controller, $name, $moduleProductID = 0)
 {
     $fields = new FieldList();
     $moduleProduct = null;
     if ($moduleProductID) {
         $fields->push(new HeaderField('AddEditModule', 'Edit ' . $controller->dataRecord->Title, 2));
         $fields->push(new HiddenField('ModuleProductID', $moduleProductID, $moduleProductID));
         $moduleProduct = ModuleProduct::get()->byID($moduleProductID);
     } else {
         $fields->push(new HeaderField('AddEditModule', $controller->dataRecord->Title, 2));
         $fields->push(new HiddenField('ModuleProductID', 0, 0));
     }
     $fields->push(new TextField('Code', 'Code (folder name)'));
     $moduleProductGroups = ModuleProductGroup::get()->filter(array("ParentID:GreaterThan" => 0));
     if (ModuleProductGroup::get()->count()) {
         $types = array("" => " --- please select ---");
         $types += ModuleProductGroup::get()->map($index = 'ID', $titleField = 'MenuTitle')->toArray();
     } else {
         $types = array();
     }
     //$fields->push(new DropdownField('ParentID','Type', $types, $controller->dataRecord->ID));
     $fields->push(new TextField('Title', 'Title'));
     $fields->push(new TextareaField('MetaDescription', 'Three sentence Introduction'));
     $fields->push(new HtmlEditorField('Content', 'Long Description'));
     $fields->push(new TextField('AdditionalTags', 'Additional Keyword(s), comma separated'));
     $fields->push(new HeaderField('LinkHeader', 'Links', 4));
     $fields->push(new TextField('MainURL', 'Home page'));
     $fields->push(new TextField('ReadMeURL', 'Read me file - e.g. http://www.mymodule.com/readme.md'));
     $fields->push(new TextField('DemoURL', 'Demo - e.g. http://demo.mymodule.com/'));
     $fields->push(new TextField('SvnURL', 'SVN repository - allowing you to checkout trunk or latest version - e.g. http://svn.mymodule.com/svn/trunk/'));
     $fields->push(new TextField('GitURL', 'GIT repository - e.g. https://github.com/my-github-username/silverstripe-my-module'));
     $fields->push(new TextField('OtherURL', 'Link to other repository or download URL - e.g. http://www.mymodule.com/downloads/'));
     $fields->push(new CheckboxSetField('EcommerceProductTags', 'Tags', EcommerceProductTag::get()->map()->toArray()));
     $member = Member::currentUser();
     if ($member->inGroup("ADMIN")) {
         $fields->push(new CheckboxSetField('Authors', 'Author(s)', Member::get()->exclude("Email", "")->map("ID", "Email")->toArray()));
         $fields->push(new DropdownField('ParentID', 'Move to', ProductGroup::get()->map()->toArray()));
         $fields->push(new CheckboxField('ShowInMenus', 'Show in menus (unticking both boxes here will hide the module)'));
         $fields->push(new CheckboxField('ShowInSearch', 'Show in search (unticking both boxes here will hide the module)'));
     } else {
         $fields->push(new HiddenField('ShowInMenus', '', 0));
         $fields->push(new HiddenField('ShowInSearch', '', 0));
         $fields->push(new HiddenField('ParentID', '', $controller->dataRecord->ID));
         if ($moduleProduct) {
             $moduleProduct->ParentID = $controller->dataRecord->ID;
             $moduleProduct->ShowInSearch = 0;
             $moduleProduct->ShowInMenus = 0;
         }
     }
     if ($moduleProduct && $moduleProduct->canEdit()) {
         if ($authors = $moduleProduct->Authors()) {
             $authorsIDArray = $authors->map("ID", "ID")->toArray();
             $authorsIDArray[0] = 0;
             $fields->push($this->ManyManyComplexTableFieldAuthorsField($controller, $authorsIDArray));
             //$controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = ""
         }
     }
     $actions = new FieldList(new FormAction("submit", "submit"));
     $validator = new AddingModuleProduct_RequiredFields($moduleProductID, array('Code', 'Name', 'ParentID', 'MainURL'));
     parent::__construct($controller, $name, $fields, $actions, $validator);
     if ($moduleProduct) {
         $this->loadDataFrom($moduleProduct);
     }
     return $this;
 }