コード例 #1
0
 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.');
     }
 }
コード例 #2
0
 /**
  * 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');
     }
 }
コード例 #3
0
 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');
         }
     }
 }