Esempio n. 1
0
 public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)
 {
     if (!Validate::isUnsignedId($id_customer) || !Validate::isUnsignedId($id_lang)) {
         die(Tools::displayError());
     }
     if (!$shop) {
         $shop = Context::getContext()->shop;
     }
     $customer = new Customer($id_customer);
     $products = MailAlert::getProducts($customer, $id_lang);
     $products_number = count($products);
     if (empty($products) === true || !$products_number) {
         return array();
     }
     for ($i = 0; $i < $products_number; ++$i) {
         $obj = new Product((int) $products[$i]['id_product'], false, (int) $id_lang);
         if (!Validate::isLoadedObject($obj)) {
             continue;
         }
         if (isset($products[$i]['id_product_attribute']) && Validate::isUnsignedInt($products[$i]['id_product_attribute'])) {
             $attributes = self::getProductAttributeCombination($products[$i]['id_product_attribute'], $id_lang);
             $products[$i]['attributes_small'] = '';
             if ($attributes) {
                 foreach ($attributes as $k => $row) {
                     $products[$i]['attributes_small'] .= $row['attribute_name'] . ', ';
                 }
             }
             $products[$i]['attributes_small'] = rtrim($products[$i]['attributes_small'], ', ');
             $products[$i]['id_shop'] = $shop->id;
             /* Get cover */
             $attrgrps = $obj->getAttributesGroups((int) $id_lang);
             foreach ($attrgrps as $attrgrp) {
                 if ($attrgrp['id_product_attribute'] == (int) $products[$i]['id_product_attribute'] && ($images = Product::_getAttributeImageAssociations((int) $attrgrp['id_product_attribute']))) {
                     $products[$i]['cover'] = $obj->id . '-' . array_pop($images);
                     break;
                 }
             }
         }
         if (!isset($products[$i]['cover']) || !$products[$i]['cover']) {
             $images = $obj->getImages((int) $id_lang);
             foreach ($images as $k => $image) {
                 if ($image['cover']) {
                     $products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
                     break;
                 }
             }
         }
         if (!isset($products[$i]['cover'])) {
             $products[$i]['cover'] = Language::getIsoById($id_lang) . '-default';
         }
         $products[$i]['link'] = $obj->getLink();
         $products[$i]['link_rewrite'] = $obj->link_rewrite;
     }
     return $products;
 }
Esempio n. 2
0
 public function initContent()
 {
     parent::initContent();
     if (!Context::getContext()->customer->isLogged()) {
         Tools::redirect('index.php?controller=authentication&redirect=module&module=mailalerts&action=account');
     }
     if (Context::getContext()->customer->id) {
         $this->context->smarty->assign('id_customer', Context::getContext()->customer->id);
         $this->context->smarty->assign('mailAlerts', MailAlert::getMailAlerts((int) Context::getContext()->customer->id, (int) Context::getContext()->language->id));
         $this->setTemplate('mailalerts-account.tpl');
     }
 }
/* SSL Management */
$useSSL = true;
include dirname(__FILE__) . '/../../config/config.inc.php';
include dirname(__FILE__) . '/../../header.php';
include_once dirname(__FILE__) . '/mailalerts.php';
// Instance of module class for translations
$module = new MailAlerts();
$errors = array();
if ($cookie->isLogged()) {
    if (Tools::getValue('action') == 'delete') {
        $id_customer = (int) $cookie->id_customer;
        if (!($id_product = (int) Tools::getValue('id_product'))) {
            $errors[] = $module->l('You must have a product to delete an alert.', 'mailalerts-account');
        }
        $id_product_attribute = (int) Tools::getValue('id_product_attribute');
        $customer = new Customer((int) $id_customer);
        MailAlerts::deleteAlert((int) $id_customer, strval($customer->email), (int) $id_product, (int) $id_product_attribute);
    }
    $this->context->smarty->assign('mailAlerts', MailAlert::getProductsAlerts((int) $cookie->id_customer, (int) $cookie->id_lang));
} else {
    $errors[] = $module->l('You must be logged in to manage your alerts.', 'mailalerts-account');
}
$this->context->smarty->assign(array('id_customer' => (int) $cookie->id_customer, 'errors' => $errors));
if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/mailalerts/myalerts.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'modules/mailalerts/myalerts.tpl');
} elseif (Tools::file_exists_cache(dirname(__FILE__) . '/myalerts.tpl')) {
    $smarty->display(dirname(__FILE__) . '/myalerts.tpl');
} else {
    echo $module->l('No template found', 'mailalerts-account');
}
include dirname(__FILE__) . '/../../footer.php';
Esempio n. 4
0
    public function hookActionProductAttributeUpdate($params)
    {
        $sql = '
			SELECT `id_product`, `quantity`
			FROM `' . _DB_PREFIX_ . 'stock_available`
			WHERE `id_product_attribute` = ' . (int) $params['id_product_attribute'];
        $result = Db::getInstance()->getRow($sql);
        if ($this->customer_qty && $result['quantity'] > 0) {
            MailAlert::sendCustomerAlert((int) $result['id_product'], (int) $params['id_product_attribute']);
        }
    }
Esempio n. 5
0
    /**
     * Send a mail when a customer return an order.
     *
     * @param array $params Hook params.
     */
    public function hookActionOrderReturn($params)
    {
        if (!$this->return_slip || empty($this->return_slip)) {
            return;
        }
        $context = Context::getContext();
        $id_lang = (int) $context->language->id;
        $id_shop = (int) $context->shop->id;
        $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_COLOR'), $id_lang, null, $id_shop);
        // Shop iso
        $iso = Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT'));
        $order = new Order((int) $params['orderReturn']->id_order);
        $customer = new Customer((int) $params['orderReturn']->id_customer);
        $delivery = new Address((int) $order->id_address_delivery);
        $invoice = new Address((int) $order->id_address_invoice);
        $order_date_text = Tools::displayDate($order->date_add);
        if ($delivery->id_state) {
            $delivery_state = new State((int) $delivery->id_state);
        }
        if ($invoice->id_state) {
            $invoice_state = new State((int) $invoice->id_state);
        }
        $order_return_products = OrderReturn::getOrdersReturnProducts($params['orderReturn']->id, $order);
        $items_table = '';
        foreach ($order_return_products as $key => $product) {
            $url = $context->link->getProductLink($product['product_id']);
            $items_table .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';">
					<td style="padding:0.6em 0.4em;">' . $product['product_reference'] . '</td>
					<td style="padding:0.6em 0.4em;">
						<strong><a href="' . $url . '">' . $product['product_name'] . '</a>
					</strong>
					</td>
					<td style="padding:0.6em 0.4em; text-align:center;">' . (int) $product['product_quantity'] . '</td>
				</tr>';
        }
        $template_vars = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => MailAlert::getFormatedAddress($delivery, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>')), '{invoice_block_html}' => MailAlert::getFormatedAddress($invoice, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>')), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => $order->reference, '{shop_name}' => $configuration['PS_SHOP_NAME'], '{date}' => $order_date_text, '{items}' => $items_table, '{message}' => Tools::purifyHTML($params['orderReturn']->question));
        // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
        $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails);
        foreach ($merchant_mails as $merchant_mail) {
            // Default language
            $mail_id_lang = $id_lang;
            $mail_iso = $iso;
            // Use the merchant lang if he exists as an employee
            $results = Db::getInstance()->executeS('
				SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'employee`
				WHERE `email` = \'' . pSQL($merchant_mail) . '\'
			');
            if ($results) {
                $user_iso = Language::getIsoById((int) $results[0]['id_lang']);
                if ($user_iso) {
                    $mail_id_lang = (int) $results[0]['id_lang'];
                    $mail_iso = $user_iso;
                }
            }
            $dir_mail = false;
            if (file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/return_slip.txt') && file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/return_slip.html')) {
                $dir_mail = dirname(__FILE__) . '/mails/';
            }
            if (file_exists(_PS_MAIL_DIR_ . $mail_iso . '/return_slip.txt') && file_exists(_PS_MAIL_DIR_ . $mail_iso . '/return_slip.html')) {
                $dir_mail = _PS_MAIL_DIR_;
            }
            if ($dir_mail) {
                Mail::Send($mail_id_lang, 'return_slip', sprintf(Mail::l('New return from order #%d - %s', $mail_id_lang), $order->id, $order->reference), $template_vars, $merchant_mail, null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, $dir_mail, null, $id_shop);
            }
        }
    }
Esempio n. 6
0
 /**
  * Add a favorite product
  */
 public function processCheck()
 {
     if (!(int) $this->context->customer->logged) {
         die('0');
     }
     $id_customer = (int) $this->context->customer->id;
     if (!($id_product = (int) Tools::getValue('id_product'))) {
         die('0');
     }
     $id_product_attribute = (int) Tools::getValue('id_product_attribute');
     if (MailAlert::customerHasNotification((int) $id_customer, (int) $id_product, (int) $id_product_attribute, (int) $this->context->shop->id)) {
         die('1');
     }
     die('0');
 }