Пример #1
0
 /**
  * @param $plugin
  *
  * @throws ShopgateLibraryException
  */
 public function __construct($plugin)
 {
     parent::__construct($plugin);
     /** @var CartCore $cart */
     $cart = new Cart();
     $cart->id_lang = $this->getPlugin()->getLanguageId();
     $cart->id_currency = $this->getPlugin()->getContext()->currency->id;
     $cart->recyclable = 0;
     $cart->gift = 0;
     $this->getPlugin()->getContext()->cart = $cart;
     /**
      * check / create shopgate carrier
      */
     /** @var CarrierCore $sgCarrier */
     $sgCarrier = new Carrier(Configuration::get('SG_CARRIER_ID'));
     if (!$sgCarrier->id) {
         $shopgateShippingModel = new ShopgateShipping(new ShopGate());
         $shopgateShippingModel->createShopgateCarrier();
     }
     /**
      * check all needed table columns
      */
     $shopGate = new ShopGate();
     if (!$shopGate->updateTables()) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DATABASE_ERROR, sprintf('Cannot update shopgate_order_table'));
     }
 }
/**
 * @param ShopGate $module
 *
 * @return bool
 */
function upgrade_module_2_9_52($module)
{
    $shopgateCarrierId = Configuration::get('SG_CARRIER_ID');
    /**
     * set current shopgate carrier as deleted
     */
    if ($shopgateCarrierId) {
        /** @var CarrierCore $carrier */
        $carrier = new Carrier($shopgateCarrierId);
        $carrier->deleted = true;
        $carrier->save();
    }
    $shopgateShippingModel = new ShopgateShipping($module);
    $shopgateShippingModel->createShopgateCarrier();
    $module->updateTables();
    return true;
}
Пример #3
0
 /**
  * install
  *
  * @return bool
  */
 public function install()
 {
     /**
      * delete shopgate config
      */
     Configuration::deleteByName(ShopgateConfigPrestashop::DEFAULT_CONFIG_NAME);
     /**
      * hooks
      */
     $registerHooks = array('header', 'adminOrder', 'updateOrderStatus', 'updateQuantity');
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         $registerHooks[] = 'displayMobileHeader';
         $registerHooks[] = 'actionUpdateQuantity';
     }
     /**
      * enable debug
      */
     ShopgateLogger::getInstance()->enableDebug();
     /**
      * set default settings
      */
     $this->configurations = ShopgateSettings::getDefaultSettings();
     /**
      * check parent install
      */
     ShopGate::log('INSTALLATION - calling parent::install()', ShopgateLogger::LOGTYPE_DEBUG);
     $result = parent::install();
     if (!$result) {
         ShopGate::log('parent::install() failed; return value: ' . var_export($result, true), ShopgateLogger::LOGTYPE_ERROR);
         return false;
     }
     /**
      * check installed php extensions
      */
     $missingExtensions = ShopgateHelper::checkLoadedExtensions(array('curl'));
     if (count($missingExtensions) > 0) {
         foreach ($missingExtensions as $missingExtension) {
             ShopGate::log(sprintf('Installation failed. %s is not installed or loaded.', $missingExtension), ShopgateLogger::LOGTYPE_ERROR);
         }
         return false;
     }
     /**
      * register hooks
      */
     $this->registerHooks($registerHooks);
     /**
      * install tables
      */
     if (!$this->installTables()) {
         return false;
     }
     /**
      * update tables
      */
     if (!$this->updateTables()) {
         return false;
     }
     /**
      * install shopgate carrier
      */
     $this->shopgateShippingModel->createShopgateCarrier();
     /**
      * order states
      */
     ShopGate::log('INSTALLATION - adding order states', ShopgateLogger::LOGTYPE_DEBUG);
     $this->addOrderState('PS_OS_SHOPGATE', $this->l('Shipping blocked (Shopgate)'));
     /**
      * save default configuration
      */
     ShopGate::log('INSTALLATION - setting config values', ShopgateLogger::LOGTYPE_DEBUG);
     $this->configurations['SG_LANGUAGE_ID'] = Configuration::get('PS_LANG_DEFAULT');
     foreach ($this->configurations as $name => $value) {
         if (!Configuration::updateValue($name, $value)) {
             ShopGate::log(sprintf('installation failed: unable to save configuration setting "%s" with value "%s"', var_export($name, true), var_export($value, true)), ShopgateLogger::LOGTYPE_ERROR);
             return false;
         }
     }
     /** @todo register plugin */
     ShopGate::log('INSTALLATION - installation was successful', ShopgateLogger::LOGTYPE_DEBUG);
     return true;
 }