public function getContinueLink()
 {
     if ($cartPage = CartPage::get()->first()) {
         if ($cartPage->ContinuePageID) {
             return $cartPage->ContinuePage()->Link();
         }
     }
     $maincategory = ProductCategory::get()->sort(array("ParentID" => "ASC", "ID" => "ASC"))->first();
     if ($maincategory) {
         return $maincategory->Link();
     }
     return Director::baseURL();
 }
 /**
  * Returns the Link to the CartPage on this site
  * @return String (URLSegment)
  */
 public static function find_link()
 {
     $page = CartPage::get()->Filter(array("ClassName" => "CartPage"))->First();
     if ($page) {
         return $page->Link();
     } else {
         return CheckoutPage::find_link();
     }
 }
 /**
  * returns the link to view the Order
  * WHY NOT CHECKOUT PAGE: first we check for cart page.
  * @return CartPage | Null
  */
 function DisplayPage()
 {
     if ($this->MyStep() && $this->MyStep()->AlternativeDisplayPage()) {
         $page = $this->MyStep()->AlternativeDisplayPage();
     } elseif ($this->IsSubmitted()) {
         $page = OrderConfirmationPage::get()->First();
     } else {
         $page = CartPage::get()->Filter(array("ClassName" => 'CartPage'))->First();
         if (!$page) {
             $page = CheckoutPage::get()->First();
         }
     }
     return $page;
 }
 protected function addPages()
 {
     if ($checkoutPage = CheckoutPage::get()->First()) {
         $this->getPageDefinitions($checkoutPage);
         $this->definitions["Pages"]["CheckoutPage"] = "Page where customers finalise (checkout) their order. This page is required.<br />" . ($checkoutPage ? "<a href=\"/admin/pages/edit/show/" . $checkoutPage->ID . "/\">edit</a>" : "Create one in the <a href=\"/admin/pages/add/\">CMS</a>");
         $this->configs["Pages"]["CheckoutPage"] = $checkoutPage ? "view: <a href=\"" . $checkoutPage->Link() . "\">" . $checkoutPage->Title . "</a><br />" . $checkoutPage->configArray : " NOT CREATED!";
         $this->defaults["Pages"]["CheckoutPage"] = $checkoutPage ? $checkoutPage->defaultsArray : "[add page first to see defaults]";
         $this->databaseValues["Pages"]["CheckoutPage"] = true;
     }
     if ($orderConfirmationPage = OrderConfirmationPage::get()->First()) {
         $this->getPageDefinitions($orderConfirmationPage);
         $this->definitions["Pages"]["OrderConfirmationPage"] = "Page where customers review their order after it has been placed. This page is required.<br />" . ($orderConfirmationPage ? "<a href=\"/admin/pages/edit/show/" . $orderConfirmationPage->ID . "/\">edit</a>" : "Create one in the <a href=\"/admin/pages/add/\">CMS</a>");
         $this->configs["Pages"]["OrderConfirmationPage"] = $orderConfirmationPage ? "view: <a href=\"" . $orderConfirmationPage->Link() . "\">" . $orderConfirmationPage->Title . "</a><br />" . $orderConfirmationPage->configArray : " NOT CREATED!";
         $this->defaults["Pages"]["OrderConfirmationPage"] = $orderConfirmationPage ? $orderConfirmationPage->defaultsArray : "[add page first to see defaults]";
         $this->databaseValues["Pages"]["OrderConfirmationPage"] = true;
     }
     if ($accountPage = AccountPage::get()->First()) {
         $this->getPageDefinitions($accountPage);
         $this->definitions["Pages"]["AccountPage"] = "Page where customers can review their account. This page is required.<br />" . ($accountPage ? "<a href=\"/admin/pages/edit/show/" . $accountPage->ID . "/\">edit</a>" : "Create one in the <a href=\"/admin/pages/add/\">CMS</a>");
         $this->configs["Pages"]["AccountPage"] = $accountPage ? "view: <a href=\"" . $accountPage->Link() . "\">" . $accountPage->Title . "</a><br />" . $accountPage->configArray : " NOT CREATED!";
         $this->defaults["Pages"]["AccountPage"] = $accountPage ? $accountPage->defaultsArray : "[add page first to see defaults]";
         $this->databaseValues["Pages"]["AccountPage"] = true;
     }
     if ($cartPage = CartPage::get()->Filter(array("ClassName" => "CartPage"))->First()) {
         $this->getPageDefinitions($cartPage);
         $this->definitions["Pages"]["CartPage"] = "Page where customers review their cart while shopping. This page is optional.<br />" . ($cartPage ? "<a href=\"/admin/pages/edit/show/" . $cartPage->ID . "/\">edit</a>" : "Create one in the <a href=\"/admin/pages/add/\">CMS</a>");
         $this->configs["Pages"]["CartPage"] = $cartPage ? "view: <a href=\"" . $cartPage->Link() . "\">" . $cartPage->Title . "</a>, <a href=\"/admin/pages/edit/show/" . $cartPage->ID . "/\">edit</a><br />" . $cartPage->configArray : " NOT CREATED!";
         $this->defaults["Pages"]["CartPage"] = $cartPage ? $cartPage->defaultsArray : "[add page first to see defaults]";
         $this->defaults["Pages"]["CartPage"] = $cartPage ? $cartPage->defaultsArray : "[add page first to see defaults]";
         $this->databaseValues["Pages"]["CartPage"] = true;
     }
 }
    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();
    }