Inheritance: extends Page
Exemplo n.º 1
0
 /**
  * Automatically create a CheckoutPage if one is not found
  * on the site at the time the database is built (dev/build).
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('CartPage')) {
         $page = new CartPage();
         $page->Title = 'Cart';
         $page->Content = '';
         $page->URLSegment = 'cart';
         $page->ShowInMenus = 0;
         $page->writeToStage('Stage');
         $page->publish('Stage', 'Live');
         DB::alteration_message("Cart page 'Cart' created", 'created');
     }
 }
 /**
  * Returns the link or the Link to the OrderConfirmationPage page on this site
  * @return String (URLSegment)
  */
 public static function find_link()
 {
     if ($page = DataObject::get_one('OrderConfirmationPage', "\"ClassName\" = 'OrderConfirmationPage'")) {
         return $page->Link();
     } elseif ($page = DataObject::get_one('OrderConfirmationPage')) {
         return $page->Link();
     }
     return CartPage::find_link();
 }
 public function save($data, $form)
 {
     $selectionsfield = $form->Fields()->fieldByName("Selections");
     $totalqty = $selectionsfield->getSumQuantities();
     //add quantities of selected products
     $quantities = $selectionsfield->getQuantities();
     $selectables = $this->getProductMenu()->ProductSelections();
     foreach ($quantities as $id => $quantity) {
         $selection = $selectables->byID($id);
         if ($selection && ($buyable = $selection->Product())) {
             //restrict order item to given selection
             $filter = array("MenuProductSelectionID" => $selection->ID);
             $item = ShoppingCart::singleton()->setQuantity($buyable, $quantity, $filter);
             if (!$item) {
                 //TODO: errors
                 //ShoppingCart::singleton()->getMessage();
             }
         } else {
             //selection not found!
         }
     }
     return $this->redirect(CartPage::find_link());
 }
Exemplo n.º 4
0
 public function getCartLink()
 {
     return CartPage::find_link();
 }
Exemplo n.º 5
0
 /**
  * loads an order
  *
  */
 public function loadorder($request)
 {
     $this->cart->loadOrder(intval($request->param('ID')));
     $cartPageLink = CartPage::find_link();
     if ($cartPageLink) {
         Director::redirect($cartPageLink);
     } else {
         Director::redirect("/");
     }
 }
Exemplo n.º 6
0
 /**
  * This is used here and in VariationForm and AddProductForm
  * @param bool|string $status
  * @return bool
  */
 public static function direct($status = true)
 {
     if (Director::is_ajax()) {
         return $status;
     }
     if (self::config()->direct_to_cart_page && ($cartlink = CartPage::find_link())) {
         Controller::curr()->redirect($cartlink);
         return;
     } else {
         Controller::curr()->redirectBack();
         return;
     }
 }
 /**
  * work out the options for the user
  **/
 protected function workOutMessagesAndActions()
 {
     if (!$this->workedOutMessagesAndActions) {
         $this->actionLinks = new ArrayList(array());
         //what order are we viewing?
         $viewingRealCurrentOrder = $this->CurrentOrderIsInCart();
         $currentUserID = Member::currentUserID();
         //Continue Shopping
         if (isset($this->ContinueShoppingLabel) && $this->ContinueShoppingLabel) {
             if ($viewingRealCurrentOrder) {
                 if ($this->isCartPage()) {
                     $continueLink = $this->ContinueShoppingLink();
                     if ($continueLink) {
                         $this->actionLinks->push(new ArrayData(array("Title" => $this->ContinueShoppingLabel, "Link" => $continueLink)));
                     }
                 }
             }
         }
         //Proceed To CheckoutLabel
         if (isset($this->ProceedToCheckoutLabel) && $this->ProceedToCheckoutLabel) {
             if ($viewingRealCurrentOrder) {
                 if ($this->isCartPage()) {
                     $checkoutPageLink = CheckoutPage::find_link();
                     if ($checkoutPageLink && $this->currentOrder && $this->currentOrder->getTotalItems()) {
                         $this->actionLinks->push(new ArrayData(array("Title" => $this->ProceedToCheckoutLabel, "Link" => $checkoutPageLink)));
                     }
                 }
             }
         }
         //view account details
         if (isset($this->ShowAccountLabel) && $this->ShowAccountLabel) {
             if ($this->isOrderConfirmationPage() || $this->isCartPage()) {
                 if (AccountPage::find_link()) {
                     if ($currentUserID) {
                         $this->actionLinks->push(new ArrayData(array("Title" => $this->ShowAccountLabel, "Link" => AccountPage::find_link())));
                     }
                 }
             }
         }
         //go to current order
         if (isset($this->CurrentOrderLinkLabel) && $this->CurrentOrderLinkLabel) {
             if ($this->isCartPage()) {
                 if (!$viewingRealCurrentOrder) {
                     $this->actionLinks->push(new ArrayData(array("Title" => $this->CurrentOrderLinkLabel, "Link" => ShoppingCart::current_order()->Link())));
                 }
             }
         }
         //Save order - we assume only current ones can be saved.
         if (isset($this->SaveOrderLinkLabel) && $this->SaveOrderLinkLabel) {
             if ($viewingRealCurrentOrder) {
                 if ($currentUserID && $this->currentOrder->MemberID == $currentUserID) {
                     if ($this->isCartPage()) {
                         if ($this->currentOrder && $this->currentOrder->getTotalItems() && !$this->currentOrder->IsSubmitted()) {
                             $this->actionLinks->push(new ArrayData(array("Title" => $this->SaveOrderLinkLabel, "Link" => $this->Link("saveorder") . "/" . $this->currentOrder->ID . "/")));
                         }
                     }
                 }
             }
         }
         //load order
         if (isset($this->LoadOrderLinkLabel) && $this->LoadOrderLinkLabel) {
             if ($this->isCartPage() && $this->currentOrder) {
                 if (!$viewingRealCurrentOrder) {
                     $this->actionLinks->push(new ArrayData(array("Title" => $this->LoadOrderLinkLabel, "Link" => $this->Link("loadorder") . "/" . $this->currentOrder->ID . "/")));
                 }
             }
         }
         //delete order
         if (isset($this->DeleteOrderLinkLabel) && $this->DeleteOrderLinkLabel) {
             if ($this->isCartPage() && $this->currentOrder) {
                 if (!$viewingRealCurrentOrder) {
                     $this->actionLinks->push(new ArrayData(array("Title" => $this->DeleteOrderLinkLabel, "Link" => $this->Link("deleteorder") . "/" . $this->currentOrder->ID . "/")));
                 }
             }
         }
         //Start new order
         //Strictly speaking this is only part of the
         //OrderConfirmationPage but we put it here for simplicity's sake
         if (isset($this->StartNewOrderLinkLabel) && $this->StartNewOrderLinkLabel) {
             if ($this->isOrderConfirmationPage()) {
                 $this->actionLinks->push(new ArrayData(array("Title" => $this->StartNewOrderLinkLabel, "Link" => CartPage::new_order_link($this->currentOrder->ID))));
             }
         }
         //copy order
         //Strictly speaking this is only part of the
         //OrderConfirmationPage but we put it here for simplicity's sake
         if (isset($this->CopyOrderLinkLabel) && $this->CopyOrderLinkLabel) {
             if ($this->isOrderConfirmationPage() && $this->currentOrder->ID) {
                 $this->actionLinks->push(new ArrayData(array("Title" => $this->CopyOrderLinkLabel, "Link" => OrderConfirmationPage::copy_order_link($this->currentOrder->ID))));
             }
         }
         //actions from modifiers
         if ($this->isOrderConfirmationPage() && $this->currentOrder->ID) {
             $modifiers = $this->currentOrder->Modifiers();
             if ($modifiers->count()) {
                 foreach ($modifiers as $modifier) {
                     $array = $modifier->PostSubmitAction();
                     if (is_array($array) && count($array)) {
                         $this->actionLinks->push(new ArrayData($array));
                     }
                 }
             }
         }
         //log out
         //Strictly speaking this is only part of the
         //OrderConfirmationPage but we put it here for simplicity's sake
         if (Member::currentUser()) {
             if ($this->isOrderConfirmationPage()) {
                 $this->actionLinks->push(new ArrayData(array("Title" => _t("CartPage.LOGOUT", "log out"), "Link" => "/Security/logout/")));
             }
         }
         //no items
         if ($this->currentOrder) {
             if (!$this->currentOrder->getTotalItems()) {
                 $this->message = $this->NoItemsInOrderMessage;
             }
         } else {
             $this->message = $this->NonExistingOrderMessage;
         }
         $this->workedOutMessagesAndActions = true;
         //does nothing at present....
     }
 }
Exemplo n.º 8
0
 /**
  * Standard SS function
  * @return FieldSet
  **/
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeFieldFromTab('Root.Content.Messages.Messages.Actions', "ProceedToCheckoutLabel");
     $fields->removeFieldFromTab('Root.Content.Messages.Messages.Actions', "ContinueShoppingLabel");
     $fields->removeFieldFromTab('Root.Content.Messages.Messages.Actions', "ContinuePageID");
     $fields->removeFieldFromTab('Root.Content.Messages.Messages.Actions', "LoadOrderLinkLabel");
     $fields->removeFieldFromTab('Root.Content.Messages.Messages.Actions', "CurrentOrderLinkLabel");
     $fields->removeFieldFromTab('Root.Content.Messages.Messages.Actions', "SaveOrderLinkLabel");
     $fields->removeFieldFromTab('Root.Content.Messages.Messages.Actions', "DeleteOrderLinkLabel");
     $termsPageIDField = new OptionalTreeDropdownField('TermsPageID', _t("CheckoutPage.TERMSANDCONDITIONSPAGE", "Terms and conditions page (if any - to remove, delete message below)"), 'SiteTree');
     $fields->addFieldToTab('Root.Content.Process', $termsPageIDField);
     $fields->addFieldToTab('Root.Content.Process', new TextField('TermsAndConditionsMessage', _t("CheckoutPage.TERMSANDCONDITIONSMESSAGE", "Terms and conditions page message (shown if the user does not tick the box) - leave blank to allow customer to proceed without ticking the box")));
     $fields->addFieldToTab('Root.Content.Process', new CheckboxField('HasCheckoutSteps', _t("CheckoutPage.HASCHECKOUTSTEPS", "Checkout Process in Steps")));
     $fields->addFieldToTab('Root.Content.Main', new HtmlEditorField('InvitationToCompleteOrder', _t("CheckoutPage.INVITATIONTOCOMPLETEORDER", 'Invitation to complete order ... shown when the customer can do a regular checkout'), $row = 4));
     //The Content field has a slightly different meaning for the Checkout Page.
     $fields->removeFieldFromTab('Root.Content.Main', "Content");
     $fields->addFieldToTab('Root.Content.Messages.Messages.AlwaysVisible', new HtmlEditorField('Content', _t("CheckoutPage.CONTENT", 'General note - always visible on the checkout page'), 7, 7));
     if (DataObject::get_one("OrderModifier_Descriptor")) {
         $orderModifierDescriptionField = new ComplexTableField($this, _t("CheckoutPage.ORDERMODIFIERDESCRIPTMESSAGES", "Messages relating to order form extras (e.g. tax or shipping)"), "OrderModifier_Descriptor");
         $orderModifierDescriptionField->setRelationAutoSetting(false);
         $orderModifierDescriptionField->setTitle(_t("CheckoutPage.ORDERMODIFIERDESCRIPTMESSAGES", "Messages relating to order form extras (e.g. tax or shipping)"));
         $orderModifierDescriptionField->setPermissions(array("show", "edit"));
         $fields->addFieldToTab('Root.Content.Messages.Messages.OrderExtras', $orderModifierDescriptionField);
     }
     if (DataObject::get_one("CheckoutPage_StepDescription")) {
         $checkoutStepDescriptionField = new ComplexTableField($this, _t("CheckoutPage.CHECKOUTSTEPESCRIPTIONS", "Checkout Step Descriptions"), "CheckoutPage_StepDescription");
         $checkoutStepDescriptionField->setRelationAutoSetting(false);
         $checkoutStepDescriptionField->setTitle(_t("CheckoutPage.CHECKOUTSTEPESCRIPTIONS", "Checkout Step Descriptions"));
         $checkoutStepDescriptionField->setPermissions(array("show", "edit"));
         $fields->addFieldToTab('Root.Content.Messages.Messages.CheckoutSteps', $checkoutStepDescriptionField);
     }
     return $fields;
 }
Exemplo n.º 9
0
 /**
  * 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;
     }
 }
 /**
  * loads an order
  * @param SS_HTTPRequest
  * @return REDIRECT
  */
 public function loadorder(SS_HTTPRequest $request)
 {
     $this->cart->loadOrder(intval($request->param('ID')));
     $cartPageLink = CartPage::find_link();
     if ($cartPageLink) {
         return $this->redirect($cartPageLink);
     } else {
         return $this->redirect(Director::baseURL());
     }
 }
    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();
    }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $checkoutPage = CheckoutPage::get()->first();
     if (!$checkoutPage) {
         $checkoutPage = CheckoutPage::create();
         $checkoutPage->Title = "Checkout";
         $checkoutPage->MenuTitle = "Checkout";
         $checkoutPage->URLSegment = "checkout";
         $checkoutPage->writeToStage("Stage");
         $checkoutPage->publish("Stage", "Live");
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $checkoutPage = CheckoutPage::get()->first();
     if ($checkoutPage) {
         $orderConfirmationPage = OrderConfirmationPage::get()->first();
         if (!$orderConfirmationPage) {
             $orderConfirmationPage = OrderConfirmationPage::create();
             $orderConfirmationPage->Title = "Order Confirmation";
             $orderConfirmationPage->MenuTitle = "Order Confirmation";
             $orderConfirmationPage->URLSegment = "order-confirmation";
             $orderConfirmationPage->writeToStage("Stage");
             $orderConfirmationPage->publish("Stage", "Live");
         }
     }
 }