/** * 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; }
/** * The same as the parent, except takes an associative array of defaults right at the end. */ function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "", $defaults = null) { parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $this->defaultValues = $defaults; }