예제 #1
0
 /**
  * @param ShopgatePluginPrestashop $module
  * @return array
  */
 public static function getShopgateSettings($module)
 {
     $result = array();
     /**
      * customer groups
      */
     $result['customer_groups'] = ShopgateSettings::getCustomerGroups($module);
     /**
      * product tax
      */
     $result['tax']['product_tax_classes'] = ShopgateSettings::getProductTaxClasses($module);
     /**
      * customer tax classes
      */
     $result['tax']['customer_tax_classes'] = array(array('key' => 'default', 'is_default' => true));
     if (version_compare(_PS_VERSION_, '1.4.0.4', '<=')) {
         $result['tax']['tax_rates'] = ShopgateSettings::getTaxRatesOldVersions($module);
         $result['tax']['tax_rules'] = ShopgateSettings::getTaxRulesOldVersions($result['tax']['product_tax_classes'], $result['tax']['customer_tax_classes'], $result['tax']['tax_rates']);
     } else {
         $result['tax']['tax_rates'] = ShopgateSettings::getTaxRates($module);
         $result['tax']['tax_rules'] = ShopgateSettings::getTaxRules($module);
     }
     /**
      * allowed_shipping_countries and allowed_address_countries
      */
     $result['allowed_shipping_countries'] = array();
     $result['allowed_address_countries'] = array();
     $countryResultItems = array();
     $addressResultItems = array();
     foreach (ShopgateShipping::getDeliveryCountries($module->context->language->id, true, true) as $country) {
         if (is_array($country['states'])) {
             $resultStates = array();
             foreach ($country['states'] as $state) {
                 $resultStates[] = $state['iso_code'];
             }
         } else {
             $resultStates = array(ShopgateShipping::CARRIER_CODE_ALL);
         }
         $countryResultItems[$country['iso_code']] = $resultStates;
     }
     foreach ($countryResultItems as $country => $state) {
         $item = array('country' => $country, 'state' => $state);
         $result['allowed_shipping_countries'][] = $item;
     }
     foreach (Country::getCountries($module->context->language->id, true) as $country) {
         if (is_array($country['states'])) {
             $resultStates = array();
             foreach ($country['states'] as $state) {
                 $resultStates[] = $state['iso_code'];
             }
         } else {
             $resultStates = array(ShopgateShipping::CARRIER_CODE_ALL);
         }
         $addressResultItems[$country['iso_code']] = $resultStates;
     }
     foreach ($addressResultItems as $country => $state) {
         $item = array('country' => $country, 'state' => $state);
         $result['allowed_address_countries'][] = $item;
     }
     return $result;
 }
예제 #2
0
 /**
  * @return string
  */
 public function prepareTaxClass()
 {
     $taxRulesGroups = TaxRulesGroupCore::getTaxRulesGroups(true);
     $idTaxRulesGroup = (int) Product::getIdTaxRulesGroupByIdProduct($this->currentProduct->id, null);
     foreach ($taxRulesGroups as $taxRulesGroup) {
         if ($taxRulesGroup['id_tax_rules_group'] == $idTaxRulesGroup) {
             $tax = ShopgateSettings::getTaxItemByTaxRuleGroupId($idTaxRulesGroup);
             $taxClassName = '';
             if (is_array($tax->name) && !empty($tax->name[$this->getPlugin()->getLanguageId()])) {
                 $taxClassName = $tax->name[$this->getPlugin()->getLanguageId()];
             } else {
                 if (is_array($tax->name)) {
                     // fallback: just in case for older Prestashop versions
                     $taxClassName = reset($tax->name);
                 }
             }
             return $taxClassName;
         }
     }
     return '';
 }
예제 #3
0
 /**
  * Returns an array of certain settings of the shop. (Currently mainly tax settings.)     *
  * @see http://developer.shopgate.com/plugin_api/system_information/get_settings
  *
  * @return array(
  *                    <ul>
  *                        <li>'tax' => Contains the tax settings as follows:
  *                            <ul>
  *                                <li>'tax_classes_products' => A list of product tax class identifiers.</li>
  *                                <li>'tax_classes_customers' => A list of customer tax classes.</li>
  *                                <li>'tax_rates' => A list of tax rates.</li>
  *                                <li>'tax_rules' => A list of tax rule containers.</li>
  *                            </ul>
  *                        </li>
  *                    </ul>)
  * @throws ShopgateLibraryException on invalid log in data or hard errors like database failure.
  */
 public function getSettings()
 {
     return ShopgateSettings::getShopgateSettings($this);
 }
예제 #4
0
 /**
  * @return mixed
  */
 public function getContent()
 {
     include_once dirname(__FILE__) . '/backward_compatibility/backward.php';
     /** @var ShopgateConfigPrestashop $shopgateConfig */
     $shopgateConfig = new ShopgateConfigPrestashop();
     /** @var mixed $errorMessage */
     $errorMessage = false;
     /** @var LanguageCore $lang */
     $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
     /**
      * prepare carrier list
      */
     $allCarriers = defined('Carrier::ALL_CARRIERS') ? Carrier::ALL_CARRIERS : ShopgateShipping::SG_ALL_CARRIERS;
     $carrierList = Carrier::getCarriers($lang->id, true, false, false, null, $allCarriers);
     $carrierIdColumn = version_compare(_PS_VERSION_, '1.5.0.1', '>=') ? 'id_reference' : 'id_carrier';
     $nativeCarriers = $carrierList;
     /**
      * save on submit
      */
     if (Tools::isSubmit('saveConfigurations')) {
         $configs = Tools::getValue('configs', array());
         /**
          * set and store configs
          */
         foreach ($configs as $key => $value) {
             $shopgateConfig->setByKey($key, $value);
         }
         try {
             foreach ($shopgateConfig->initFolders() as $key => $value) {
                 $shopgateConfig->setByKey($key, $value);
             }
             $shopgateConfig->store();
         } catch (ShopgateLibraryException $e) {
             $errorMessage = $e->getAdditionalInformation();
         }
         $settings = array();
         foreach ($carrierList as $carrier) {
             $settings['SG_MOBILE_CARRIER'][(int) $carrier[$carrierIdColumn]] = 0;
         }
         foreach (Tools::getValue('settings', array()) as $key => $value) {
             if (!empty($value) && is_array($value) && !empty($settings[$key])) {
                 $settings[$key] = $value + $settings[$key];
             } else {
                 $settings[$key] = $value;
             }
         }
         /**
          * store settings
          */
         foreach ($settings as $key => $value) {
             if (in_array($key, ShopgateSettings::getSettingKeys())) {
                 if (is_array($value)) {
                     $value = base64_encode(serialize($value));
                 }
                 Configuration::updateValue($key, htmlentities($value, ENT_QUOTES));
             }
         }
     }
     $languages = array();
     foreach (Language::getLanguages() as $l) {
         $languages[$l['iso_code']] = $l['name'];
     }
     $orderStates = array();
     foreach (OrderState::getOrderStates($lang->id) as $key => $orderState) {
         $orderStates[$orderState['id_order_state']] = $orderState['name'];
     }
     $newOrderStateMapping = array();
     foreach ($this->shopgatePaymentModel->getPaymentMethods() as $key => $method) {
         $newOrderStateMapping[ShopgateSettings::getOrderStateKey($key)] = $method;
     }
     /**
      * prepare css
      */
     if (version_compare(_PS_VERSION_, '1.6', '<')) {
         $configCss = 'configurations_without_bs.css';
     } else {
         $configCss = 'configurations.css';
     }
     $mobileCarrierUse = unserialize(base64_decode(Configuration::get('SG_MOBILE_CARRIER')));
     $resultNativeCarriers = array();
     foreach ($nativeCarriers as $nativeCarrier) {
         if ($nativeCarrier['external_module_name'] != ShopgateShipping::DEFAULT_EXTERNAL_MODULE_CARRIER_NAME) {
             $nativeCarrier['identifier'] = $nativeCarrier[$carrierIdColumn];
             if (!is_array($mobileCarrierUse)) {
                 $nativeCarrier['mobile_used'] = 1;
             } else {
                 if (!empty($mobileCarrierUse[$nativeCarrier['identifier']])) {
                     $nativeCarrier['mobile_used'] = 1;
                 } else {
                     $nativeCarrier['mobile_used'] = 0;
                 }
             }
             $resultNativeCarriers[] = $nativeCarrier;
         }
     }
     $shopgateCarrier = new Carrier(Configuration::get('SG_CARRIER_ID'), $lang->id);
     $carrierList[] = array('name' => $shopgateCarrier->name, 'id_carrier' => $shopgateCarrier->id);
     /**
      * price types
      */
     $priceTypes = array(Shopgate_Model_Catalog_Price::DEFAULT_PRICE_TYPE_NET => $this->l('Net'), Shopgate_Model_Catalog_Price::DEFAULT_PRICE_TYPE_GROSS => $this->l('Gross'));
     /**
      * fill smarty params
      */
     $this->context->smarty->assign('error_message', $errorMessage);
     $this->context->smarty->assign('settings', Configuration::getMultiple(ShopgateSettings::getSettingKeys()));
     $this->context->smarty->assign('configs', $shopgateConfig->toArray());
     $this->context->smarty->assign('mod_dir', $this->_path);
     $this->context->smarty->assign('video_url', ShopgateHelper::getVideoLink($this->context));
     $this->context->smarty->assign('offer_url', ShopgateHelper::getOfferLink($this->context));
     $this->context->smarty->assign('api_url', ShopgateHelper::getApiUrl($this->context));
     $this->context->smarty->assign('currencies', Currency::getCurrencies());
     $this->context->smarty->assign('servers', ShopgateHelper::getEnvironments($this));
     $this->context->smarty->assign('shipping_service_list', $this->shopgateShippingModel->getShippingServiceList());
     $this->context->smarty->assign('product_export_descriptions', ShopgateSettings::getProductExportDescriptionsArray($this));
     $this->context->smarty->assign('languages', $languages);
     $this->context->smarty->assign('carrier_list', $carrierList);
     $this->context->smarty->assign('shippingModel', $this->shopgateShippingModel);
     $this->context->smarty->assign('configCss', $configCss);
     $this->context->smarty->assign('product_export_price_type', $priceTypes);
     $this->context->smarty->assign('native_carriers', $resultNativeCarriers);
     $this->context->smarty->assign('order_state_mapping', $orderStates);
     return $this->display(__FILE__, 'views/templates/admin/configurations.tpl');
 }