Jump to:

2088 Posts in 1007 Topics by 455 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Remove/Hide Country Field in Checkout

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 1558 Views
  • t00thy
    Avatar
    Community Member
    31 Posts

    Remove/Hide Country Field in Checkout Link to this post

    Hi,

    I am trying remove country DropdownField from the Checkout page. But i am not successful.
    I think that the directing files are OrderForm and EcommerceRole.
    I try to modify these files, but when i do that I have a BlancPage.

    In EcommerceRole.php i try to remove these line:

    function getEcommerceFields() {
       $fields = new FieldSet(
          new HeaderField('Fakturační informace', 3),
          new TextField('FirstName', 'Jméno'),
          new TextField('Surname', 'Příjmení'),
          new TextField('HomePhone', 'Telefon'),
          new TextField('MobilePhone', 'Mobil'),
          new TextField('Address', 'Adresa'),
          new TextField('AddressLine2', 'PSČ'),
          new TextField('City', 'Město'),
          new TextField('Country', 'Country', Geoip::getCountryDropDown(), EcommerceRole::findCountry()) <- this line i remove
       );


    and also the comma on the line over.

    When i do this, the field for Country is not displayed, but when I try to push "Different Shipping address" I have only blanc page. And the same thing in OrderForm.php

    Have anybody an idea what to do? How I can remove Country Field?

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Remove/Hide Country Field in Checkout Link to this post

    First, if you're getting blank pages, you need to switch errors on. Developing SilverStripe without the error messages is like trying to play chess blindfolded.

    In EcommerceRole.php i try to remove these line:

    Second, don't change the distributed code unless there's no alternative. You can usually get the behaviour you want by subclassing or extending. e.g.

    <?php
    /**
    * MemberDecorator.php
    *
    * Customise the Member object for use with the ecommerce module
    *
    * Instructions:
    * Add the following line to _config.php
    * DataObject::add_extension('Member', 'MemberDecorator');
    *
    */

    class MemberDecorator extends DataObjectDecorator {

       // Customise the order form
       function augmentEcommerceFields($fields) {
          // Remove the country field
          $fields->removeByName('Country');
       }
    }

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Remove/Hide Country Field in Checkout Link to this post

    By the way, this is the line in EcommerceRole::getEcommerceFields() that tells you it can be extended, and how...

    $this->owner->extend('augmentEcommerceFields', $fields);

    EcommerceRole is adding the extension 'augmentEcommerceFields' to the Member class ($this->owner), so that's what we need to extend with...

    DataObject::add_extension('Member', 'MemberDecorator')

    Does that make sense?

  • t00thy
    Avatar
    Community Member
    31 Posts

    Re: Remove/Hide Country Field in Checkout Link to this post

    Yes, it does. But...

    I try what you say. I creat file name MemberDecorator.php and put the code from your first reply to it. Than save file in ecommerce/code/model. After it I insert the line

    DataObject::add_extension('Member', 'MemberDecorator');

    to config file in ecommerce. Run dev/build and try to open www.mysite.tld/checkout. I have blank page.
    I can't use dev mode, because it says to me that the Wrong parameter count for session_set_cookie_params()

    Maybe I'm doing something wrong. Of course i do.

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Remove/Hide Country Field in Checkout Link to this post

    It will help if you can get dev mode working. What version of php are you running?
    Is this the problem: http://www.electrictoolbox.com/silverstripe-php-version-requirements/

    There may be an alternative way to get error messages via logging.

    Add this to _config.php

    SS_Log::add_writer(new SS_LogFileWriter('silverstripe-log/silverstripe.log'), SS_Log::NOTICE);

    Create a silverstripe-log directory in the SilverStripe root i.e. beside saphire and silverstripe-cache.
    Grant write permissions on the silverstripe-log directory to the web process
    ...I think. if this doesn't work, create a silverstripe-log directory one level higher or inside saphire

    if still nothing appears in the log file, add this to Page::init()

    SS_Log::log( New Exception('Page::init() - hello'), SS_Log::NOTICE );

    I use logging a LOT for debugging as I don't have step-through debugging set up yet..

  • t00thy
    Avatar
    Community Member
    31 Posts

    Re: Remove/Hide Country Field in Checkout Link to this post

    Hi inCharge,

    i try it, but nothing work. Maybe I need to creat silverstripe-log folder up from root directory, but I haven't acces here.
    So, is posibility to set default country? I find some advice in the forum, but everything is for old version and it doesn't work.

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Remove/Hide Country Field in Checkout Link to this post

    Try creating the log directory in the saphire directory, and make sure it's writable.

    > but I haven't acces here.

    You're developing on a shared server? It's much easier to work on a local machine. I recommend setting up your laptop/desktop with a web server, php, mysql etc.

    > So, is posibility to set default country?

    I would think so, but now sure how, because I avoided the problem by removing country altogether

  • t00thy
    Avatar
    Community Member
    31 Posts

    Re: Remove/Hide Country Field in Checkout Link to this post

    Yes, i developing on a shared local server. It's because table in database have Upper first letter on Windows, but not on Linux.

    Ok... I will try tu unspell the Country.

    1558 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.