public function renderView()
 {
     // Build delete link
     $admin_delete_link = $this->context->link->getAdminLink('AdminMyModComments') . '&deletemymod_comment&id_mymod_comment=' . (int) $this->object->id;
     // Build admin product link
     $admin_product_link = $this->context->link->getAdminLink('AdminProducts') . '&updateproduct&id_product=' . (int) $this->object->id_product . '&key_tab=ModuleMymodcomments';
     // If author is known as a customer, build admin customer link
     $admin_customer_link = '';
     $customers = Customer::getCustomersByEmail($this->object->email);
     if (isset($customers[0]['id_customer'])) {
         $admin_customer_link = $this->context->link->getAdminLink('AdminCustomers') . '&viewcustomer&id_customer=' . (int) $customers[0]['id_customer'];
     }
     // Add delete shortcut button to toolbar
     $this->page_header_toolbar_btn['delete'] = array('href' => $admin_delete_link, 'desc' => $this->l('Delete it'), 'icon' => 'process-icon-delete', 'js' => "return confirm('" . $this->l('Are you sure you want to delete it ?') . "');");
     $this->object->loadProductName();
     $tpl = $this->context->smarty->createTemplate(dirname(__FILE__) . '/../../views/templates/admin/view.tpl');
     $tpl->assign('mymodcomment', $this->object);
     $tpl->assign('admin_product_link', $admin_product_link);
     $tpl->assign('admin_customer_link', $admin_customer_link);
     return $tpl->fetch();
 }
 protected function addressImportOne($info, $force_ids, $validateOnly = false)
 {
     AdminImportController::setDefaultValues($info);
     if ($force_ids && isset($info['id']) && (int) $info['id']) {
         $address = new Address((int) $info['id']);
     } else {
         if (array_key_exists('id', $info) && (int) $info['id'] && Address::addressExists((int) $info['id'])) {
             $address = new Address((int) $info['id']);
         } else {
             $address = new Address();
         }
     }
     AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address);
     if (isset($address->country) && is_numeric($address->country)) {
         if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
             $address->id_country = (int) $address->country;
         }
     } elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) {
         if ($id_country = Country::getIdByName(null, $address->country)) {
             $address->id_country = (int) $id_country;
         } else {
             $country = new Country();
             $country->active = 1;
             $country->name = AdminImportController::createMultiLangField($address->country);
             $country->id_zone = 0;
             // Default zone for country to create
             $country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2));
             // Default iso for country to create
             $country->contains_states = 0;
             // Default value for country to create
             $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
             if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $country->add()) {
                 $address->id_country = (int) $country->id;
             } else {
                 if (!$validateOnly) {
                     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
                     $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $country->name[$default_language_id]);
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     if (isset($address->state) && is_numeric($address->state)) {
         if (State::getNameById((int) $address->state)) {
             $address->id_state = (int) $address->state;
         }
     } elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) {
         if ($id_state = State::getIdByName($address->state)) {
             $address->id_state = (int) $id_state;
         } else {
             $state = new State();
             $state->active = 1;
             $state->name = $address->state;
             $state->id_country = isset($country->id) ? (int) $country->id : 0;
             $state->id_zone = 0;
             // Default zone for state to create
             $state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2));
             // Default iso for state to create
             $state->tax_behavior = 0;
             if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $state->add()) {
                 $address->id_state = (int) $state->id;
             } else {
                 if (!$validateOnly) {
                     $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $state->name);
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     if (isset($address->customer_email) && !empty($address->customer_email)) {
         if (Validate::isEmail($address->customer_email)) {
             // a customer could exists in different shop
             $customer_list = Customer::getCustomersByEmail($address->customer_email);
             if (count($customer_list) == 0) {
                 $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
             }
         } else {
             $this->errors[] = sprintf($this->trans('"%s" is not a valid email address.', array(), 'Admin.Parameters.Notification'), $address->customer_email);
             return;
         }
     } elseif (isset($address->id_customer) && !empty($address->id_customer)) {
         if (Customer::customerIdExistsStatic((int) $address->id_customer)) {
             $customer = new Customer((int) $address->id_customer);
             // a customer could exists in different shop
             $customer_list = Customer::getCustomersByEmail($customer->email);
             if (count($customer_list) == 0) {
                 $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer);
             }
         } else {
             $this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), $address->id_customer);
         }
     } else {
         $customer_list = array();
         $address->id_customer = 0;
     }
     if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) {
         $address->id_manufacturer = (int) $address->manufacturer;
     } elseif (isset($address->manufacturer) && is_string($address->manufacturer) && !empty($address->manufacturer)) {
         if ($manufacturerId = Manufacturer::getIdByName($address->manufacturer)) {
             $address->id_manufacturer = $manufacturerId;
         } else {
             $manufacturer = new Manufacturer();
             $manufacturer->name = $address->manufacturer;
             if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $manufacturer->add()) {
                 $address->id_manufacturer = (int) $manufacturer->id;
             } else {
                 if (!$validateOnly) {
                     $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     if (isset($address->supplier) && is_numeric($address->supplier) && Supplier::supplierExists((int) $address->supplier)) {
         $address->id_supplier = (int) $address->supplier;
     } elseif (isset($address->supplier) && is_string($address->supplier) && !empty($address->supplier)) {
         if ($supplierId = Supplier::getIdByName($address->supplier)) {
             $address->id_supplier = $supplierId;
         } else {
             $supplier = new Supplier();
             $supplier->name = $address->supplier;
             if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $supplier->add()) {
                 $address->id_supplier = (int) $supplier->id;
             } else {
                 if (!$validateOnly) {
                     $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null');
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     $res = false;
     if (($field_error = $address->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
         $address->force_id = (bool) $force_ids;
         if (isset($customer_list) && count($customer_list) > 0) {
             $filter_list = array();
             foreach ($customer_list as $customer) {
                 if (in_array($customer['id_customer'], $filter_list)) {
                     continue;
                 }
                 $filter_list[] = $customer['id_customer'];
                 $address->id_customer = $customer['id_customer'];
             }
         }
         if ($address->id && $address->addressExists($address->id)) {
             $res = $validateOnly || $address->update();
         }
         if (!$res) {
             $res = $validateOnly || $address->add();
         }
     }
     if (!$res) {
         if (!$validateOnly) {
             $this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
         }
         if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
             $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
         }
     }
 }
 public function addressImport()
 {
     $this->receiveTab();
     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
     $handle = $this->openCsvFile();
     AdminImportController::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8EncodeArray($line);
         }
         $info = AdminImportController::getMaskedRow($line);
         AdminImportController::setDefaultValues($info);
         $address = new Address();
         AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address);
         if (isset($address->country) && is_numeric($address->country)) {
             if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
                 $address->id_country = (int) $address->country;
             }
         } elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) {
             if ($id_country = Country::getIdByName(null, $address->country)) {
                 $address->id_country = (int) $id_country;
             } else {
                 $country = new Country();
                 $country->active = 1;
                 $country->name = AdminImportController::createMultiLangField($address->country);
                 $country->id_zone = 0;
                 // Default zone for country to create
                 $country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2));
                 // Default iso for country to create
                 $country->contains_states = 0;
                 // Default value for country to create
                 $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
                 if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $country->add()) {
                     $address->id_country = (int) $country->id;
                 } else {
                     $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $country->name[$default_language_id]);
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
         if (isset($address->state) && is_numeric($address->state)) {
             if (State::getNameById((int) $address->state)) {
                 $address->id_state = (int) $address->state;
             }
         } elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) {
             if ($id_state = State::getIdByName($address->state)) {
                 $address->id_state = (int) $id_state;
             } else {
                 $state = new State();
                 $state->active = 1;
                 $state->name = $address->state;
                 $state->id_country = isset($country->id) ? (int) $country->id : 0;
                 $state->id_zone = 0;
                 // Default zone for state to create
                 $state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2));
                 // Default iso for state to create
                 $state->tax_behavior = 0;
                 if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $state->add()) {
                     $address->id_state = (int) $state->id;
                 } else {
                     $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $state->name);
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
         if (isset($address->customer_email) && !empty($address->customer_email)) {
             if (Validate::isEmail($address->customer_email)) {
                 // a customer could exists in different shop
                 $customer_list = Customer::getCustomersByEmail($address->customer_email);
                 if (count($customer_list) == 0) {
                     $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
                 }
             } else {
                 $this->errors[] = sprintf(Tools::displayError('"%s" is not a valid email address.'), $address->customer_email);
                 continue;
             }
         } elseif (isset($address->id_customer) && !empty($address->id_customer)) {
             if (Customer::customerIdExistsStatic((int) $address->id_customer)) {
                 $customer = new Customer((int) $address->id_customer);
                 // a customer could exists in different shop
                 $customer_list = Customer::getCustomersByEmail($customer->email);
                 if (count($customer_list) == 0) {
                     $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer);
                 }
             } else {
                 $this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be saved.'), $address->id_customer);
             }
         } else {
             $customer_list = array();
             $address->id_customer = 0;
         }
         if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) {
             $address->id_manufacturer = (int) $address->manufacturer;
         } elseif (isset($address->manufacturer) && is_string($address->manufacturer) && !empty($address->manufacturer)) {
             $manufacturer = new Manufacturer();
             $manufacturer->name = $address->manufacturer;
             if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
                 $address->id_manufacturer = (int) $manufacturer->id;
             } else {
                 $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
                 $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
             }
         }
         if (isset($address->supplier) && is_numeric($address->supplier) && Supplier::supplierExists((int) $address->supplier)) {
             $address->id_supplier = (int) $address->supplier;
         } elseif (isset($address->supplier) && is_string($address->supplier) && !empty($address->supplier)) {
             $supplier = new Supplier();
             $supplier->name = $address->supplier;
             if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) {
                 $address->id_supplier = (int) $supplier->id;
             } else {
                 $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null');
                 $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
             }
         }
         $res = false;
         if (($field_error = $address->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
             if (isset($customer_list) && count($customer_list) > 0) {
                 $filter_list = array();
                 foreach ($customer_list as $customer) {
                     if (in_array($customer['id_customer'], $filter_list)) {
                         continue;
                     }
                     $filter_list[] = $customer['id_customer'];
                     unset($address->id);
                     $address->id_customer = $customer['id_customer'];
                     $res = $address->add();
                     if (!$res) {
                         $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
                     }
                 }
             } else {
                 $address->force_id = (bool) Tools::getValue('forceIDs');
                 if ($address->id && $address->addressExists($address->id)) {
                     $res = $address->update();
                 }
                 if (!$res) {
                     $res = $address->add();
                 }
             }
         }
         if (!$res) {
             $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['alias'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
             $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
         }
     }
     $this->closeCsvFile($handle);
 }
Beispiel #4
0
 * @copyright  2013 - 2016 xport communication GmbH
 * @link       http://www.xport.de
 */
require_once dirname(__FILE__) . '/../../config/config.inc.php';
$json = file_get_contents('php://input');
$jsonObj = json_decode($json);
// default shop context
if (Shop::isFeatureActive()) {
    Shop::setContext(Shop::CONTEXT_ALL);
}
if (is_object($jsonObj)) {
    $campaignmonitor = Module::getInstanceByName('campaignmonitor');
    $blocknewsletter = Module::getInstanceByName('blocknewsletter');
    foreach ($jsonObj->Events as $event) {
        $emailAddress = $event->EmailAddress;
        $customerByMail = Customer::getCustomersByEmail($emailAddress);
        if ($customerByMail) {
            $customer = new Customer($customerByMail[0]['id_customer']);
            if ($event->Type == 'Deactivate') {
                $customer->newsletter = false;
            }
            if ($event->Type == 'Subscribe' || $event->Type == 'Update') {
                $customer->newsletter = true;
            }
            $customer->save();
        } else {
            $id_shop = null;
            // set shop context for each subscriber
            if (Shop::isFeatureActive()) {
                $id_shop = $campaignmonitor->getCustomFieldValue('ps Shop ID', $event->CustomFields);
                Shop::setContext(Shop::CONTEXT_SHOP, $id_shop);
Beispiel #5
0
        }
        return false;
    } catch (Syspay_Merchant_UnexpectedResponseException $s) {
        $website = SyspayTools::getWebsite(true, false);
        if (version_compare(_PS_VERSION_, '1.5', '>=')) {
            Tools::redirect('/index.php?controller=order&step=3&err=1');
        } else {
            Tools::redirectLink($website . '/order.php?step=3&err=1');
        }
        return false;
    }
} elseif (Tools::isSubmit('rebill')) {
    $client = new Syspay_Merchant_Client($mid, $pass, $mode);
    $id_rebill = Tools::getValue('rebill');
    if (version_compare(_PS_VERSION_, '1.5', '>=')) {
        $customer = Customer::getCustomersByEmail(Tools::getValue('email'));
        $id = SyspayTools::getIdsRebillByIdCustomer($customer[0]['id_customer']);
    } else {
        $customer = new Customer();
        $customer = $customer->getByEmail(Tools::getValue('email'));
        $id = SyspayTools::getIdsRebillByIdCustomer($customer->id);
    }
    if ($id_rebill != $id) {
        $website = SyspayTools::getWebsite(true, false);
        if (version_compare(_PS_VERSION_, '1.5', '>=')) {
            Tools::redirect('/index.php?controller=order&step=3&err=1');
        } else {
            Tools::redirectLink($website . '/order.php?step=3&err=1');
        }
        return;
    }