/** * Handles the action. * Prepares the popup to load the pring preview * * @param GridField $gridField GridField to handle action for * @param array $recordIDs Record IDs to handle action for * @param array $data Data to handle action for * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 14.03.2013 */ public function handle(GridField $gridField, $recordIDs, $data) { $orders = new ArrayList(); foreach ($recordIDs as $orderID) { $order = SilvercartOrder::get_by_id('SilvercartOrder', $orderID); if ($order->exists()) { $order->markAsSeen(); $orders->push($order); } } $gridField->getConfig()->addComponent(new SilvercartGridFieldPopupTrigger(SilvercartPrint::getPrintURLForMany($orders))); return $gridField->FieldHolder(); }
/** * Executes the print controllers logic * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 19.04.2012 */ public function init() { parent::init(); $request = $this->getRequest(); $params = $request->allParams(); $dataObjectName = $params['DataObjectName']; $dataObjectID = $params['DataObjectID']; if (strpos($request->getVar('url'), 'silvercart-print-many') !== false) { $dataObjectIDs = explode('-', $dataObjectID); $output = SilvercartPrint::getPrintManyOutput($dataObjectName, $dataObjectIDs); if (!empty($output)) { print $output; exit; } $this->redirect(Director::baseURL()); } else { $dataObject = DataObject::get_by_id($dataObjectName, $dataObjectID); if ($dataObject && $dataObject->canView()) { if ($dataObject->hasMethod('printDataObject')) { print $dataObject->printDataObject(); } else { if (strpos($request->getVar('url'), 'silvercart-print-inline') === false) { $output = SilvercartPrint::getPrintOutput($dataObject); } else { $output = SilvercartPrint::getPrintInlineOutput($dataObject); } print $output; } exit; } else { $this->redirect(Director::baseURL()); } } }
/** * customize backend fields * * @return FieldList the form fields for the backend * * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <sdiel@πixeltricks.de> * @since 28.01.2013 */ public function getCMSFields() { $this->markAsSeen(); $fields = SilvercartDataObject::getCMSFields($this); //add the shipping/invloice address fields as own tab $address = singleton('SilvercartAddress'); $fields->findOrMakeTab('Root.ShippingAddressTab', $this->fieldLabel('ShippingAddressTab')); $fields->findOrMakeTab('Root.InvoiceAddressTab', $this->fieldLabel('InvoiceAddressTab')); $fields->addFieldToTab('Root.ShippingAddressTab', new LiteralField('sa__Preview', '<p>' . Convert::raw2xml($this->getShippingAddressSummary(true)) . '</p>')); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__TaxIdNumber', $address->fieldLabel('TaxIdNumber'), $this->SilvercartShippingAddress()->TaxIdNumber)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Company', $address->fieldLabel('Company'), $this->SilvercartShippingAddress()->Company)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__FirstName', $address->fieldLabel('FirstName'), $this->SilvercartShippingAddress()->FirstName)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Surname', $address->fieldLabel('Surname'), $this->SilvercartShippingAddress()->Surname)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Addition', $address->fieldLabel('Addition'), $this->SilvercartShippingAddress()->Addition)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Street', $address->fieldLabel('Street'), $this->SilvercartShippingAddress()->Street)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__StreetNumber', $address->fieldLabel('StreetNumber'), $this->SilvercartShippingAddress()->StreetNumber)); $fields->addFieldToTab('Root.ShippingAddressTab', new CheckboxField('sa__IsPackstation', $address->fieldLabel('IsPackstation'), $this->SilvercartShippingAddress()->IsPackstation)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__PostNumber', $address->fieldLabel('PostNumber'), $this->SilvercartShippingAddress()->PostNumber)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Packstation', $address->fieldLabel('PackstationPlain'), $this->SilvercartShippingAddress()->Packstation)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Postcode', $address->fieldLabel('Postcode'), $this->SilvercartShippingAddress()->Postcode)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__City', $address->fieldLabel('City'), $this->SilvercartShippingAddress()->City)); $fields->addFieldToTab('Root.ShippingAddressTab', new DropdownField('sa__Country', $address->fieldLabel('Country'), SilvercartCountry::get_active()->map()->toArray(), $this->SilvercartShippingAddress()->SilvercartCountry()->ID)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__PhoneAreaCode', $address->fieldLabel('PhoneAreaCode'), $this->SilvercartShippingAddress()->PhoneAreaCode)); $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Phone', $address->fieldLabel('Phone'), $this->SilvercartShippingAddress()->Phone)); $fields->addFieldToTab('Root.InvoiceAddressTab', new LiteralField('ia__Preview', '<p>' . Convert::raw2xml($this->getInvoiceAddressSummary(true)) . '</p>')); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__TaxIdNumber', $address->fieldLabel('TaxIdNumber'), $this->SilvercartInvoiceAddress()->TaxIdNumber)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Company', $address->fieldLabel('Company'), $this->SilvercartInvoiceAddress()->Company)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__FirstName', $address->fieldLabel('FirstName'), $this->SilvercartInvoiceAddress()->FirstName)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Surname', $address->fieldLabel('Surname'), $this->SilvercartInvoiceAddress()->Surname)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Addition', $address->fieldLabel('Addition'), $this->SilvercartInvoiceAddress()->Addition)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Street', $address->fieldLabel('Street'), $this->SilvercartInvoiceAddress()->Street)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__StreetNumber', $address->fieldLabel('StreetNumber'), $this->SilvercartInvoiceAddress()->StreetNumber)); $fields->addFieldToTab('Root.InvoiceAddressTab', new CheckboxField('ia__IsPackstation', $address->fieldLabel('IsPackstation'), $this->SilvercartInvoiceAddress()->IsPackstation)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__PostNumber', $address->fieldLabel('PostNumber'), $this->SilvercartInvoiceAddress()->PostNumber)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Packstation', $address->fieldLabel('PackstationPlain'), $this->SilvercartInvoiceAddress()->Packstation)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Postcode', $address->fieldLabel('Postcode'), $this->SilvercartInvoiceAddress()->Postcode)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__City', $address->fieldLabel('City'), $this->SilvercartInvoiceAddress()->City)); $fields->addFieldToTab('Root.InvoiceAddressTab', new DropdownField('ia__Country', $address->fieldLabel('Country'), SilvercartCountry::get_active()->map()->toArray(), $this->SilvercartInvoiceAddress()->SilvercartCountry()->ID)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__PhoneAreaCode', $address->fieldLabel('PhoneAreaCode'), $this->SilvercartInvoiceAddress()->PhoneAreaCode)); $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Phone', $address->fieldLabel('Phone'), $this->SilvercartInvoiceAddress()->Phone)); //add print preview $fields->findOrMakeTab('Root.PrintPreviewTab', $this->fieldLabel('PrintPreview')); $printPreviewField = new LiteralField('PrintPreviewField', sprintf('<iframe width="100%%" height="100%%" border="0" src="%s" class="print-preview"></iframe>', SilvercartPrint::getPrintInlineURL($this))); $fields->addFieldToTab('Root.PrintPreviewTab', $printPreviewField); return $fields; }