Jump to content

Prestashop 1.6 core controller override


rosuandreimihai

Recommended Posts

I am trying to override a core controller protected function within PrestaShop 1.6.1. The controller is AddressController.php

The override controller looks like:
 

    class AddressController extends AddressControllerCore
    {
    
          
        /**
         * Assign template vars related to countries display
         */
        protected function assignCountries()
        {
            $this->id_country = (int)Tools::getCountry($this->_address);
            // Generate countries list
            if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
                $countries = Carrier::getDeliveredCountries($this->context->language->id, true, true);
            } else {
                $countries = Country::getCountries($this->context->language->id, true);
            }
    
            // @todo use helper
            $list = '';
            $product_by_country = Configuration::get('TOOLPRODUCTCOUNTRY_PRICE');
            foreach ($countries as $country) {
                if($product_by_country==1){
                    if (isset(Context::getContext()->cookie->productcountry_delivery)) {
                        $selected = ((int)$country['id_country'] === Context::getContext()->cookie->productcountry_delivery) ? ' selected="selected"' : '';
                    } else {
                        $selected = ((int)$country['id_country'] === $this->id_country) ? ' selected="selected"' : '';
                    }
                } else {
                    $selected = ((int)$country['id_country'] === $this->id_country) ? ' selected="selected"' : '';
                }
                $list .= '<option value="'.(int)$country['id_country'].'"'.$selected.'>'.htmlentities($country['name'], ENT_COMPAT, 'UTF-8').'</option>';
            }
    
            // Assign vars
            $this->context->smarty->assign(array(
                'countries_list' => $list,
                'countries' => $countries,
                'sl_country' => (int)$this->id_country,
            ));
        }
    
    }


Basically, I want to show in the checkout steps as default country another one than selected in PrestaShop BO for the `$('#id_country')` drop down list. The country desired is chosen before the checkout process and is stored as `productcountry_delivery`.
The problem is that this code is not taken into consideration by Prestashop, as if it wouldn't exist.
I have removed the class_index.php from cache folder to force a recompile but yet again with no succes

Could someone help me figure this out?

Thank you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...