Jump to content

Lien follow up dans un autre template mail ps 1.6


Recommended Posts

Bonjour,

pour réduire le nombre de mail envoyé aux clients, j'ai ajouté le lien de suivi du colis follow up, dans le template mail 'expédié' (qui à tjours le numéro de suivi lors de ce changement de statut)

Le lien est vide même avec l'adresse du suivi renseigné dans le transporteur. Je pense que le code n'est pas appelé.

Ma question comment appeler faire pour que ce lien fonctionne dans mon statut de commande 'expédié'.

Merci pour votre aide.

Ps 1.6

 

Link to comment
Share on other sites

Il faut l'ajouter dans order_history.php (Code à adapter à votre boutique^^)

    public function sendEmail($order, $template_vars = false)
    {
		$context = Context::getContext();
		// Send order confirmation only if order is valid and paid
		if (in_array($this->id_order_state, array(Configuration::get('PS_OS_PAYMENT'), Configuration::get('PS_OS_WS_PAYMENT')))) {
			return $this->SendConfirmation($order, $context);
		}
        $result = Db::getInstance()->getRow('
			SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, os.`pdf_invoice`, os.`pdf_delivery`, o.`shipping_number`, oc.`tracking_number`
			FROM `'._DB_PREFIX_.'order_history` oh
				LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
				LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
				LEFT JOIN `'._DB_PREFIX_.'order_carrier` oc ON oc.`id_order` = o.`id_order`
				LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
				LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
			WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1');
			
        if (isset($result['template']) && Validate::isEmail($result['email'])) {
            ShopUrl::cacheMainDomainForShop($order->id_shop);

			// Mise à jour commande si shipping manquant mais tracking existant
			If(!$result['shipping_number'] && $result['tracking_number']) {
				$order->shipping_number = $result['shipping_number'] = $result['tracking_number'];
				$order->update();
			}
            $topic = $result['osname'];
			
            $data = array(
                '{lastname}' => $result['lastname'],
                '{firstname}' => $result['firstname'],
                '{id_order}' => (int)$this->id_order,
                '{order_name}' => $order->getUniqReference()
            );

            if ($result['module_name']) {
                $module = Module::getInstanceByName($result['module_name']);
                if (Validate::isLoadedObject($module) && isset($module->extra_mail_vars) && is_array($module->extra_mail_vars)) {
                    $data = array_merge($data, $module->extra_mail_vars);
                }
            }
			$virtual_products = $order->getVirtualProducts();
			if ($result['id_order_state'] == Configuration::get('PS_OS_SHIPPING')) {
			
				if(count($order->getProductsDetail()) == count($virtual_products))
					return true;
				$topic = Mail::l('Package in transit', (int)$order->id_lang); 
				if($result['shipping_number']) {
					$carrier = new Carrier($order->id_carrier, $order->id_lang);
					$data['{followup}'] = str_replace('@', $result['shipping_number'], $carrier->url);
				}
				else {
					$result['template'] = 'shipped';
				}
			}
			
            if ($template_vars) {
                $data = array_merge($data, $template_vars);
            }
			$rest_to_pay = $order->total_paid > $order->total_paid_real ? $order->total_paid - $order->total_paid_real : $order->total_paid;
            $data['{total_paid}'] = Tools::displayPrice((float)$rest_to_pay, new Currency((int)$order->id_currency), false);
			
            if ($virtual_products && (!$last_order_state || !$last_order_state->logable) && $new_order_state && $new_order_state->logable) {
                $assign = array();
                foreach ($virtual_products as $key => $virtual_product) {
                    if ((int)$virtual_product['product_attribute_id'] > 0) {
                        $id_product_download = ProductDownload::_getIdFromCombination($virtual_product['product_id'], $virtual_product['product_attribute_id']);
                    } else {
                        $id_product_download = ProductDownload::getIdFromIdProduct($virtual_product['product_id']);
                    }
                    $product_download = new ProductDownload($id_product_download);
                    if ($product_download->display_filename != '') {
                        $assign[$key]['name'] = $product_download->display_filename;
                        $dl_link = $product_download->getTextLink(false, $virtual_product['download_hash'])
                            .'&id_order='.$order->id
                            .'&secure_key='.$order->secure_key;
                        $assign[$key]['link'] = $dl_link;
                        if ($virtual_product['download_deadline'] != '0000-00-00 00:00:00') {
                            $assign[$key]['deadline'] = Tools::displayDate($virtual_product['download_deadline'], $order->id_lang);
                        }
                        if ($product_download->nb_downloadable != 0) {
                            $assign[$key]['downloadable'] = $product_download->nb_downloadable;
                        }
                    }
                }
                $context->smarty->assign('virtualProducts', $assign);
                $context->smarty->assign('id_order', $order->id);
                $iso = Language::getIsoById((int)$order->id_lang);
                $links = $context->smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
                $tmp_array = array('{nbProducts}' => count($virtual_products), '{virtualProducts}' => $links);
                $data = array_merge($data, $tmp_array);
                if (!empty($assign)) {
                    Mail::Send((int)$order->id_lang, 'download_product', Mail::l('Virtual product to download', $order->id_lang), $data, $result['email'], $result['firstname'].' '.$result['lastname'], null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop);
                }
            }
			
            if (Validate::isLoadedObject($order)) {
                // Attach invoice and / or delivery-slip if they exists and status is set to attach them
                if (($result['pdf_invoice'] || $result['pdf_delivery'])) {

					$invoice = $order->getInvoicesCollection();
                    $file_attachement = array();
			
                    if ($result['pdf_invoice'] && (int)Configuration::get('PS_INVOICE') && $order->invoice_number) {
                        Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $invoice));
                        $pdf = new PDF($invoice, PDF::TEMPLATE_INVOICE, $context->smarty);
                        $file_attachement['invoice']['content'] = $pdf->render(false);
                        $file_attachement['invoice']['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number).'.pdf';
                        $file_attachement['invoice']['mime'] = 'application/pdf';
                    }
					
                    if ($result['pdf_delivery'] && $order->delivery_number) {
                        $pdf = new PDF($invoice, PDF::TEMPLATE_DELIVERY_SLIP, $context->smarty);
                        $file_attachement['delivery']['content'] = $pdf->render(false);
                        $file_attachement['delivery']['name'] = Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id, null, $order->id_shop).sprintf('%06d', $order->delivery_number).'.pdf';
                        $file_attachement['delivery']['mime'] = 'application/pdf';
                    }
                } 
				else {
                    $file_attachement = null;
                }

                if (!Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname'],
                    null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int)$order->id_shop)) {
                    return false;
                }
            }
            ShopUrl::resetMainDomainCache();
        }
        return true;
    }

 

Link to comment
Share on other sites

c'est bon, j'ai juste ajouter

$virtual_products = $order->getVirtualProducts();
			if ($result['id_order_state'] == Configuration::get('PS_OS_SHIPPING')) {
			
				if(count($order->getProductsDetail()) == count($virtual_products))
					return true;
				$topic = Mail::l('Package in transit', (int)$order->id_lang); 
				if($result['shipping_number']) {
					$carrier = new Carrier($order->id_carrier, $order->id_lang);
					$data['{followup}'] = str_replace('@', $result['shipping_number'], $carrier->url);
				}
				else {
					$result['template'] = 'shipped';
				}
			}

à mon code.

Ca semble fonctionner.

Encore Merci.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...