Jump to content
Sign in to follow this  
pashast

[HowTo] Новые товары в рассылке

Recommended Posts

Помогите доделать рассылку новых товаров через стандартные опенкартовские рассылки.

 

В контроллер рассылок admin/controller/sale/contact.php

		//Latest
		
					$this->load->model('catalog/product');
					
					$this->load->model('tool/image');
					
					$latest_data = array(
						'sort'  => 'p.date_added',
						'order' => 'DESC',
						'start' => 0,
						'limit' => 4
					);

					$results = $this->model_catalog_product->getProducts($latest_data);

					foreach ($results as $result) {
						if ($result['image']) {
							$image = $this->model_tool_image->resize($result['image'], 138, 138);
						} else {
							$image = false;
						}
									

						$price = $this->currency->format($result['price']);
								
						
						$this->data['latest_products'][] = array(
							'product_id' => $result['product_id'],
							'thumb'   	 => $image,
							'name'    	 => $result['name'],
							'date'    	 => $result['date_added'],
							'price'   	 => $price,
							'href'    	 => str_replace('/admin/', '/catalog/', $this->url->link('product/product', 'product_id=' . $result['product_id'])),
						);
					}
		//Latest	

 

В шаблон /admin/view/template/sale/contact.tpl

		<div id="kod" style="display: none ;">
		<h1>Рассылка магазина</h1>
			<table cellspacing="0" border="0" cellpadding="0" width="624">
				<tbody><tr>
					<td>
						<h3 style="font-size: 24px; font-family: Helvetica, Arial, sans-serif; color: #333 !important; margin: 0px;">Новинки</h3>
						<hr/>
						<table cellspacing="0" border="0" cellpadding="8" width="100%" style="margin-top: 10px;">
							<tbody><tr>
							<?php foreach ($latest_products as $latest_product) { ?>
								<td valign="top">
								<?php if ($latest_product['thumb']) { ?>
									<p style="font-size: 17px; line-height: 24px; font-family: Georgia, 'Times New Roman', Times, serif; color: #333; margin: 0px;"><a href="<?php echo $latest_product['href']; ?>"><img src="<?php echo $latest_product['thumb']; ?>" alt="<?php echo $latest_product['name']; ?>"  style="border: solid 1px #FFF; box-shadow: 2px 2px 6px #333;" /></a></p>
								<?php } ?>	
									<h4 style="font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: #333 !important; margin: 12px 0px;"><?php echo $latest_product['name']; ?></h4>
									<p style="font-size: 17px; line-height: 24px; font-family: Georgia, 'Times New Roman', Times, serif; color: #333; margin: 0px;"><?php echo $latest_product['price']; ?></p>
								</td>
							 <?php } ?>	
							</tr>
						</tbody></table>
					</td>
				</tr>
			</tbody></table>
			
			<table cellspacing="0" border="0" cellpadding="0" width="624">
                                        <tbody><tr>
                                            <td/><hr/><hr/><td/>
                                        </tr>
            </tbody></table>			
			
		</div>	

 

 textarea в которую пишется текст рассылки присвоил id="cke"

ниже дописал кнопку вставки 

	<tr>
            <td><span class="required">*</span>Добавить новинки к письму</td>
            <td><a class="button" id="insertkod">Insert</a></td>
          </tr>

 

и скрипт 

<script type="text/javascript">
	html = $('#kod').html();

	$('#insertkod').bind('click', function(){		
	CKEDITOR.instances.cke.insertHtml(html);	
	})
</script>

 

Результат, по клику на кнопку товары добавляются в скедитор.

 

post-7225-0-20460600-1366200622_thumb.png

 

все ок

Но вот почему только порядок не соответствует указанной сортировке,

 

'sort' => 'p.date_added',

'order' => 'DESC',

 

 не пойму

 

Если сортировать по цене или названию - все ок , по дате не получается

Share this post


Link to post
Share on other sites

Спасибо Yoda за помощь,

в моделе товара в getProducts нужно добавить  'p.date_added',

$sort_data = array(
				'pd.name',
				'p.model',
				'p.price',
				'p.date_added',
				'p.quantity',
				'p.status',
				'p.sort_order'
			);	

Share this post


Link to post
Share on other sites

Помогите доделать рассылку новых товаров через стандартные опенкартовские рассылки.

 

В контроллер рассылок admin/controller/sale/contact.php

		//Latest
		
					$this->load->model('catalog/product');
					
					$this->load->model('tool/image');
					
					$latest_data = array(
						'sort'  => 'p.date_added',
						'order' => 'DESC',
						'start' => 0,
						'limit' => 4
					);

					$results = $this->model_catalog_product->getProducts($latest_data);

					foreach ($results as $result) {
						if ($result['image']) {
							$image = $this->model_tool_image->resize($result['image'], 138, 138);
						} else {
							$image = false;
						}
									

						$price = $this->currency->format($result['price']);
								
						
						$this->data['latest_products'][] = array(
							'product_id' => $result['product_id'],
							'thumb'   	 => $image,
							'name'    	 => $result['name'],
							'date'    	 => $result['date_added'],
							'price'   	 => $price,
							'href'    	 => str_replace('/admin/', '/catalog/', $this->url->link('product/product', 'product_id=' . $result['product_id'])),
						);
					}
		//Latest	

В шаблон /admin/view/template/sale/contact.tpl

		<div id="kod" style="display: none ;">
		<h1>Рассылка магазина</h1>
			<table cellspacing="0" border="0" cellpadding="0" width="624">
				<tbody><tr>
					<td>
						<h3 style="font-size: 24px; font-family: Helvetica, Arial, sans-serif; color: #333 !important; margin: 0px;">Новинки</h3>
						<hr/>
						<table cellspacing="0" border="0" cellpadding="8" width="100%" style="margin-top: 10px;">
							<tbody><tr>
							<?php foreach ($latest_products as $latest_product) { ?>
								<td valign="top">
								<?php if ($latest_product['thumb']) { ?>
									<p style="font-size: 17px; line-height: 24px; font-family: Georgia, 'Times New Roman', Times, serif; color: #333; margin: 0px;"><a href="<?php echo $latest_product['href']; ?>"><img src="<?php echo $latest_product['thumb']; ?>" alt="<?php echo $latest_product['name']; ?>"  style="border: solid 1px #FFF; box-shadow: 2px 2px 6px #333;" /></a></p>
								<?php } ?>	
									<h4 style="font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: #333 !important; margin: 12px 0px;"><?php echo $latest_product['name']; ?></h4>
									<p style="font-size: 17px; line-height: 24px; font-family: Georgia, 'Times New Roman', Times, serif; color: #333; margin: 0px;"><?php echo $latest_product['price']; ?></p>
								</td>
							 <?php } ?>	
							</tr>
						</tbody></table>
					</td>
				</tr>
			</tbody></table>
			
			<table cellspacing="0" border="0" cellpadding="0" width="624">
                                        <tbody><tr>
                                            <td/><hr/><hr/><td/>
                                        </tr>
            </tbody></table>			
			
		</div>	

 textarea в которую пишется текст рассылки присвоил id="cke"

ниже дописал кнопку вставки 

	<tr>
            <td><span class="required">*</span>Добавить новинки к письму</td>
            <td><a class="button" id="insertkod">Insert</a></td>
          </tr>

и скрипт 

<script type="text/javascript">
	html = $('#kod').html();

	$('#insertkod').bind('click', function(){		
	CKEDITOR.instances.cke.insertHtml(html);	
	})
</script>

Результат, по клику на кнопку товары добавляются в скедитор.

 

attachicon.gifScreenshot_1.png

 

все ок

Но вот почему только порядок не соответствует указанной сортировке,

 

'sort' => 'p.date_added',

'order' => 'DESC',

 

 не пойму

 

Если сортировать по цене или названию - все ок , по дате не получается

куда это вставлять в файле admin/view/template/sale/contact.tpl   ?

вот мой файл contact.tpl

<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/mail.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a id="button-send" onclick="send('index.php?route=sale/contact/send&token=<?php echo $token; ?>');" class="button"><?php echo $button_send; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
        <table id="mail" class="form">
          <tr>
            <td><?php echo $entry_store; ?></td>
            <td><select name="store_id">
                <option value="0"><?php echo $text_default; ?></option>
                <?php foreach ($stores as $store) { ?>
                <option value="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></option>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_to; ?></td>
            <td><select name="to">
                <option value="newsletter"><?php echo $text_newsletter; ?></option>
                <option value="customer_all"><?php echo $text_customer_all; ?></option>
                <option value="customer_group"><?php echo $text_customer_group; ?></option>
                <option value="customer"><?php echo $text_customer; ?></option>
                <option value="affiliate_all"><?php echo $text_affiliate_all; ?></option>
                <option value="affiliate"><?php echo $text_affiliate; ?></option>
                <option value="product"><?php echo $text_product; ?></option>
              </select></td>
          </tr>
          <tbody id="to-customer-group" class="to">
            <tr>
              <td><?php echo $entry_customer_group; ?></td>
              <td><select name="customer_group_id">
                  <?php foreach ($customer_groups as $customer_group) { ?>
                  <option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>
                  <?php } ?>
                </select></td>
            </tr>
          </tbody>
          <tbody id="to-customer" class="to">
            <tr>
              <td><?php echo $entry_customer; ?></td>
              <td><input type="text" name="customers" value="" /></td>
            </tr>
            <tr>
              <td> </td>
              <td><div id="customer" class="scrollbox"></div></td>
            </tr>
          </tbody>
          <tbody id="to-affiliate" class="to">
            <tr>
              <td><?php echo $entry_affiliate; ?></td>
              <td><input type="text" name="affiliates" value="" /></td>
            </tr>
            <tr>
              <td> </td>
              <td><div id="affiliate" class="scrollbox"></div></td>
            </tr>
          </tbody>
          <tbody id="to-product" class="to">
            <tr>
              <td><?php echo $entry_product; ?></td>
              <td><input type="text" name="products" value="" /></td>
            </tr>
            <tr>
              <td> </td>
              <td><div id="product" class="scrollbox"></div></td>
            </tr>
          </tbody>
          <tr>
            <td><span class="required">*</span> <?php echo $entry_subject; ?></td>
            <td><input type="text" name="subject" value="" /></td>
          </tr>
          <tr>
            <td><span class="required">*</span> <?php echo $entry_message; ?></td>
            <td><textarea name="message"></textarea></td>
          </tr>
        </table>
    </div>
  </div>
</div>
<script type="text/javascript" src="view/javascript/ckeditor/ckeditor.js"></script>
<script type="text/javascript"><!--
CKEDITOR.replace('message', {
	filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});
//--></script> 
<script type="text/javascript"><!--	
$('select[name=\'to\']').bind('change', function() {
	$('#mail .to').hide();
	
	$('#mail #to-' + $(this).attr('value').replace('_', '-')).show();
});

$('select[name=\'to\']').trigger('change');
//--></script> 
<script type="text/javascript"><!--
$.widget('custom.catcomplete', $.ui.autocomplete, {
	_renderMenu: function(ul, items) {
		var self = this, currentCategory = '';
		
		$.each(items, function(index, item) {
			if (item.category != currentCategory) {
				ul.append('<li class="ui-autocomplete-category">' + item.category + '</li>');
				
				currentCategory = item.category;
			}
			
			self._renderItem(ul, item);
		});
	}
});

$('input[name=\'customers\']').catcomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=sale/customer/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {	
				response($.map(json, function(item) {
					return {
						category: item.customer_group,
						label: item.name,
						value: item.customer_id
					}
				}));
			}
		});
		
	}, 
	select: function(event, ui) {
		$('#customer' + ui.item.value).remove();
		
		$('#customer').append('<div id="customer' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" alt="" /><input type="hidden" name="customer[]" value="' + ui.item.value + '" /></div>');

		$('#customer div:odd').attr('class', 'odd');
		$('#customer div:even').attr('class', 'even');
				
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('#customer div img').live('click', function() {
	$(this).parent().remove();
	
	$('#customer div:odd').attr('class', 'odd');
	$('#customer div:even').attr('class', 'even');	
});
//--></script> 
<script type="text/javascript"><!--	
$('input[name=\'affiliates\']').autocomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=sale/affiliate/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.affiliate_id
					}
				}));
			}
		});
		
	}, 
	select: function(event, ui) {
		$('#affiliate' + ui.item.value).remove();
		
		$('#affiliate').append('<div id="affiliate' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" alt="" /><input type="hidden" name="affiliate[]" value="' + ui.item.value + '" /></div>');

		$('#affiliate div:odd').attr('class', 'odd');
		$('#affiliate div:even').attr('class', 'even');
				
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('#affiliate div img').live('click', function() {
	$(this).parent().remove();
	
	$('#affiliate div:odd').attr('class', 'odd');
	$('#affiliate div:even').attr('class', 'even');	
});

$('input[name=\'products\']').autocomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.product_id
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('#product' + ui.item.value).remove();
		
		$('#product').append('<div id="product' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" alt="" /><input type="hidden" name="product[]" value="' + ui.item.value + '" /></div>');

		$('#product div:odd').attr('class', 'odd');
		$('#product div:even').attr('class', 'even');
				
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('#product div img').live('click', function() {
	$(this).parent().remove();
	
	$('#product div:odd').attr('class', 'odd');
	$('#product div:even').attr('class', 'even');	
});

function send(url) { 
	$('textarea[name="message"]').val(CKEDITOR.instances.message.getData());
	
	$.ajax({
		url: url,
		type: 'post',
		data: $('select, input, textarea'),		
		dataType: 'json',
		beforeSend: function() {
			$('#button-send').attr('disabled', true);
			$('#button-send').before('<span class="wait"><img src="view/image/loading.gif" alt="" /> </span>');
		},
		complete: function() {
			$('#button-send').attr('disabled', false);
			$('.wait').remove();
		},				
		success: function(json) {
			$('.success, .warning, .error').remove();
			
			if (json['error']) {
				if (json['error']['warning']) {
					$('.box').before('<div class="warning" style="display: none;">' + json['error']['warning'] + '</div>');
			
					$('.warning').fadeIn('slow');
				}
				
				if (json['error']['subject']) {
					$('input[name=\'subject\']').after('<span class="error">' + json['error']['subject'] + '</span>');
				}	
				
				if (json['error']['message']) {
					$('textarea[name=\'message\']').parent().append('<span class="error">' + json['error']['message'] + '</span>');
				}									
			}			
			
			if (json['next']) {
				if (json['success']) {
					$('.box').before('<div class="success">' + json['success'] + '</div>');
					
					send(json['next']);
				}		
			} else {
				if (json['success']) {
					$('.box').before('<div class="success" style="display: none;">' + json['success'] + '</div>');
			
					$('.success').fadeIn('slow');
				}					
			}				
		}
	});
}
//--></script> 
<?php echo $footer; ?>

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.

Sign in to follow this  

  • 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.