/**
  * STANDARD SILVERSTRIPE STUFF
  * broken up into submitted and not (yet) submitted
  **/
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $currentMember = Member::currentUser();
     if (!$this->exists() || !$this->StatusID) {
         $firstStep = OrderStep::get()->First();
         $this->StatusID = $firstStep->ID;
         $this->write();
     }
     $submitted = $this->IsSubmitted() ? true : false;
     if ($submitted) {
         //TODO
         //Having trouble here, as when you submit the form (for example, a payment confirmation)
         //as the step moves forward, meaning the fields generated are incorrect, causing an error
         //"I can't handle sub-URLs of a Form object." generated by the RequestHandler.
         //Therefore we need to try reload the page so that it will be requesting the correct URL to generate the correct fields for the current step
         //Or something similar.
         //why not check if the URL == $this->CMSEditLink()
         //and only tryToFinaliseOrder if this is true....
         if ($_SERVER['REQUEST_URI'] == $this->CMSEditLink() || $_SERVER['REQUEST_URI'] == $this->CMSEditLink("edit")) {
             $this->tryToFinaliseOrder();
         }
     } else {
         $this->init(true);
         $this->calculateOrderAttributes(true);
         Session::set("EcommerceOrderGETCMSHack", $this->ID);
     }
     if ($submitted) {
         $this->fieldsAndTabsToBeRemoved[] = "CustomerOrderNote";
     } else {
         $this->fieldsAndTabsToBeRemoved[] = "Emails";
     }
     foreach ($this->fieldsAndTabsToBeRemoved as $field) {
         $fields->removeByName($field);
     }
     $fields->insertAfter(new Tab("Next", new HeaderField("MyOrderStepHeader", _t("Order.CURRENTSTATUS", "1. Current Status")), $this->OrderStepField(), new HeaderField("OrderStepNextStepHeader", _t("Order.ACTIONNEXTSTEP", "2. Action Next Step")), new LiteralField("OrderStepNextStepHeaderExtra", "<p><strong>" . _t("Order.NEEDTOREFRESH", "If you have made any changes to the order then you will have to refresh or save this record to see up-to-date options here.") . "</strong></p>"), new HeaderField("ActionNextStepManually", _t("Order.MANUALSTATUSCHANGE", "3. Move Order Along")), new LiteralField("StatusIDExplanation", "<h3><a href=\"" . $this->CMSEditLink() . "\" class=\"action ss-ui-button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only\"><span class=\"ui-button-text\">" . _t("Order.REFRESH", "refresh now") . "</span></a></h3>")), "Main");
     $this->MyStep()->addOrderStepFields($fields, $this);
     if ($submitted) {
         //Config::nest();
         //Config::inst()->update('SSViewer', 'theme_enabled', true);
         //$htmlSummary = $this->renderWith("Order");
         //Config::unnest();
         $fields->addFieldToTab('Root.Main', new LiteralField('MainDetails', '<iframe src="' . $this->PrintLink() . '" width="100%" height="500"></iframe>'));
         $fields->insertAfter(new Tab("Emails", $this->getEmailsTableField()), "Next");
         $fields->addFieldToTab('Root.Payments', $this->getPaymentsField());
         $fields->addFieldToTab("Root.Payments", new ReadOnlyField("TotalPaid", _t("Order.TOTALPAID", "Total Paid"), $this->getTotalPaid()));
         $fields->addFieldToTab("Root.Payments", new ReadOnlyField("TotalOutstanding", _t("Order.TOTALOUTSTANDING", "Total Outstanding"), $this->getTotalOutstanding()));
         if ($this->canPay()) {
             $link = EcommercePaymentController::make_payment_link($this->ID);
             $js = "window.open(this.href, 'payment', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=800,height=600'); return false;";
             $header = _t("Order.MAKEPAYMENT", "make payment");
             $label = _t("Order.MAKEADDITIONALPAYMENTNOW", "make additional payment now");
             $linkHTML = '<a href="' . $link . '" onclick="' . $js . '">' . $label . '</a>';
             $fields->addFieldToTab("Root.Payments", new HeaderField("MakeAdditionalPaymentHeader", $header, 3));
             $fields->addFieldToTab("Root.Payments", new LiteralField("MakeAdditionalPayment", $linkHTML));
         }
         //member
         $member = $this->Member();
         if ($member && $member->exists()) {
             $fields->addFieldToTab('Root.Account', new LiteralField("MemberDetails", $member->getEcommerceFieldsForCMS()));
         } else {
             $fields->addFieldToTab('Root.Customer', new LiteralField("MemberDetails", "<p>" . _t("Order.NO_ACCOUNT", "There is no --- account --- associated with this order") . "</p>"));
         }
         $cancelledField = $fields->dataFieldByName("CancelledByID");
         $fields->removeByName("CancelledByID");
         $fields->addFieldToTab("Root.Cancellation", DropdownField::create("CancelledByID", $cancelledField->Title(), array(0 => "--- " . _t("Order.NOT_CANCELLED", "Not Cancelled") . " ---", $currentMember->ID => _t("Order.CANCELLED_BY", "Cancelled By") . " " . $currentMember->getName())));
         $fields->addFieldToTab('Root.Log', $this->getOrderStatusLogsTableField_Archived());
         $submissionLog = $this->SubmissionLog();
         if ($submissionLog) {
             $fields->addFieldToTab('Root.Log', new ReadonlyField('SequentialOrderNumber', _t("Order.SEQUENTIALORDERNUMBER", "Sequential order number for submitted orders (e.g. 1,2,3,4,5...)"), $submissionLog->SequentialOrderNumber));
         }
     } else {
         $linkText = _t("Order.LOAD_THIS_ORDER", "load this order");
         $message = _t("Order.NOSUBMITTEDYET", "No details are shown here as this order has not been submitted yet. You can {link} to submit it... NOTE: For this, you will be logged in as the customer and logged out as (shop)admin .", array("link" => '<a href="' . $this->RetrieveLink() . '" data-popup="true">' . $linkText . '</a>'));
         $fields->addFieldToTab('Root.Main', new LiteralField('MainDetails', '<p>' . $message . '</p>'));
         $fields->addFieldToTab('Root.Items', $this->getOrderItemsField());
         $fields->addFieldToTab('Root.Extras', $this->getModifierTableField());
         //MEMBER STUFF
         $specialOptionsArray = array();
         if ($this->MemberID) {
             $specialOptionsArray[0] = _t("Order.SELECTCUSTOMER", "--- Remover Customer ---");
             $specialOptionsArray[$this->MemberID] = _t("Order.LEAVEWITHCURRENTCUSTOMER", "- Leave with current customer: ") . $this->Member()->getTitle();
         } elseif ($currentMember) {
             $specialOptionsArray[0] = _t("Order.SELECTCUSTOMER", "--- Select Customers ---");
             $currentMemberID = $currentMember->ID;
             $specialOptionsArray[$currentMemberID] = _t("Order.ASSIGNTHISORDERTOME", "- Assign this order to me: ") . $currentMember->getTitle();
         }
         //MEMBER FIELD!!!!!!!
         $memberArray = $specialOptionsArray + EcommerceRole::list_of_customers();
         $fields->addFieldToTab("Root.Main", new DropdownField("MemberID", _t("Order.SELECTCUSTOMER", "Select Customer"), $memberArray), "CustomerOrderNote");
         $memberArray = null;
     }
     $fields->addFieldToTab('Root.Addresses', new HeaderField("BillingAddressHeader", _t("Order.BILLINGADDRESS", "Billing Address")));
     $fields->addFieldToTab('Root.Addresses', $this->getBillingAddressField());
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $fields->addFieldToTab('Root.Addresses', new HeaderField("ShippingAddressHeader", _t("Order.SHIPPINGADDRESS", "Shipping Address")));
         $fields->addFieldToTab('Root.Addresses', new CheckboxField("UseShippingAddress", _t("Order.USESEPERATEADDRESS", "Use separate shipping address?")));
         if ($this->UseShippingAddress) {
             $fields->addFieldToTab('Root.Addresses', $this->getShippingAddressField());
         }
     }
     $currencies = EcommerceCurrency::get_list();
     if ($currencies && $currencies->count()) {
         $currencies = $currencies->map()->toArray();
         $fields->addFieldToTab("Root.Currency", new ReadOnlyField("ExchangeRate ", _t("Order.EXCHANGERATE", "Exchange Rate"), $this->ExchangeRate));
         $fields->addFieldToTab("Root.Currency", new DropdownField("CurrencyUsedID", _t("Order.CurrencyUsed", "Currency Used"), $currencies));
     } else {
         $fields->addFieldToTab("Root.Currency", new LiteralField("CurrencyInfo", "<p>You can not change currencies, because no currencies have been created.</p>"));
         $fields->replaceField("CurrencyUsedID", $fields->dataFieldByName("CurrencyUsedID")->performReadonlyTransformation());
     }
     $fields->addFieldToTab("Root.Log", new ReadonlyField("Created", _t("Root.CREATED", "Created")));
     $fields->addFieldToTab("Root.Log", new ReadonlyField("LastEdited", _t("Root.LASTEDITED", "Last saved")));
     $this->extend('updateSettingsFields', $fields);
     return $fields;
 }
Beispiel #2
0
    /**
     * STANDARD SILVERSTRIPE STUFF
     * broken up into submitted and not (yet) submitted
     **/
    function getCMSFields()
    {
        $fields = parent::getCMSFields();
        if ($this->exists()) {
            $submitted = $this->IsSubmitted() ? true : false;
            if ($submitted) {
                $this->tryToFinaliseOrder();
            } else {
                $this->init(true);
            }
            if ($submitted) {
                $this->fieldsAndTabsToBeRemoved[] = "CustomerOrderNote";
            } else {
                $this->fieldsAndTabsToBeRemoved[] = "Emails";
            }
            foreach ($this->fieldsAndTabsToBeRemoved as $field) {
                $fields->removeByName($field);
            }
            //$fields->insertBefore(new LiteralField('Title',"<h2>".$this->Title()."</h2>"),'Root');
            $fields->insertAfter(new Tab("Next", new HeaderField("MyOrderStepHeader", _t("Order.CURRENTSTATUS", "Current Status")), $this->OrderStepField(), new HeaderField("OrderStepNextStepHeader", _t("Order.ACTIONNEXTSTEP", "Action Next Step"), 1), new LiteralField("OrderStepNextStepHeaderExtra", "<p><strong>" . _t("Order.NEEDTOREFRESH", "If you have made any changes to the order then you will have to refresh or save this record to see up-to-date options here.") . "</strong></p>"), new LiteralField("ActionNextStepManually", "<br /><br /><br /><h3>" . _t("Order.MANUALSTATUSCHANGE", "Manual Status Change") . "</h3>")), "Main");
            if ($submitted) {
                $htmlSummary = $this->renderWith("Order");
                $fields->addFieldToTab('Root.Main', new LiteralField('MainDetails', $htmlSummary));
                $paymentsTable = new HasManyComplexTableField($this, "Payments", "Payment", null, null, "\"OrderID\" = " . $this->ID . "", "\"Created\" ASC", null);
                $paymentsTable->setPageSize(20);
                $paymentsTable->addSummary(_t("Order.TOTAL", "Total"), array("Total" => array("sum", "Currency->Nice")));
                if ($this->IsPaid()) {
                    $paymentsTable->setPermissions(array('export', 'show'));
                } else {
                    $paymentsTable->setPermissions(array('edit', 'delete', 'export', 'show'));
                }
                $paymentsTable->setShowPagination(false);
                $paymentsTable->setRelationAutoSetting(true);
                $fields->addFieldToTab('Root.Payments', $paymentsTable);
                $fields->addFieldToTab("Root.Payments", new ReadOnlyField("TotalPaid", _t("Order.TOTALPAID", "Total Paid"), $this->getTotalPaid()));
                $fields->addFieldToTab("Root.Payments", new ReadOnlyField("TotalOutstanding", _t("Order.TOTALOUTSTANDING", "Total Outstanding"), $this->getTotalOutstanding()));
                if ($this->canPay()) {
                    $link = EcommercePaymentController::make_payment_link($this->ID);
                    $js = "window.open(this.href, 'payment', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=800,height=600'); return false;";
                    $header = _t("Order.MAKEPAYMENT", "make payment");
                    $label = _t("Order.MAKEADDITIONALPAYMENTNOW", "make additional payment now");
                    $linkHTML = '<a href="' . $link . '" onclick="' . $js . '">' . $label . '</a>';
                    $fields->addFieldToTab("Root.Payments", new HeaderField("MakeAdditionalPaymentHeader", $header, 3));
                    $fields->addFieldToTab("Root.Payments", new LiteralField("MakeAdditionalPayment", $linkHTML));
                }
                //member
                if ($member = $this->Member()) {
                    $fields->addFieldToTab('Root.Customer', new LiteralField("MemberDetails", $member->getEcommerceFieldsForCMSAsString()));
                }
                $cancelledField = $fields->dataFieldByName("CancelledByID");
                $fields->removeByName("CancelledByID");
                $fields->addFieldToTab("Root.Cancellation", $cancelledField);
                $oldOrderStatusLogs = new ComplexTableField($this, $name = "OldOrderStatusLogs", $sourceClass = "OrderStatusLog", $fieldList = null, $detailFormFields = null, $sourceFilter = "\"OrderID\" = " . $this->ID, $sourceSort = "", $sourceJoin = "");
                $oldOrderStatusLogs->setPermissions(array("show"));
                $fields->addFieldToTab('Root.Log', $oldOrderStatusLogs);
                $submissionLog = $this->SubmissionLog();
                if ($submissionLog) {
                    $fields->addFieldToTab('Root.Log', new ReadonlyField('SequentialOrderNumber', _t("Order.SEQUENTIALORDERNUMBER", "Sequential order number for submitted orders (e.g. 1,2,3,4,5...)"), $submissionLog->SequentialOrderNumber));
                }
            } else {
                $msg = sprintf(_t("Order.NOSUBMITTEDYET", 'No details are shown here as this order has not been submitted yet.
						You can %1$s to submit it... NOTE: For this, you will be logged in as the customer and logged out as (shop)admin .'), '<a href="' . $this->RetrieveLink() . '" target="_blank">load this order</a>');
                $fields->addFieldToTab('Root.Main', new LiteralField('MainDetails', '<p>' . $msg . '</p>'));
                $orderItemsTable = new HasManyComplexTableField($this, "Attributes", "OrderItem", null, null, "\"OrderID\" = " . $this->ID . "", "\"Created\" ASC", null);
                $orderItemsTable->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd', "show"));
                $orderItemsTable->setShowPagination(false);
                $orderItemsTable->setRelationAutoSetting(true);
                $orderItemsTable->addSummary(_t("Order.TOTAL", "Total"), array("Total" => array("sum", "Currency->Nice")));
                $fields->addFieldToTab('Root.Items', $orderItemsTable);
                $modifierTable = new ComplexTableField($this, "OrderModifiers", "OrderModifier", null, null, "\"OrderID\" = " . $this->ID . "", "\"Created\" ASC", null);
                $modifierTable->setPermissions(array('edit', 'delete', 'export', 'show'));
                $modifierTable->setPageSize(100);
                $fields->addFieldToTab('Root.Extras', $modifierTable);
                //MEMBER STUFF
                $specialOptionsArray = array();
                if ($this->MemberID) {
                    $specialOptionsArray[0] = _t("Order.SELECTCUSTOMER", "-- - Remover Customer -- -");
                    $specialOptionsArray[$this->MemberID] = _t("Order.LEAVEWITHCURRENTCUSTOMER", "- Leave with current customer: ") . $this->Member()->getTitle();
                } elseif ($currentMember = Member::currentUser()) {
                    $specialOptionsArray[0] = _t("Order.SELECTCUSTOMER", "-- - Select Customers -- -");
                    $currentMemberID = $currentMember->ID;
                    $specialOptionsArray[$currentMemberID] = _t("Order.ASSIGNTHISORDERTOME", "- Assign this order to me: ") . $currentMember->getTitle();
                }
                //MEMBER FIELD!!!!!!!
                $memberArray = $specialOptionsArray + EcommerceRole::list_of_customers();
                $fields->addFieldToTab("Root.Main", new DropdownField("MemberID", _t("Order.SELECTCUSTOMER", "Select Cutomer"), $memberArray), "CustomerOrderNote");
                $memberArray = null;
            }
            $fields->addFieldToTab('Root.Addresses', new HeaderField("BillingAddressHeader", _t("Order.BILLINGADDRESS", "Billing Address")));
            $billingAddressObject = $this->CreateOrReturnExistingAddress("BillingAddress");
            $billingAddressField = new HasOneComplexTableField($this, "BillingAddress", "BillingAddress", null, null, "\"BillingAddress\".\"ID\" = " . $this->BillingAddressID, "\"Created\" ASC", null);
            if (!$this->BillingAddressID) {
                $billingAddressField->setPermissions(array('edit', 'add', 'inlineadd', 'show'));
            } elseif ($this->canEdit()) {
                $billingAddressField->setPermissions(array('edit', 'show'));
            } else {
                $billingAddressField->setPermissions(array('export', 'show'));
            }
            //DO NOT ADD!
            //$billingAddressField->setRelationAutoSetting(true);
            //$billingAddress->setShowPagination(false);
            $fields->addFieldToTab('Root.Addresses', $billingAddressField);
            if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
                $fields->addFieldToTab('Root.Addresses', new HeaderField("ShippingAddressHeader", _t("Order.SHIPPINGADDRESS", "Shipping Address")));
                $fields->addFieldToTab('Root.Addresses', new CheckboxField("UseShippingAddress", _t("Order.USESEPERATEADDRESS", "Use seperate shipping address?")));
                if ($this->UseShippingAddress) {
                    $shippinggAddressObject = $this->CreateOrReturnExistingAddress("ShippingAddress");
                    $shippingAddressField = new HasOneComplexTableField($this, "ShippingAddress", "ShippingAddress", null, null, "\"ShippingAddress\".\"ID\" = " . $this->ShippingAddressID, "\"Created\" ASC", null);
                    if (!$this->ShippingAddressID) {
                        $shippingAddressField->setPermissions(array('edit', 'add', 'inlineadd', 'show'));
                    } elseif ($this->canEdit()) {
                        $shippingAddressField->setPermissions(array('edit', 'show'));
                    } else {
                        $shippingAddressField->setPermissions(array('export', 'show'));
                    }
                    //DO NOT ADD
                    //$shippingAddress->setRelationAutoSetting(true);
                    $fields->addFieldToTab('Root.Addresses', $shippingAddressField);
                }
            }
            $this->MyStep()->addOrderStepFields($fields, $this);
            $fields->addFieldToTab("Root.Next", new LiteralField("StatusIDExplanation", _t("Order.STATUSIDEXPLANATION", "You can not manually update the status of an order.")));
            $fields->addFieldToTab("Root.Currency", new NumericField("ExchangeRate ", _t("Order.EXCHANGERATE", "Exchange Rate")));
            $fields->addFieldToTab("Root.Currency", new DropdownField("CurrencyUsedID ", _t("Order.CurrencyUsed", "Currency Used"), DataObject::get("EcommerceCurrency"), EcommerceCurrency::default_currency_id()));
        } else {
            $fields->removeByName("Main");
            $firstStep = DataObject::get_one("OrderStep");
            $msg = _t("Order.VERYFIRSTSTEP", "The first step in creating an order is to save (<i>add</i>) it.");
            $fields->addFieldToTab("Root.Next", new LiteralField("VeryFirstStep", "<p>" . $msg . "</p>"));
            if ($firstStep) {
                $fields->addFieldToTab("Root.Next", new HiddenField("StatusID", $firstStep->ID, $firstStep->ID));
            }
        }
        $this->extend('updateCMSFields', $fields);
        return $fields;
    }
 static function set_url_segment($s)
 {
     self::$url_segment = $s;
 }