public function ajaxProcessFinishStep()
 {
     $return = array('has_error' => false);
     if (!$this->access('edit')) {
         $return = array('has_error' => true, $return['errors'][] = $this->trans('You do not have permission to use this wizard.', array(), 'Admin.Shipping.Notification'));
     } else {
         $this->validateForm(false);
         if ($id_carrier = Tools::getValue('id_carrier')) {
             $current_carrier = new Carrier((int) $id_carrier);
             // if update we duplicate current Carrier
             /** @var Carrier $new_carrier */
             $new_carrier = $current_carrier->duplicateObject();
             if (Validate::isLoadedObject($new_carrier)) {
                 // Set flag deteled to true for historization
                 $current_carrier->deleted = true;
                 $current_carrier->update();
                 // Fill the new carrier object
                 $this->copyFromPost($new_carrier, $this->table);
                 $new_carrier->position = $current_carrier->position;
                 $new_carrier->update();
                 $this->updateAssoShop((int) $new_carrier->id);
                 $this->duplicateLogo((int) $new_carrier->id, (int) $current_carrier->id);
                 $this->changeGroups((int) $new_carrier->id);
                 //Copy default carrier
                 if (Configuration::get('PS_CARRIER_DEFAULT') == $current_carrier->id) {
                     Configuration::updateValue('PS_CARRIER_DEFAULT', (int) $new_carrier->id);
                 }
                 // Call of hooks
                 Hook::exec('actionCarrierUpdate', array('id_carrier' => (int) $current_carrier->id, 'carrier' => $new_carrier));
                 $this->postImage($new_carrier->id);
                 $this->changeZones($new_carrier->id);
                 $new_carrier->setTaxRulesGroup((int) Tools::getValue('id_tax_rules_group'));
                 $carrier = $new_carrier;
             }
         } else {
             $carrier = new Carrier();
             $this->copyFromPost($carrier, $this->table);
             if (!$carrier->add()) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving this carrier.', array(), 'Admin.Shipping.Notification');
             }
         }
         if ($carrier->is_free) {
             //if carrier is free delete shipping cost
             $carrier->deleteDeliveryPrice('range_weight');
             $carrier->deleteDeliveryPrice('range_price');
         }
         if (Validate::isLoadedObject($carrier)) {
             if (!$this->changeGroups((int) $carrier->id)) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving carrier groups.', array(), 'Admin.Shipping.Notification');
             }
             if (!$this->changeZones((int) $carrier->id)) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving carrier zones.', array(), 'Admin.Shipping.Notification');
             }
             if (!$carrier->is_free) {
                 if (!$this->processRanges((int) $carrier->id)) {
                     $return['has_error'] = true;
                     $return['errors'][] = $this->trans('An error occurred while saving carrier ranges.', array(), 'Admin.Shipping.Notification');
                 }
             }
             if (Shop::isFeatureActive() && !$this->updateAssoShop((int) $carrier->id)) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving associations of shops.', array(), 'Admin.Shipping.Notification');
             }
             if (!$carrier->setTaxRulesGroup((int) Tools::getValue('id_tax_rules_group'))) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving the tax rules group.', array(), 'Admin.Shipping.Notification');
             }
             if (Tools::getValue('logo')) {
                 if (Tools::getValue('logo') == 'null' && file_exists(_PS_SHIP_IMG_DIR_ . $carrier->id . '.jpg')) {
                     unlink(_PS_SHIP_IMG_DIR_ . $carrier->id . '.jpg');
                 } else {
                     $logo = basename(Tools::getValue('logo'));
                     if (!file_exists(_PS_TMP_IMG_DIR_ . $logo) || !copy(_PS_TMP_IMG_DIR_ . $logo, _PS_SHIP_IMG_DIR_ . $carrier->id . '.jpg')) {
                         $return['has_error'] = true;
                         $return['errors'][] = $this->trans('An error occurred while saving carrier logo.', array(), 'Admin.Shipping.Notification');
                     }
                 }
             }
             $return['id_carrier'] = $carrier->id;
         }
     }
     die(json_encode($return));
 }