public function installOrderState()
 {
     if (Configuration::get('PS_OS_MYMOD_PAYMENT') < 1) {
         $order_state = new OrderState();
         $order_state->send_email = true;
         $order_state->module_name = $this->name;
         $order_state->invoice = false;
         $order_state->color = '#98c3ff';
         $order_state->logable = true;
         $order_state->shipped = false;
         $order_state->unremovable = false;
         $order_state->delivery = false;
         $order_state->hidden = false;
         $order_state->paid = false;
         $order_state->deleted = false;
         $order_state->name = array((int) Configuration::get('PS_LANG_DEFAULT') => pSQL($this->l('MyMod Payment - Awaiting confirmation')));
         $order_state->template = array();
         foreach (LanguageCore::getLanguages() as $l) {
             $order_state->template[$l['id_lang']] = 'mymodpayment';
         }
         // We copy the mails templates in mail directory
         foreach (LanguageCore::getLanguages() as $l) {
             $module_path = dirname(__FILE__) . '/views/templates/mails/' . $l['iso_code'] . '/';
             $application_path = dirname(__FILE__) . '/../../mails/' . $l['iso_code'] . '/';
             if (!copy($module_path . 'mymodpayment.txt', $application_path . 'mymodpayment.txt') || !copy($module_path . 'mymodpayment.html', $application_path . 'mymodpayment.html')) {
                 return false;
             }
         }
         if ($order_state->add()) {
             // We save the order State ID in Configuration database
             Configuration::updateValue('PS_OS_MYMOD_PAYMENT', $order_state->id);
             // We copy the module logo in order state logo directory
             copy(dirname(__FILE__) . '/logo.gif', dirname(__FILE__) . '/../../img/os/' . $order_state->id . '.gif');
             copy(dirname(__FILE__) . '/logo.gif', dirname(__FILE__) . '/../../img/tmp/order_state_mini_' . $order_state->id . '.gif');
         } else {
             return false;
         }
     }
     return true;
 }
 /**
  * Get all languages
  *
  * @return array
  */
 private function getLang()
 {
     return LanguageCore::getLanguages();
 }
Exemple #3
0
 public function getLanguages()
 {
     if (preg_match("/^1.3.*/", _PS_VERSION_)) {
         return Language::getLanguages();
     } else {
         return LanguageCore::getLanguages();
     }
 }
 /**
  * Returns Nosto accounts based on active shops.
  *
  * The result is formatted as follows:
  *
  * array(
  *   array(object(NostoAccount), int(id_shop), int(id_lang))
  * )
  *
  * @return NostoAccount[] the account data.
  */
 protected function getAccountData()
 {
     $data = array();
     /** @var NostoTaggingHelperAccount $account_helper */
     $account_helper = Nosto::helper('nosto_tagging/account');
     foreach ($this->getContextShops() as $shop) {
         $id_shop = (int) $shop['id_shop'];
         $id_shop_group = (int) $shop['id_shop_group'];
         foreach (LanguageCore::getLanguages(true, $id_shop) as $language) {
             $id_lang = (int) $language['id_lang'];
             $account = $account_helper->find($id_lang, $id_shop_group, $id_shop);
             if ($account === null || !$account->isConnectedToNosto()) {
                 continue;
             }
             $data[] = array($account, $id_shop, $id_lang);
         }
     }
     return $data;
 }
Exemple #5
0
 /**
  * Returns available languages. The first one is the employee default one.
  *
  * @param bool     $active   Select only active languages
  * @param int|bool $id_shop  Shop ID
  * @param bool     $ids_only If true, returns an array of language IDs
  *
  * @return array Languages
  */
 public function getLanguages($active = true, $id_shop = false, $ids_only = false)
 {
     $languages = \LanguageCore::getLanguages($active, $id_shop, $ids_only);
     $defaultLanguageFirst = $this->getContext()->employee->id_lang;
     usort($languages, function ($a, $b) use($defaultLanguageFirst) {
         if ($a['id_lang'] == $defaultLanguageFirst) {
             return -1;
             // $a is the default one.
         }
         if ($b['id_lang'] == $defaultLanguageFirst) {
             return 1;
             // $b is the default one.
         }
         return 0;
     });
     return $languages;
 }
 /**
  * Process customization collection
  *
  * @param object $product
  * @param array $data
  *
  * @return bool
  */
 public function processProductCustomization($product, $data)
 {
     //remove customization field langs
     foreach ($product->getCustomizationFieldIds() as $customizationFiled) {
         \Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customization_field_lang WHERE `id_customization_field` = ' . (int) $customizationFiled['id_customization_field']);
     }
     //remove customization for the product
     \Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'customization_field WHERE `id_product` = ' . (int) $product->id);
     //create new customizations
     $countFieldText = 0;
     $countFieldFile = 0;
     $productCustomizableValue = 0;
     $hasRequiredField = false;
     $shopList = \ShopCore::getContextListShopID();
     if ($data) {
         foreach ($data as $customization) {
             if ($customization['require']) {
                 $hasRequiredField = true;
             }
             //create label
             \Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'customization_field` (`id_product`, `type`, `required`)
                 VALUES (' . (int) $product->id . ', ' . (int) $customization['type'] . ', ' . ($customization['require'] ? 1 : 0) . ')');
             $id_customization_field = (int) \Db::getInstance()->Insert_ID();
             // Create multilingual label name
             $langValues = '';
             foreach (\LanguageCore::getLanguages() as $language) {
                 $name = $customization['label'][$language['id_lang']];
                 foreach ($shopList as $id_shop) {
                     $langValues .= '(' . (int) $id_customization_field . ', ' . (int) $language['id_lang'] . ', ' . $id_shop . ',\'' . $name . '\'), ';
                 }
             }
             \Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'customization_field_lang` (`id_customization_field`, `id_lang`, `id_shop`, `name`) VALUES ' . rtrim($langValues, ', '));
             if ($customization['type'] == 0) {
                 $countFieldFile++;
             } else {
                 $countFieldText++;
             }
         }
         $productCustomizableValue = $hasRequiredField ? 2 : 1;
     }
     //update product count fields labels
     \Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product` SET `customizable` = ' . $productCustomizableValue . ', `uploadable_files` = ' . (int) $countFieldFile . ', `text_fields` = ' . (int) $countFieldText . ' WHERE `id_product` = ' . (int) $product->id);
     //update product_shop count fields labels
     \ObjectModelCore::updateMultishopTable('product', array('customizable' => $productCustomizableValue, 'uploadable_files' => (int) $countFieldFile, 'text_fields' => (int) $countFieldText), 'a.id_product = ' . (int) $product->id);
     \ConfigurationCore::updateGlobalValue('PS_CUSTOMIZATION_FEATURE_ACTIVE', '1');
 }