Jump to content
d2boy

Вывод категорий товара в инвойс

Recommended Posts

Подскажите, в каком направлении копать.

Попробовал отсюда взять - пишет undefined variable: category_info

Share this post


Link to post
Share on other sites

смотрите функцию getproductcategories

делаете по аналогии функцию чтоб названия массивом возвращала

клеите их к товару и выводите в инвойсе

Share this post


Link to post
Share on other sites
Posted (edited)
20 hours ago, spectre said:

смотрите функцию getproductcategories

делаете по аналогии функцию чтоб названия массивом возвращала

клеите их к товару и выводите в инвойсе

 

Сделал так:

 

В admin/controller/sale/order.php перед $option_data = array(); добавил
 

$categories = array();
  $this->load->model('catalog/product');
  $categories = $this->model_catalog_product->getProductCategories($product['product_id']);
  $this->load->model('catalog/category');
    foreach($categories as $category_id){
        $categories_names[] = $this->model_catalog_category->getCategory($category_id);
                        }
          $option_data = array();
          $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);

и в массив   $product_data[] = array(

Добавил строчку 

'categories' => $categories_names,

в invoice_template.tpl в первый столбик добавил

 <?php if (!empty($product['categories'])) { ?>
                      <?php foreach ($product['categories'] as $category) { ?>
                          <?php echo $category['name']; ?><br />
                      <?php } ?>
               <?php } ?>

Теперь выводится

Edited by d2boy

Share this post


Link to post
Share on other sites

А может быть кто-то подскажет, как вывести категорию товаров в шаблон письма?

Share this post


Link to post
Share on other sites
6 часов назад, d2boy сказал:

А может быть кто-то подскажет, как вывести категорию товаров в шаблон письма?

немного подумать и адаптировать код выше, он правда кривой и избыточный но рабочий 

Share this post


Link to post
Share on other sites

Сделал ocmod сам (языковые переменные только не смог победить, как-то запутанно, прописал жёстко)
 

<file path="catalog/model/catalog/product.php">			
		<operation>
			<search><![CDATA[
			public function getProductSpecials($data = array()) {
			]]></search>
			<add position="before"><![CDATA[				
					public function getProductCategories($product_id) {
					$product_category_data = array();

					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");

					foreach ($query->rows as $result) {
						$product_category_data[] = $result['category_id'];
					}

					return $product_category_data;
				}
			]]>
        	</add>
		</operation>
	</file>
	<file path="catalog/model/checkout/order.php">			
		<operation>
			<search><![CDATA[$data['products'][] = array(]]></search>
			<add position="before"><![CDATA[								
				$this->load->model('catalog/product');
				$this->load->model('catalog/category');				
			
              	$category_names = array();
				$products_to_categories = $this->model_catalog_product->getProductCategories($product['product_id']);
				if ($products_to_categories) {	
					foreach ($products_to_categories as $product_to_category) {
						$category_info = $this->model_catalog_category->getCategory($product_to_category);		
						if ($category_info) {
							$category_names[$product['product_id']] = $category_info['name'];
						}
					}
				}
				]]>
        	</add>
		</operation>
		<operation>
			<search><![CDATA['model'    => $product['model'],]]></search>
			<add position="after"><![CDATA['href' => $this->url->link('product/product', 'product_id=' . $product['product_id']),				
				'category' => (!empty($category_names[$product['product_id']]) ? $category_names[$product['product_id']] : ''),
				]]>				
			</add>
		</operation>
	</file>
  	<file path="catalog/view/theme/*/template/mail/order.tpl">
		<operation>
			<search><![CDATA[<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;"><?php echo $text_product; ?></td>]]></search>
			<add position="after"><![CDATA[<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;">Категории</td>]]></add>
		</operation>	
		<operation>
			<search><![CDATA[<td style="font-size: 12px;	border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;" colspan="4">]]></search>
			<add position="replace"><![CDATA[<td style="font-size: 12px;	border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;" colspan="5">]]></add>
		</operation>
		<operation>
			<search><![CDATA[<td style="font-size: 12px;	border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><?php echo $product['model']; ?></td>]]></search>
			<add position="before"><![CDATA[<td style="font-size: 12px;	border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;">
			<?php echo $product['category']; ?><br>  					       
			</td>]]></add>
		</operation>
	</file>

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.