Esempio n. 1
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     if ($checkouts = CheckoutPage::get()) {
         $fields->addFieldToTab('Root.Links', DropdownField::create('CheckoutPageID', _t('CartPage.has_one_CheckoutPage', 'Checkout Page'), $checkouts->map("ID", "Title")));
     }
     $fields->addFieldToTab('Root.Links', TreeDropdownField::create('ContinuePageID', _t('CartPage.has_one_ContinuePage', 'Continue Shopping Page'), 'SiteTree'));
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     if ($checkouts = CheckoutPage::get()) {
         $fields->addFieldToTab('Root.Links', DropdownField::create('CheckoutPageID', _t('CartPage.has_one_CheckoutPage', 'Checkout Page'), $checkouts->map("ID", "Title")));
     }
     if ($pgroups = ProductCategory::get()) {
         $fields->addFieldToTab('Root.Links', DropdownField::create('ContinuePageID', _t('CartPage.has_one_ContinuePage', 'Continue Product Group Page'), $pgroups->map("ID", "Title")));
     }
     return $fields;
 }
 /**
  * @param string $template
  * @param string $subject
  *
  * @return Email
  */
 private function buildEmail($template, $subject)
 {
     $from = ShopConfig::config()->email_from ? ShopConfig::config()->email_from : Email::config()->admin_email;
     $to = $this->order->getLatestEmail();
     $checkoutpage = CheckoutPage::get()->first();
     $completemessage = $checkoutpage ? $checkoutpage->PurchaseComplete : '';
     $email = Email::create();
     $email->setTemplate($template);
     $email->setFrom($from);
     $email->setTo($to);
     $email->setSubject($subject);
     $email->populateTemplate(array('PurchaseCompleteMessage' => $completemessage, 'Order' => $this->order, 'BaseURL' => Director::absoluteBaseURL()));
     return $email;
 }
 /**
  * Send a mail of the order to the client (and another to the admin).
  *
  * @param $template - the class name of the email you wish to send
  * @param $subject - subject of the email
  * @param $copyToAdmin - true by default, whether it should send a copy to the admin
  */
 public function sendEmail($template, $subject, $copyToAdmin = true)
 {
     $from = ShopConfig::config()->email_from ? ShopConfig::config()->email_from : Email::config()->admin_email;
     $to = $this->order->getLatestEmail();
     $checkoutpage = CheckoutPage::get()->first();
     $completemessage = $checkoutpage ? $checkoutpage->PurchaseComplete : "";
     $email = new Email();
     $email->setTemplate($template);
     $email->setFrom($from);
     $email->setTo($to);
     $email->setSubject($subject);
     if ($copyToAdmin) {
         $email->setBcc(Email::config()->admin_email);
     }
     $email->populateTemplate(array('PurchaseCompleteMessage' => $completemessage, 'Order' => $this->order, 'BaseURL' => Director::absoluteBaseURL()));
     return $email->send();
 }
 /**
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function claim(SS_HTTPRequest $request)
 {
     /** @var Order $order */
     $order = Order::get()->byID($request->param('ID'));
     $hash = $request->param('OtherID');
     $realHash = FollowUpEmail::generate_hash($order);
     if (!$order || !$order->exists() || empty($hash) || $hash !== $realHash) {
         $this->httpError(404);
     }
     // Require a login if the order is attached to an account
     if ($order->MemberID && $order->MemberID != Member::currentUserID()) {
         return Security::permissionFailure($this->owner, _t('ShopEmail.NotYourOrder', 'You must log in to access this order.'));
     }
     // Otherwise if all is good, proceed to checkout
     ShoppingCart::singleton()->setCurrent($order);
     return $this->redirect(CheckoutPage::get()->first()->Link());
 }
 /**
  * returns the link to finalise the Order
  * @return String(URLSegment)
  */
 function CheckoutLink()
 {
     $page = CheckoutPage::get()->First();
     if ($page) {
         return $page->Link();
     } else {
         $page = ErrorPage::get()->Filter(array("ErrorCode" => '404'))->First();
         if ($page) {
             return $page->Link();
         }
     }
 }
 function checkoutAndModifierDetails()
 {
     $checkoutPage = CheckoutPage::get()->First();
     if (!$checkoutPage) {
         $task = new EcommerceTaskDefaultRecords();
         $task->run(null);
         $checkoutPage = CheckoutPage::get()->First();
         if (!$checkoutPage) {
             user_error("There is no checkout page available and it seems impossible to create one.");
         }
     }
     $steps = CheckoutPage_StepDescription::get();
     if ($steps->count()) {
         foreach ($steps as $key => $step) {
             $stepNumber = $key + 1;
             $fields = Config::inst()->get($step->ClassName, "db");
             $defaultsArray = $step->stat("defaults", true);
             $configArray = array();
             foreach ($fields as $fieldKey => $fieldType) {
                 if ($fields) {
                     $configArray[$fieldKey] = $step->{$fieldKey};
                     if (!isset($defaultsArray[$fieldKey])) {
                         $defaultsArray[$fieldKey] = "[default not set]";
                     }
                 }
             }
             $this->definitions["CheckoutPage_Controller"]["STEP_{$stepNumber}" . "_" . $step->getCode()] = $step->Description . "<br />see: <a href=\"/admin/pages/edit/show/" . $checkoutPage->ID . "/\">checkout page</a>.";
             $this->configs["CheckoutPage_Controller"]["STEP_{$stepNumber}" . "_" . $step->getCode()] = $configArray;
             $this->defaults["CheckoutPage_Controller"]["STEP_{$stepNumber}" . "_" . $step->getCode()] = $defaultsArray;
             $this->databaseValues["CheckoutPage_Controller"]["STEP_{$stepNumber}" . "_" . $step->getCode()] = true;
         }
     }
     $steps = OrderModifier_Descriptor::get();
     if ($steps->count()) {
         foreach ($steps as $step) {
             $fields = Config::inst()->get($step->ClassName, "db");
             $defaultsArray = $step->stat("defaults", true);
             $configArray = array();
             foreach ($fields as $fieldKey => $fieldType) {
                 if ($fields) {
                     $configArray[$fieldKey] = $step->{$fieldKey};
                     if (!isset($defaultsArray[$fieldKey])) {
                         $defaultsArray[$fieldKey] = "[default not set]";
                     }
                 }
             }
             $this->definitions["CheckoutPage_Controller"]["OrderModifier_Descriptor_" . $step->ModifierClassName] = $step->Description . "<br />see: <a href=\"/admin/pages/edit/show/" . $checkoutPage->ID . "/\">checkout page</a>.";
             $this->configs["CheckoutPage_Controller"]["OrderModifier_Descriptor_" . $step->ModifierClassName] = $configArray;
             $this->defaults["CheckoutPage_Controller"]["OrderModifier_Descriptor_" . $step->ModifierClassName] = $defaultsArray;
             $this->databaseValues["CheckoutPage_Controller"]["OrderModifier_Descriptor_" . $step->ModifierClassName] = true;
         }
     }
 }
 function doAddNewPriceForm($data, $form)
 {
     $amount = $this->parseFloat($data["Amount"]);
     if ($this->MinimumAmount && $amount < $this->MinimumAmount) {
         $form->sessionMessage(_t("AnyPriceProductPage.ERRORINFORMTOOLOW", "Please enter a higher amount."), "bad");
         $this->redirectBack();
         return;
     } elseif ($this->MaximumAmount && $amount > $this->MaximumAmount) {
         $form->sessionMessage(_t("AnyPriceProductPage.ERRORINFORMTOOHIGH", "Please enter a lower amount."), "bad");
         $this->redirectBack();
         return;
     }
     Session::clear("AnyPriceProductPageAmount");
     $obj = AnyPriceProductPage_ProductVariation::get()->filter(array("ProductID" => $this->ID, "Price" => $amount))->First();
     //create new one if needed
     if (!$obj) {
         Currency::setCurrencySymbol(EcommercePayment::site_currency());
         $titleDescriptor = new Currency("titleDescriptor");
         $titleDescriptor->setValue($amount);
         $obj = new AnyPriceProductPage_ProductVariation();
         $obj->Title = _t("AnyPriceProductPage.PAYMENTFOR", "Payment for: ") . $titleDescriptor->Nice();
         $obj->Price = $amount;
         $obj->AllowPurchase = true;
         $obj->ProductID = $this->ID;
         $obj->write("Stage");
         // line below does not work - suspected bug in framework Versioning System
         //$componentSet->add($obj);
     }
     //check if we have one now
     if (!$obj) {
         $obj = AnyPriceProductPage_ProductVariation::get()->filter(array("ProductID" => $this->ID, "Price" => $amount))->First();
     }
     if ($obj) {
         $shoppingCart = ShoppingCart::singleton();
         $shoppingCart->addBuyable($obj);
     } else {
         $form->sessionMessage(_t("AnyPriceProductPage.ERROROTHER", "Sorry, we could not add our entry."), "bad");
         $this->redirectBack();
         return;
     }
     $checkoutPage = CheckoutPage::get()->First();
     if ($checkoutPage) {
         $this->redirect($checkoutPage->Link());
     }
     return;
 }
 /**
  * Ensures member unique id stays unique and other basic stuff...
  * @param array $data = Form Data
  * @return Boolean
  */
 function php($data)
 {
     $valid = parent::php($data);
     $checkoutPage = CheckoutPage::get()->First();
     if ($checkoutPage && $checkoutPage->TermsAndConditionsMessage) {
         if (isset($data["ReadTermsAndConditions"])) {
             if (!$data["ReadTermsAndConditions"]) {
                 $this->validationError("ReadTermsAndConditions", $checkoutPage->TermsAndConditionsMessage, "required");
                 $valid = false;
             }
         }
     }
     $order = ShoppingCart::current_order();
     if (!$order) {
         $this->validationError("Order", _t("OrderForm.ORDERNOTFOUND", "There was an error in processing your order, please try again or contact the administrator."), "required");
         $valid = false;
     }
     $billingAddress = BillingAddress::get()->byID($order->BillingAddressID);
     if (!$billingAddress) {
         $this->validationError("BillingAddress", _t("OrderForm.MUSTHAVEBILLINGADDRESS", "All orders must have a billing address, please go back and add your details."), "required");
         $valid = false;
     }
     return $valid;
 }
    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();
    }
 function addConfirmationPage_250()
 {
     $explanation = "\r\n\t\t\t<h1>250. Add Confirmation Page</h1>\r\n\t\t\t<p>Creates a checkout page and order confirmation page in case they do not exist.</p>\r\n\t\t";
     if ($this->retrieveInfoOnly) {
         return $explanation;
     } else {
         echo $explanation;
     }
     $checkoutPage = CheckoutPage::get()->First();
     if (!$checkoutPage) {
         $checkoutPage = new CheckoutPage();
         $this->DBAlterationMessageNow("Creating a CheckoutPage", "created");
     } else {
         $this->DBAlterationMessageNow("No need to create a CheckoutPage Page");
     }
     if ($checkoutPage) {
         $checkoutPage->HasCheckoutSteps = 1;
         $checkoutPage->writeToStage('Stage');
         $checkoutPage->publish('Stage', 'Live');
         $orderConfirmationPage = OrderConfirmationPage::get()->First();
         if ($orderConfirmationPage) {
             $this->DBAlterationMessageNow("No need to create an Order Confirmation Page");
         } else {
             $orderConfirmationPage = new OrderConfirmationPage();
             $orderConfirmationPage->ParentID = $checkoutPage->ID;
             $orderConfirmationPage->writeToStage('Stage');
             $orderConfirmationPage->publish('Stage', 'Live');
             $this->DBAlterationMessageNow("Creating an Order Confirmation Page", "created");
         }
     } else {
         $this->DBAlterationMessageNow("There is no CheckoutPage available", "deleted");
     }
     return 0;
 }
Esempio n. 12
0
 /**
  * Send a mail of the order to the client (and another to the admin).
  *
  * @param $emailClass - the class name of the email you wish to send
  * @param $copyToAdmin - true by default, whether it should send a copy to the admin
  */
 public function sendEmail($emailClass, $copyToAdmin = true)
 {
     $from = ShopConfig::config()->email_from ? ShopConfig::config()->email_from : Email::config()->admin_email;
     $to = $this->order->getLatestEmail();
     $subject = sprintf(_t("Order.EMAILSUBJECT", "Shop Sale Information #%d"), $this->order->Reference);
     $checkoutpage = CheckoutPage::get()->first();
     $completemessage = $checkoutpage ? $checkoutpage->PurchaseComplete : "";
     $email = new $emailClass();
     $email->setFrom($from);
     $email->setTo($to);
     $email->setSubject($subject);
     if ($copyToAdmin) {
         $email->setBcc(Email::config()->admin_email);
     }
     $email->populateTemplate(array('PurchaseCompleteMessage' => $completemessage, 'Order' => $this->order, 'BaseURL' => Director::absoluteBaseURL()));
     return $email->send();
 }
 function run($request)
 {
     $update = array();
     $orderStep = singleton("OrderStep");
     $orderStep->requireDefaultRecords();
     // ACCOUNT PAGE
     $accountPage = AccountPage::get()->First();
     if (!$accountPage) {
         $accountPage = new AccountPage();
         $accountPage->Title = 'Account';
         $accountPage->MenuTitle = 'Account';
         $accountPage->MetaTitle = 'Account';
         $accountPage->Content = '<p>This is the account page. It is used for shop users to login and change their member details if they have an account.</p>';
         $accountPage->URLSegment = 'account';
         $accountPage->ShowInMenus = 0;
         $accountPage->writeToStage('Stage');
         $accountPage->publish('Stage', 'Live');
         DB::alteration_message('Account page \'Account\' created', 'created');
     } else {
         DB::alteration_message('No need to create an account page, it already exists.');
     }
     //CHECKOUT PAGE
     //CHECKOUT PAGE
     $checkoutPage = CheckoutPage::get()->First();
     if (!$checkoutPage) {
         $checkoutPage = new CheckoutPage();
         $checkoutPage->Content = '<p>This is the checkout page. You can edit all the messages in the Content Management System.</p>';
         $checkoutPage->Title = 'Checkout';
         $checkoutPage->TermsAndConditionsMessage = 'You must agree with the terms and conditions to proceed. ';
         $checkoutPage->MetaTitle = 'Checkout';
         $checkoutPage->MenuTitle = 'Checkout';
         $checkoutPage->URLSegment = 'checkout';
         $update[] = 'Checkout page \'Checkout\' created';
         $checkoutPage->ShowInMenus = 0;
         DB::alteration_message('new checkout page created.', 'created');
     } else {
         DB::alteration_message('No need to create an checkout page, it already exists.');
     }
     if ($checkoutPage) {
         if ($checkoutPage->TermsPageID == 0 && ($termsPage = Page::get()->Filter(array("URLSegment" => "terms-and-conditions"))->First())) {
             $checkoutPage->TermsPageID = $termsPage->ID;
             DB::alteration_message('terms and conditions page linked.', "created");
         } else {
             DB::alteration_message('No terms and conditions page linked.');
         }
         $checkoutPage->writeToStage('Stage');
         $checkoutPage->publish('Stage', 'Live');
         DB::alteration_message('Checkout page saved');
         $orderConfirmationPage = OrderConfirmationPage::get()->First();
         if ($orderConfirmationPage) {
             DB::alteration_message('No need to create an Order Confirmation Page. It already exists.');
         } else {
             $orderConfirmationPage = new OrderConfirmationPage();
             $orderConfirmationPage->ParentID = $checkoutPage->ID;
             $orderConfirmationPage->Title = 'Order confirmation';
             $orderConfirmationPage->MenuTitle = 'Order confirmation';
             $orderConfirmationPage->MetaTitle = 'Order confirmation';
             $orderConfirmationPage->Content = '<p>This is the order confirmation page. It is used to confirm orders after they have been placed in the checkout page.</p>';
             $orderConfirmationPage->URLSegment = 'order-confirmation';
             $orderConfirmationPage->ShowInMenus = 0;
             $orderConfirmationPage->writeToStage('Stage');
             $orderConfirmationPage->publish('Stage', 'Live');
             DB::alteration_message('Order Confirmation created', 'created');
         }
     }
     $update = array();
     $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config();
     if ($ecommerceConfig) {
         if (!$ecommerceConfig->ReceiptEmail) {
             $ecommerceConfig->ReceiptEmail = Email::config()->admin_email;
             if (!$ecommerceConfig->ReceiptEmail) {
                 user_error("you must set an AdminEmail (Email::setAdminEmail)", E_USER_NOTICE);
             }
             $update[] = "created default entry for ReceiptEmail";
         }
         if (!$ecommerceConfig->NumberOfProductsPerPage) {
             $ecommerceConfig->NumberOfProductsPerPage = 12;
             $update[] = "created default entry for NumberOfProductsPerPage";
         }
         if (count($update)) {
             $ecommerceConfig->write();
             DB::alteration_message($ecommerceConfig->ClassName . " created/updated: " . implode(" --- ", $update), 'created');
         }
     }
 }
 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");
         }
     }
 }