liqiusheng / silverstripe-ecommerce

Automatically exported from code.google.com/p/silverstripe-ecommerce
0 stars 0 forks source link

Checkoutpage and content field problem #590

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
e-commerce version: 3.1 10/09/2013

SilverStripe version: 3.1 from github

You have hidden the 'Content' field from the checkout page in the CMS.
I need to show it on the CMS.
Making a extension for the checkout page not work, since the order of calls 
prevents re-display.
Can it be done in some way?

Regards,
Jose A.

Original issue reported on code.google.com by supp...@sendasoft.com on 10 Sep 2013 at 7:48

GoogleCodeExporter commented 8 years ago
The content field is moved to a different tab:

'Root.Messages.Messages.AlwaysVisible'

If you extend the CheckoutPage, then I am sure you can move it back to the main 
tab. 

The order of calls is:

$fields = parent::getCMSFields
$field->addStuff
return $fields
so that should work

Original comment by nfranc...@gmail.com on 11 Sep 2013 at 5:48

GoogleCodeExporter commented 8 years ago
The following not work:

class CheckoutPageExtension extends DataExtension {

    function updateCMSFields($fields) {
        $fields->addFieldsToTab("Root.Main", array(
             HTMLEditorField::create('Content', _t("CheckoutPageExtension.CONTENT","Content"))
            )
         );
    }
}

because the order in checkoutpage.php is:

    function getCMSFields() {
        $fields = parent::getCMSFields();   // <<<<<< Here is called $this->extend('updateCMSFields', $fields);
        $fields->removeFieldFromTab('Root.Messages.Messages.Actions',"ProceedToCheckoutLabel");
        $fields->removeFieldFromTab('Root.Messages.Messages.Actions',"ContinueShoppingLabel");
        $fields->removeFieldFromTab('Root.Messages.Messages.Actions',"ContinuePageID");
        $fields->removeFieldFromTab('Root.Messages.Messages.Actions',"LoadOrderLinkLabel");
        $fields->removeFieldFromTab('Root.Messages.Messages.Actions',"CurrentOrderLinkLabel");
        $fields->removeFieldFromTab('Root.Messages.Messages.Actions',"SaveOrderLinkLabel");
        $fields->removeFieldFromTab('Root.Messages.Messages.Actions',"DeleteOrderLinkLabel");
        $termsPageIDField = OptionalTreeDropdownField::create('TermsPageID', _t("CheckoutPage.TERMSANDCONDITIONSPAGE", "Terms and conditions page (if any - to remove, delete message below)"), 'SiteTree');
        $fields->addFieldToTab('Root.Process', $termsPageIDField);
        $fields->addFieldToTab('Root.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")));
        //The Content field has a slightly different meaning for the Checkout Page.
        $fields->removeFieldFromTab('Root.Main', "Content");
        $fields->addFieldToTab('Root.Messages.Messages.AlwaysVisible', $htmlEditorField = new HTMLEditorField('Content', _t("CheckoutPage.CONTENT", 'General note - always visible on the checkout page')));
        $htmlEditorField->setRows(3);
        if(OrderModifier_Descriptor::get()->count()) {
            $fields->addFieldToTab('Root.Messages.Messages.OrderExtras',$this->getOrderModifierDescriptionField());
        }
        if(CheckoutPage_StepDescription::get()->count()) {
            $fields->addFieldToTab('Root.Messages.Messages.CheckoutSteps',$this->getCheckoutStepDescriptionField());
        }
        return $fields;
    }

Is in $fields = parent::getCMSFields();  where is called 
$this->extend('updateCMSFields', $fields); (SiteTree.php)

After this, you do:

$fields->addFieldToTab('Root.Messages.Messages.AlwaysVisible', $htmlEditorField 
= new HTMLEditorField('Content', _t("CheckoutPage.CONTENT", 'General note - 
always visible on the checkout page')));

so my code does not work. :(

Do not understand why you put the 'Content' field in AlwaysVisible tab.
This loses the homogeneity of CMS.

Regards,
Jose A.

Original comment by supp...@sendasoft.com on 11 Sep 2013 at 10:25

GoogleCodeExporter commented 8 years ago
--- WHY IS IT THE WAY IT IS --------

It is this way, because the content field in the Checkout page takes on a 
slightly different meaning. It is basically a message that is shown on all 
pages and NOT the main content.  I guess it depends from install to install how 
to approach that, but on the whole I found it to be logical in this way. 

--- HOW CAN I CHANGE MY CONTENT FIELD -----------

What I would recommend is that you do it as follows:

class MyCheckoutPage extends CheckoutPage {

    private static $hide_ancestor = "CheckoutPage";

    function getCMSFields(){
        $fields = parent::getCMSFields();
        your magic goes here!
        return $fields;
    }

}

class MyCheckoutPage_Controller extends CheckoutPage_Controller

}

This is a much more efficient and easier way to change the checkout page.  Once 
oyu have installed this class then make sure to change the page type for your 
existing checkout page.

Original comment by nfranc...@gmail.com on 15 Sep 2013 at 9:42