public function testZeroPrice() { Config::inst()->update('ProductCategory', 'must_have_price', true); $products = $this->products->ProductsShowable(); $this->assertNotNull($products, "Products exist in category"); // hdtv not in the list, since it doesn't have a base-price set $this->assertDOSEquals(array(array('URLSegment' => 'socks'), array('URLSegment' => 't-shirt'), array('URLSegment' => 'beach-ball')), $products); $this->socks->BasePrice = ''; $this->socks->write(); $products = $this->products->ProductsShowable(); $this->assertDOSEquals(array(array('URLSegment' => 't-shirt'), array('URLSegment' => 'beach-ball')), $products); }
public function testTiersWithPromotionalPricing() { $this->p2->PromoActive = true; $this->p2->PromoType = 'Percent'; $this->p2->PromoPercent = 0.5; $this->p2->write(); $this->p2->publish('Stage', 'Live'); $price = round(14.99 * 0.25, 2); $qty = 10; $tiers = $this->p2->getPrices(); $this->assertEquals(3, $tiers->count()); $this->assertEquals($price, $tiers->offsetGet(2)->Price); $this->assertEquals(7.5, $tiers->offsetGet(2)->OriginalPrice); ShoppingCart::singleton()->add($this->p2, $qty); ShoppingCart::curr()->calculate(); $this->assertEquals($price * $qty, ShoppingCart::curr()->SubTotal()); }
/** * 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>"); } }
private function readCSVFile() { echo "start"; system("pwd"); // // $fp = fopen("../mysite/code/stock.csv","r"); // if($fp !== FALSE) { // // while(! feof($fp)) { // $data = fgetcsv($fp, 1000, ","); // print_r ($data); // } // } // fclose($fp); $row = 0; if (($handle = fopen("../mysite/code/stock.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $row++; array_unshift($data, "foo"); if ($row < 20000000000.0) { $p = new Product(); Debug::show($data); $p->OldID = $data[1]; $p->ShowDate = $data[2]; $p->IndateStamp = $data[3]; $p->SoldDate = $data[4]; $p->Brand = $data[5]; $p->Brand_sv = $data[6]; $p->Model = $data[7]; $p->Model_sv = $data[8]; $p->MadeYear = $data[9]; $p->Description = $data[10]; $p->YearText_sv = $data[11]; $p->YearText = $data[12]; $p->Description_sv = $data[13]; $p->SellPrice = $data[14]; $p->BuyPrice = $data[15]; $p->Comment = $data[16]; $p->SC_FK = $data[17]; #TODO if ($data[18] == 0) { $p->DealID = 44350; } if ($data[18] == 1) { $p->DealID = 44351; } if ($data[18] == 2) { $p->DealID = 44352; } if ($data[18] == 3) { $p->DealID = 44353; } $p->ShowInList = $data[19]; $p->InStock = $data[20]; $p->OnHold = $data[21]; $p->Sold = $data[22]; $p->Price = $data[23]; $p->Price_sv = $data[24]; $p->DatumKod = $data[25]; $p->OriginalKod = $data[26]; $p->SortKey = $data[27]; $p->ModelSortKey = $data[28]; $p->AllRow = $data[29]; $p->IsForSale = $data[30]; $p->OldCat = $data[31]; $p->SortDate = $data[32]; $p->NewOfDate = $data[33]; $p->NewSubCatFK = $data[34]; $p->write(); Debug::show($data); } } } }
function old_testNewProductGetsUniqueUrlSegment() { // Create a new product without a title $newProduct = new Product(); $newProduct->write(); $this->assertNotNull($newProduct->URLSegment); $existingProduct = DataObject::get_one('Product', sprintf('"Product"."URLSegment" = \'%s\' AND "Product"."ID" != %d', $newProduct->URLSegment, $newProduct->ID)); $this->assertFalse($existingProduct); }
public function requireDefaultRecords() { parent::requireDefaultRecords(); if (!DataObject::get_one('Product', "Name = 'Bronze'")) { $product = new Product(); $product->Name = 'Bronze'; $product->IsSubscription = 1; $product->Recurrence = 30; $product->Price = null; $product->TrialPrice = 0.01; $product->RecurringPrice = 27.0; $product->Credits = 10; $product->ISProductID = 42; $product->write(); } if (!DataObject::get_one('Product', "Name = 'Silver'")) { $product = new Product(); $product->Name = 'Silver'; $product->IsSubscription = 1; $product->Recurrence = 30; $product->Price = null; $product->TrialPrice = null; $product->RecurringPrice = 97.0; $product->Credits = 50; $product->ISProductID = 44; $product->write(); } if (!DataObject::get_one('Product', "Name = 'Gold'")) { $product = new Product(); $product->Name = 'Gold'; $product->IsSubscription = 1; $product->Recurrence = 30; $product->Price = null; $product->TrialPrice = null; $product->RecurringPrice = 197.0; $product->Credits = 200; $product->ISProductID = 48; $product->write(); } if (!DataObject::get_one('Product', "Name = 'Non-expiring Heatmaps-Bronze'")) { $product = new Product(); $product->Name = 'Non-expiring Heatmaps-Bronze'; $product->IsSubscription = 0; $product->Recurrence = 0; $product->Price = 49.0; $product->TrialPrice = null; $product->RecurringPrice = null; $product->Credits = 10; $product->ISProductID = 52; $product->write(); } if (!DataObject::get_one('Product', "Name = 'Non-expiring Heatmaps-Silver'")) { $product = new Product(); $product->Name = 'Non-expiring Heatmaps-Silver'; $product->IsSubscription = 0; $product->Recurrence = 0; $product->Price = 29.0; $product->TrialPrice = null; $product->RecurringPrice = null; $product->Credits = 10; $product->ISProductID = 54; $product->write(); } if (!DataObject::get_one('Product', "Name = 'Non-expiring Heatmaps-Gold'")) { $product = new Product(); $product->Name = 'Non-expiring Heatmaps-Gold'; $product->IsSubscription = 0; $product->Recurrence = 0; $product->Price = 19.0; $product->TrialPrice = null; $product->RecurringPrice = null; $product->Credits = 10; $product->ISProductID = 56; $product->write(); } if (!DataObject::get_one('Product', "Name = 'Prepaid, Non-expiring Heatmaps'")) { $product = new Product(); $product->Name = 'Prepaid, Non-expiring Heatmaps'; $product->IsSubscription = 0; $product->Recurrence = 0; $product->Price = 59.0; $product->TrialPrice = null; $product->RecurringPrice = null; $product->Credits = 10; $product->ISProductID = 40; $product->write(); } if (!DataObject::get_one('Product', "Name = 'Gift Heatmaps'")) { $product = new Product(); $product->Name = 'Gift Heatmaps'; $product->IsSubscription = 0; $product->Recurrence = 0; $product->Price = 0; $product->TrialPrice = null; $product->RecurringPrice = null; $product->Credits = 10; $product->write(); } }