stephen89 Posted February 8, 2012 Share Posted February 8, 2012 Hey, I was wondering if it was possible to have the Category (and/or sub category) of a product appear in the order email and invoice. Mockup Any help &/or input is greatly appreciated. Link to comment Share on other sites More sharing options...
bellini13 Posted February 8, 2012 Share Posted February 8, 2012 for the invoice, you would have to alter the PDF.php class, to include the category information. for the order confirmation email, you would likely need to alter the PaymentModule.php file and the possibly the mail template. if you are looking to hire someone to do this work, you can send me a PM. Link to comment Share on other sites More sharing options...
stephen89 Posted February 8, 2012 Author Share Posted February 8, 2012 I will keep that in mind, I'll probably mess around with it myself for a while, I just haven't entirely figured out where everything is pulled from and was mostly hoping for which files needed to be played with to reflect the changes I need. Thanks for your help. Link to comment Share on other sites More sharing options...
stephen89 Posted February 9, 2012 Author Share Posted February 9, 2012 So from what I can tell, im mailalerts.php I need to edit this, and add a categories cell. Perhaps somebody could push me in the right direction on how I go about that? Also I assume I need to add a corresponding th in new_order.html $itemsTable .= '<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>'.$product['product_name'].(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '').(!empty($customizationText) ? '<br />'.$customizationText : '').'</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td> <td style="padding:0.6em 0.4em; text-align:center;">'.(int)($product['product_quantity']).'</td> <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false).'</td> </tr>'; } Link to comment Share on other sites More sharing options...
stephen89 Posted March 7, 2012 Author Share Posted March 7, 2012 so in mailalerts I have foreach ($customizedDatas[$product['product_id']][$product['product_attribute_id']] AS $customization) { if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] AS $text) $customizationText .= $text['name'].':'.' '.$text['value'].'<br />'; if (isset($customization['datas'][_CUSTOMIZE_FILE_])) $customizationText .= sizeof($customization['datas'][_CUSTOMIZE_FILE_]) .' '. Tools::displayError('image(s)').'<br />'; $customizationText .= '---<br />'; } $customizationText = rtrim($customizationText, '---<br />'); } $category = new Category($product['id_category_default'], $id_lang); $itemsTable .= '<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';"> <td>'.$category->name.'</td> <td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td> <td style="padding:0.6em 0.4em;"><strong>'.$product['product_name'].(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '').(!empty($customizationText) ? '<br />'.$customizationText : '').'</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td> <td style="padding:0.6em 0.4em; text-align:center;">'.(int)($product['product_quantity']).'</td> <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false).'</td> </tr>'; } and in new_order.html I have <td align="left"> <table style="width:100%; font-family:Verdana,sans-serif; font-size:11px; color:#374953;"> <tr style="background-color:#B9BABE; text-align:center;"> <th style="width:15%; padding: 0.6em 0;">Delivery</th> <th style="width:15%; padding: 0.6em 0;">Reference</th> <th>Product</th> <th style="width:15%; padding: 0.6em 0;">Unit price</th> <th style="width:15%; padding: 0.6em 0;">Quantity</th> <th style="width:20%; padding: 0.6em 0;">Total price</th> </tr> But it comes in blank, I am probably missing something stupid, but I was hoping somebody could tell me what I was doing wrong Link to comment Share on other sites More sharing options...
stephen89 Posted March 9, 2012 Author Share Posted March 9, 2012 Okay, so I've still been messing around and searching around the forums and I am still lost. Is there nobody with any input at all? Link to comment Share on other sites More sharing options...
SanitMaharjan Posted March 29, 2012 Share Posted March 29, 2012 Hey me too searching for this. Plz somebody help. Link to comment Share on other sites More sharing options...
vietnam Posted April 11, 2012 Share Posted April 11, 2012 I want to be able to have the customer email in new_order.html Link to comment Share on other sites More sharing options...
sane_software Posted June 27, 2012 Share Posted June 27, 2012 (edited) I haven't looked into the invoice yet, but I was able to get category names in emails by the following method. You could easily add other fields by varying this procedure. You need to override some classes to make the category info available to the email templates. If these files already exist you will need to merge the below changes into the existing files. First is override/classes/Product.php. Create the new file if it doesn't exist. The constructor adds a new property "categoryInfo" and stores the Category object in it. <?php class Product extends ProductCore { public function __construct($id_product = NULL, $full = false, $id_lang = NULL) { global $cart; parent::__construct($id_product, $full, $id_lang); if ($this->id_category_default) $this->categoryInfo = new Category((int)$this->id_category_default, (int)$id_lang); } /** * getCategories return an array of categories which this product belongs to * * @return array of categories */ public function getCategoriesFull() { return Product::getProductCategoriesFull($this->id); } } Then override/classes/Order.php. This will add the category name for each product as "category_name". <?php class Order extends OrderCore { /** * Get order products * * @return array Products with price, quantity (with taxe and without) */ public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) $products = $this->getProductsDetail(); $resultArray = array(); foreach ($products AS $row) { // Change qty if selected if ($selectedQty) { $row['product_quantity'] = 0; foreach ($selectedProducts AS $key => $id_product) if ($row['id_order_detail'] == $id_product) $row['product_quantity'] = (int)($selectedQty[$key]); if (!$row['product_quantity']) continue ; } $this->setProductPrices($row); /* Add information for virtual product */ if ($row['download_hash'] AND !empty($row['download_hash'])) $row['filename'] = ProductDownload::getFilenameFromIdProduct($row['product_id']); // Add the category name $product = new Product($row['product_id']); $row['category_name'] = is_array($product->categoryInfo->name)?$product->categoryInfo->name[1]:$product->categoryInfo->name; /* Stock product */ $resultArray[(int)($row['id_order_detail'])] = $row; } return $resultArray; } } Here's the big one - override/classes/PaymentModule.php. It's so big because you need to basically copy the whole validateOrder method from the parent and change a few lines. Around line 247 is where the magic happens. You can modify the layout for the tables to suit your needs, but the bit that gives you the category name is $products['category_name']. <?php include_once(dirname(__FILE__).'/../config/config.inc.php'); //error_reporting(E_ALL); //ini_set('display_errors', '1'); abstract class PaymentModule extends PaymentModuleCore { /** * Validate an order in database * Function called from a payment module * * @param integer $id_cart Value * @param integer $id_order_state Value * @param float $amountPaid Amount really paid by customer (in the default currency) * @param string $paymentMethod Payment method (eg. 'Credit card') * @param string $message Message to attach to order */ public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $secure_key = false) { global $cart; $cart = new Cart((int)($id_cart)); // Does order already exists ? if (!$this->active) die(Tools::displayError()); if (Validate::isLoadedObject($cart) AND $cart->OrderExists() == false) { if ($secure_key !== false AND $secure_key != $cart->secure_key) die(Tools::displayError()); // Copying data from cart $order = new Order(); $order->id_carrier = (int)($cart->id_carrier); $order->id_customer = (int)($cart->id_customer); $order->id_address_invoice = (int)($cart->id_address_invoice); $order->id_address_delivery = (int)($cart->id_address_delivery); $vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $order->id_currency = ($currency_special ? (int)($currency_special) : (int)($cart->id_currency)); $order->id_lang = (int)($cart->id_lang); $order->id_cart = (int)($cart->id); $customer = new Customer((int)($order->id_customer)); $order->secure_key = ($secure_key ? pSQL($secure_key) : pSQL($customer->secure_key)); $order->payment = $paymentMethod; if (isset($this->name)) $order->module = $this->name; $order->recyclable = $cart->recyclable; $order->gift = (int)($cart->gift); $order->gift_message = $cart->gift_message; $currency = new Currency($order->id_currency); $order->conversion_rate = $currency->conversion_rate; $amountPaid = !$dont_touch_amount ? Tools::ps_round((float)($amountPaid), 2) : $amountPaid; $order->total_paid_real = $amountPaid; $order->total_products = (float)($cart->getOrderTotal(false, Cart::ONLY_PRODUCTS)); $order->total_products_wt = (float)($cart->getOrderTotal(true, Cart::ONLY_PRODUCTS)); $order->total_discounts = (float)(abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS))); $order->total_shipping = (float)($cart->getOrderShippingCost()); $order->carrier_tax_rate = (float)Tax::getCarrierTaxRate($cart->id_carrier, (int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $order->total_wrapping = (float)(abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING))); $order->total_paid = (float)(Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH)), 2)); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; // Amount paid by customer is not the right one -> Status = payment error // We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php // if ($order->total_paid != $order->total_paid_real) // We use number_format in order to compare two string if (number_format($order->total_paid, 2) != number_format($order->total_paid_real, 2)) $id_order_state = Configuration::get('PS_OS_ERROR'); // Creating order if ($cart->OrderExists() == false) $result = $order->add(); else { $errorMessage = Tools::displayError('An order has already been placed using this cart.'); Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($order->id_cart)); die($errorMessage); } // Next ! if ($result AND isset($order->id)) { if (!$secure_key) $message .= $this->l('Warning : the secure key is empty, check your payment account before validation'); // Optional message to attach to this order if (isset($message) AND !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (Validate::isCleanHtml($message)) { $msg->message = $message; $msg->id_order = intval($order->id); $msg->private = 1; $msg->add(); } } // Insert products from cart into order_detail table $products = $cart->getProducts(); $productsList = ''; $db = Db::getInstance(); $query = 'INSERT INTO `'._DB_PREFIX_.'order_detail` (`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `reduction_percent`, `reduction_amount`, `group_reduction`, `product_quantity_discount`, `product_ean13`, `product_upc`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `ecotax_tax_rate`, `discount_quantity_applied`, `download_deadline`, `download_hash`) VALUES '; $customizedDatas = Product::getAllCustomizedDatas((int)($order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); $outOfStock = false; $storeAllTaxes = array(); foreach ($products AS $key => $product) { $productQuantity = (int)(Product::getQuantity((int)($product['id_product']), ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL))); $quantityInStock = ($productQuantity - (int)($product['cart_quantity']) < 0) ? $productQuantity : (int)($product['cart_quantity']); if ($id_order_state != Configuration::get('PS_OS_CANCELED') AND $id_order_state != Configuration::get('PS_OS_ERROR')) { if (Product::updateQuantity($product, (int)$order->id)) $product['stock_quantity'] -= $product['cart_quantity']; if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) $outOfStock = true; Product::updateDefaultAttribute($product['id_product']); } $price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); /* Store tax info */ $id_country = (int)Country::getDefaultCountryId(); $id_state = 0; $id_county = 0; $rate = 0; $id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) { $id_country = (int)($address_infos['id_country']); $id_state = (int)$address_infos['id_state']; $id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']); } $allTaxes = TaxRulesGroup::getTaxes((int)Product::getIdTaxRulesGroupByIdProduct((int)$product['id_product']), $id_country, $id_state, $id_county); $nTax = 0; foreach ($allTaxes AS $res) { if (!isset($storeAllTaxes[$res->id])) { $storeAllTaxes[$res->id] = array(); $storeAllTaxes[$res->id]['amount'] = 0; } $storeAllTaxes[$res->id]['name'] = $res->name[(int)$order->id_lang]; $storeAllTaxes[$res->id]['rate'] = $res->rate; if (!$nTax++) $storeAllTaxes[$res->id]['amount'] += ($price * ($res->rate * 0.01)) * $product['cart_quantity']; else { $priceTmp = $price_wt / (1 + ($res->rate * 0.01)); $storeAllTaxes[$res->id]['amount'] += ($price_wt - $priceTmp) * $product['cart_quantity']; } } /* End */ // Add some informations for virtual products $deadline = '0000-00-00 00:00:00'; $download_hash = NULL; if ($id_product_download = ProductDownload::getIdFromIdProduct((int)($product['id_product']))) { $productDownload = new ProductDownload((int)($id_product_download)); $deadline = $productDownload->getDeadLine(); $download_hash = $productDownload->getHash(); } // Exclude VAT if (Tax::excludeTaxeOption()) { $product['tax'] = 0; $product['rate'] = 0; $tax_rate = 0; } else $tax_rate = Tax::getProductTaxRate((int)($product['id_product']), $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotaxTaxRate = 0; if (!empty($product['ecotax'])) $ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $product_price = (float)Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), (Product::getTaxCalculationMethod((int)($order->id_customer)) == PS_TAX_EXC ? 2 : 6), NULL, false, false, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), $specificPrice, false, false); $group_reduction = (float)GroupReduction::getValueForProduct((int)$product['id_product'], $customer->id_default_group) * 100; if (!$group_reduction) $group_reduction = Group::getReduction((int)$order->id_customer); $quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], Shop::getCurrentShop(), (int)$cart->id_currency, (int)$vat_address->id_country, (int)$customer->id_default_group, (int)$product['cart_quantity']); $unitPrice = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL), 2, NULL, false, true, 1, false, (int)$order->id_customer, NULL, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $quantityDiscountValue = $quantityDiscount ? ((Product::getTaxCalculationMethod((int)$order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100)) : 0.00; $query .= '('.(int)($order->id).', '.(int)($product['id_product']).', '.(isset($product['id_product_attribute']) ? (int)($product['id_product_attribute']) : 'NULL').', \''.pSQL($product['name'].((isset($product['attributes']) AND $product['attributes'] != NULL) ? ' - '.$product['attributes'] : '')).'\', '.(int)($product['cart_quantity']).', '.$quantityInStock.', '.$product_price.', '.(float)(($specificPrice AND $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.00).', '.(float)(($specificPrice AND $specificPrice['reduction_type'] == 'amount') ? (!$specificPrice['id_currency'] ? Tools::convertPrice($specificPrice['reduction'], $order->id_currency) : $specificPrice['reduction']) : 0.00).', '.$group_reduction.', '.$quantityDiscountValue.', '.(empty($product['ean13']) ? 'NULL' : '\''.pSQL($product['ean13']).'\'').', '.(empty($product['upc']) ? 'NULL' : '\''.pSQL($product['upc']).'\'').', '.(empty($product['reference']) ? 'NULL' : '\''.pSQL($product['reference']).'\'').', '.(empty($product['supplier_reference']) ? 'NULL' : '\''.pSQL($product['supplier_reference']).'\'').', '.(float)($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']).', \''.(empty($tax_rate) ? '' : pSQL($product['tax'])).'\', '.(float)($tax_rate).', '.(float)Tools::convertPrice(floatval($product['ecotax']), intval($order->id_currency)).', '.(float)$ecotaxTaxRate.', '.(($specificPrice AND $specificPrice['from_quantity'] > 1) ? 1 : 0).', \''.pSQL($deadline).'\', \''.pSQL($download_hash).'\'),'; $customizationQuantity = 0; if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) { $customizationText = ''; foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] AS $customization) { if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] AS $text) $customizationText .= $text['name'].':'.' '.$text['value'].'<br />'; if (isset($customization['datas'][_CUSTOMIZE_FILE_])) $customizationText .= sizeof($customization['datas'][_CUSTOMIZE_FILE_]) .' '. Tools::displayError('image(s)').'<br />'; $customizationText .= '---<br />'; } $customizationText = rtrim($customizationText, '---<br />'); // Add the category name $tmp = new Product($product['id_product']); $product['category_name'] = is_array($tmp->categoryInfo->name)?$tmp->categoryInfo->name[1]:$tmp->categoryInfo->name; $customizationQuantity = (int)($product['customizationQuantityTotal']); $productsList .= '<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';"> <td style="padding: 0.6em 0.4em;"><strong>'.$product['category_name'].'</strong></td> <td style="padding: 0.6em 0.4em;"><strong>'.$product['name'].'</strong></td> <td style="padding: 0.6em 0.4em;"><strong>'.(isset($product['attributes']) ? ' - '.$product['attributes'] : '').' - '.$this->l('Customized').(!empty($customizationText) ? ' - '.$customizationText : '').'</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false).'</td> <td style="padding: 0.6em 0.4em; text-align: center;">'.$customizationQuantity.'</td> <td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td> </tr>'; } if (!$customizationQuantity OR (int)$product['cart_quantity'] > $customizationQuantity) $productsList .= '<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';"> <td style="padding: 0.6em 0.4em;"><strong>'.$product['category_name'].'</strong></td> <td style="padding: 0.6em 0.4em;"><strong>'.$product['name'].'</strong></td> <td style="padding: 0.6em 0.4em;"><strong>'.(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false).'</td> <td style="padding: 0.6em 0.4em; text-align: center;">'.((int)($product['cart_quantity']) - $customizationQuantity).'</td> <td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(((int)($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td> </tr>'; } // end foreach ($products) $query = rtrim($query, ','); $result = $db->Execute($query); /* Add carrier tax */ $shippingCostTaxExcl = $cart->getOrderShippingCost((int)$order->id_carrier, false); $allTaxes = TaxRulesGroup::getTaxes((int)Carrier::getIdTaxRulesGroupByIdCarrier((int)$order->id_carrier), $id_country, $id_state, $id_county); $nTax = 0; foreach ($allTaxes AS $res) { if (!isset($res->id)) continue; if (!isset($storeAllTaxes[$res->id])) $storeAllTaxes[$res->id] = array(); if (!isset($storeAllTaxes[$res->id]['amount'])) $storeAllTaxes[$res->id]['amount'] = 0; $storeAllTaxes[$res->id]['name'] = $res->name[(int)$order->id_lang]; $storeAllTaxes[$res->id]['rate'] = $res->rate; if (!$nTax++) $storeAllTaxes[$res->id]['amount'] += ($shippingCostTaxExcl * (1 + ($res->rate * 0.01))) - $shippingCostTaxExcl; else { $priceTmp = $order->total_shipping / (1 + ($res->rate * 0.01)); $storeAllTaxes[$res->id]['amount'] += $order->total_shipping - $priceTmp; } } /* Store taxes */ foreach ($storeAllTaxes AS $t) Db::getInstance()->Execute(' INSERT INTO '._DB_PREFIX_.'order_tax (id_order, tax_name, tax_rate, amount) VALUES ('.(int)$order->id.', \''.pSQL($t['name']).'\', '.(float)($t['rate']).', '.(float)$t['amount'].')'); // Insert discounts from cart into order_discount table $discounts = $cart->getDiscounts(); $discountsList = ''; $total_discount_value = 0; $shrunk = false; foreach ($discounts AS $discount) { $objDiscount = new Discount((int)$discount['id_discount']); $value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $order->total_shipping, $cart->id); if ($objDiscount->id_discount_type == 2 AND in_array($objDiscount->behavior_not_exhausted, array(1,2))) $shrunk = true; if ($shrunk AND ($total_discount_value + $value) > ($order->total_products_wt + $order->total_shipping + $order->total_wrapping)) { $amount_to_add = ($order->total_products_wt + $order->total_shipping + $order->total_wrapping) - $total_discount_value; if ($objDiscount->id_discount_type == 2 AND $objDiscount->behavior_not_exhausted == 2) { $voucher = new Discount(); foreach ($objDiscount AS $key => $discountValue) $voucher->$key = $discountValue; $voucher->name = 'VSRK'.(int)$order->id_customer.'O'.(int)$order->id; $voucher->value = (float)$value - $amount_to_add; $voucher->add(); $params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false); $params['{voucher_num}'] = $voucher->name; $params['{firstname}'] = $customer->firstname; $params['{lastname}'] = $customer->lastname; $params['{id_order}'] = $order->id; @Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order #', (int)$order->id_lang).$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname); } } else $amount_to_add = $value; $order->addDiscount($objDiscount->id, $objDiscount->name, $amount_to_add); $total_discount_value += $amount_to_add; if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED')) $objDiscount->quantity = $objDiscount->quantity - 1; $objDiscount->update(); $discountsList .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">'.$this->l('Voucher code:').' '.$objDiscount->name.'</td> <td style="padding: 0.6em 0.4em; text-align: right;">'.($value != 0.00 ? '-' : '').Tools::displayPrice($value, $currency, false).'</td> </tr>'; } // Specify order id for message $oldMessage = Message::getMessageByCartId((int)($cart->id)); if ($oldMessage) { $message = new Message((int)$oldMessage['id_message']); $message->id_order = (int)$order->id; $message->update(); } // Hook new order $orderStatus = new OrderState((int)$id_order_state, (int)$order->id_lang); if (Validate::isLoadedObject($orderStatus)) { Hook::newOrder($cart, $order, $customer, $currency, $orderStatus); foreach ($cart->getProducts() AS $product) if ($orderStatus->logable) ProductSale::addProductSale((int)$product['id_product'], (int)$product['cart_quantity']); } if (isset($outOfStock) && $outOfStock && Configuration::get('PS_STOCK_MANAGEMENT')) { $history = new OrderHistory(); $history->id_order = (int)$order->id; $history->changeIdOrderState(Configuration::get('PS_OS_OUTOFSTOCK'), (int)$order->id); $history->addWithemail(); } // Set order state in order history ONLY even if the "out of stock" status has not been yet reached // So you migth have two order states $new_history = new OrderHistory(); $new_history->id_order = (int)$order->id; $new_history->changeIdOrderState((int)$id_order_state, (int)$order->id); $new_history->addWithemail(true, $extraVars); // Order is reloaded because the status just changed $order = new Order($order->id); // Send an e-mail to customer if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED') AND $customer->id) { $invoice = new Address((int)($order->id_address_invoice)); $delivery = new Address((int)($order->id_address_delivery)); $carrier = new Carrier((int)($order->id_carrier), $order->id_lang); $delivery_state = $delivery->id_state ? new State((int)($delivery->id_state)) : false; $invoice_state = $invoice->id_state ? new State((int)($invoice->id_state)) : false; $data = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => $this->_getFormatedAddress($delivery, "<br />", array( 'firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')), '{invoice_block_html}' => $this->_getFormatedAddress($invoice, "<br />", array( 'firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; 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_vat_number}' => $invoice->vat_number, '{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}' => sprintf("#%06d", (int)($order->id)), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), (int)($order->id_lang), 1), '{carrier}' => $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false)); if (is_array($extraVars)) $data = array_merge($data, $extraVars); // Join PDF invoice if ((int)(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)($order->id_lang)).sprintf('%06d', $order->invoice_number).'.pdf'; $fileAttachment['mime'] = 'application/pdf'; } else $fileAttachment = NULL; if (Validate::isEmail($customer->email)) Mail::Send((int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment); } $this->currentOrder = (int)$order->id; return true; } else { $errorMessage = Tools::displayError('Order creation failed'); Logger::addLog($errorMessage, 4, '0000002', 'Cart', intval($order->id_cart)); die($errorMessage); } } else { $errorMessage = Tools::displayError('Cart cannot be loaded or an order has already been placed using this cart'); Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id)); die($errorMessage); } } /** * @param Object Address $the_address that needs to be txt formated * @return String the txt formated address block */ private function _getFormatedAddress(Address $the_address, $line_sep, $fields_style = array()) { return AddressFormat::generateAddress($the_address, array('avoid' => array()), $line_sep, ' ', $fields_style); } } Now you need to edit modules/mailalerts/mailalerts.php. Because we changed the getProducts method in Order.php we now have $product['category_name'] available to use in the template. Modify the "hookNewOrder" method at about line 166, for example: $itemsTable .= '<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';"> <td style="padding:0.6em 0.4em;"><strong>'.$product['category_name'].'</strong></td> <td style="padding:0.6em 0.4em;"><strong>'.$product['product_name'].'</strong></td> <td style="padding:0.6em 0.4em;"><strong>'.$attributes.'</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td> <td style="padding:0.6em 0.4em; text-align:center;">'.(int)($product['product_quantity']).'</td> <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false).'</td> </tr>'; Your exact formatting requirements may be different, so modify the above code to suit your needs. Disclaimer: I made these modifications whilst on the second night of an all-night coding session. They work, but I may have inadvertently left something out. :-) Edited June 27, 2012 by sane_software (see edit history) Link to comment Share on other sites More sharing options...
sw4all Posted August 6, 2014 Share Posted August 6, 2014 Hi all. Can you please insert manual to modify for Prestashop 1.6. Thank you very much. Daniel Link to comment Share on other sites More sharing options...
sw4all Posted August 21, 2014 Share Posted August 21, 2014 Modify to Prestashop 1.6: http://www.prestashop.com/forums/topic/348625-kategorie-v-emailu-prestashop-16/ Solved Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now