Commit ad6a27e0 authored by Batyr Mackenov's avatar Batyr Mackenov

Minor fixes

parent 98e367e4
......@@ -3,57 +3,50 @@
class iaProduct extends abstractModuleAdmin
{
const STATUS_OUT_OF_STOCK = 'out_of_stock';
const STATUS_OUT_OF_STOCK = 'out_of_stock';
protected static $_table = 'products';
protected static $_table = 'products';
protected $_moduleName = 'commerce';
protected $_moduleName = 'commerce';
protected $_itemName = 'products';
protected $_itemName = 'products';
protected $_statuses = [iaCore::STATUS_ACTIVE, self::STATUS_OUT_OF_STOCK, iaCore::STATUS_INACTIVE];
protected $_statuses = [iaCore::STATUS_ACTIVE, self::STATUS_OUT_OF_STOCK, iaCore::STATUS_INACTIVE];
public $dashboardStatistics = ['icon' => 'cart'];
public $dashboardStatistics = ['icon' => 'cart'];
protected function getUrl(array $entryData)
{
$base = $this->getInfo('url');
protected function getUrl(array $entryData)
{
$base = $this->getInfo('url');
$category = empty($entryData['category_slug']) ? '' : $entryData['category_slug'];
$path = $category . $entryData['slug'];
return $base . $path . '.html';
}
public function getSitemapEntries()
{
$stmt = ":table`status` != ':status' AND :table`description` != ''";
$sql = 'SELECT p.`alias`, c.`url` `category_alias` '
. 'FROM `:table_products` p '
. 'LEFT JOIN `:table_categories` c ON (p.`category_id` = c.`id`) '
. 'WHERE :where '
. 'ORDER BY p.`title ';
$this->iaCore->loadClass('common', 'category', $this->getModuleName());
$stmt = iaDb::printf($stmt, ['table' => 'p.', 'status' => iaCore::STATUS_INACTIVE]);
$sql = iaDb::printf($sql, ['table_products' => self::getTable(true), 'table_categories' => iaCategory::getTable(true), 'where' => $stmt]);
$rows = $this->iaDb->getAll($sql);
$result = [];
if ($rows)
{
foreach ($rows as $row)
{
$result[] = $this->getUrl($row);
}
}
return $base . $path . '.html';
}
return $result;
public function getSitemapEntries()
{
$sql = 'SELECT p.`slug`, c.`slug` `category_slug` '
. 'FROM `:table_products` p '
. 'LEFT JOIN `:table_categories` c ON (p.`category_id` = c.`id`) '
. 'WHERE p.`status` != "hidden" '
. 'ORDER BY p.`title ';
$sql = iaDb::printf($sql, [
'table_products' => self::getTable(true),
'table_categories' => $this->iaDb->prefix . 'categories'
]);
$result = [];
if ($rows = $this->iaDb->getAll($sql)) {
foreach ($rows as $row) {
$result[] = $this->getUrl($row);
}
}
return $result;
}
public function getTreeVars(array $entryData)
......
......@@ -6,7 +6,7 @@ class iaNotification extends abstractCore
protected static $_moduleName = 'commerce';
public function send($eventType, $data, $data2 = null)
public function send($notificationType, $data, $data2 = null)
{
$emailsOptions = [
'order_placed' => true
......@@ -16,27 +16,19 @@ class iaNotification extends abstractCore
$addressee = [];
$result = true;
if (!$this->iaCore->get(self::$_moduleName . '_' . $eventType))
{
$iaMailer = $this->iaCore->factory('mailer');
if (!$iaMailer->loadTemplate(self::$_moduleName . '_' . $notificationType)) {
return $result;
}
$iaMailer = $this->iaCore->factory('mailer');
switch ($eventType)
switch ($notificationType)
{
case 'order_placed':
$addressee[$data['buyer_email']] = $data['buyer_name'];
$params['order'] = $data;
$params['items'] = $this->iaCore->factoryModule('order', self::$_moduleName)->getItemsByOrderId($data['id']);
}
if ($emailsOptions[$eventType]) {
$iaMailer->loadTemplate(self::$_moduleName . '_' . $eventType . '_admin');
$iaMailer->Body = self::_fetchEmailTemplate($eventType, $params, true);
$result = $iaMailer->sendToAdministrators(true);
$params['products'] = $this->iaCore->factoryModule('order', self::$_moduleName)->getItemsByOrderId($data['id']);
}
if (!$addressee) {
......@@ -47,47 +39,19 @@ class iaNotification extends abstractCore
$iaMailer->addAddress($emailAddress, $title);
}
$iaMailer->loadTemplate(self::$_moduleName . '_' . $eventType);
$iaMailer->Body = self::_fetchEmailTemplate($eventType, $params);
return ($result && $iaMailer->send());
}
private static function _fetchEmailTemplate($templateName, array $params, $useBackendTemplate = false)
{
static $iaSmarty;
if (is_null($iaSmarty)) {
$iaCore = iaCore::instance();
$iaSmarty = $iaCore->iaView->iaSmarty;
$iaSmarty->assign('nonProtocolUrl', $iaCore->iaView->assetsUrl);
$iaSmarty->assign('img', IA_TPL_URL . 'img/');
$iaSmarty->assign('core', [
'config' => $iaCore->getConfig()
]);
foreach ($params as $param => $value) {
$iaMailer->setReplacements($param, $value);
}
foreach ($params as $key => $value) {
$iaSmarty->assign($key, $value);
}
$result = $iaMailer->send();
$templateName = 'email.' . ($useBackendTemplate ? 'admin.' : '') . $templateName;
if ($emailsOptions[$notificationType]) {
$iaMailer->loadTemplate(self::$_moduleName . '_' . $notificationType . '_admin');
$iaMailer->setReplacements($params);
return self::_compileLayout($iaSmarty, $iaSmarty->fetch('extra:' . self::$_moduleName . '/' . $templateName), $useBackendTemplate);
}
private static function _compileLayout(&$smarty, $content, $useBackendTemplate)
{
$iaCore = iaCore::instance();
$smarty->assign('_content_', $content);
$smarty->assign('defaultEmailSignature', str_replace(['{%SITE_URL%}', '{%SITE_NAME%}'],
[IA_URL, $iaCore->get('site')], $iaCore->get('default_email_signature')));
$result = $iaMailer->sendToAdministrators(true);
}
$layoutFile = 'extra:' . self::$_moduleName . '/email'. ($useBackendTemplate ? '.admin' : '') . '.layout';
//header('Content-type: text/html; charset=utf8');die($smarty->fetch($layoutFile));
return $smarty->fetch($layoutFile);
return $result;
}
}
\ No newline at end of file
......@@ -62,13 +62,115 @@
<config group="commerce" name="commerce_products_per_page" type="text" description="Products per page">20</config>
<config group="commerce" name="commerce_featured_products_limit" type="text" description="Products in 'Featured Products' block" private="1">10</config>
<config group="commerce" name="commerce_priority_categories_limit" type="text" description="Categories in 'Priority Categories' block">10</config>
<config group="email_templates" type="divider" description="Commerce" private="1"><![CDATA[]]></config>
<config group="email_templates" name="commerce_order_placed" type="radio" values="1,0" description="New order placed">1</config>
<config group="email_templates" name="commerce_order_placed_subject" type="hidden">Thank you for your order at {%SITE_NAME%}!</config>
<config group="email_templates" name="commerce_order_placed_body" type="hidden"><![CDATA[]]></config>
<config group="email_templates" name="commerce_order_placed_admin" type="radio" values="1,0" description="New order placed - notification to administrators">1</config>
<config group="email_templates" name="commerce_order_placed_admin_subject" type="hidden">New order</config>
<config group="email_templates" name="commerce_order_placed_admin_body" type="hidden"><![CDATA[]]></config>
<emails>
<email name="commerce_divider" description="Commerce" divider="1"><![CDATA[]]></email>
<email name="commerce_order_placed"
description="New order placed"
subject="Thank you for your order at {$siteName}!">
<![CDATA[
<span class="pull-right small muted">{'F j, Y H:i'|date:strtotime($order.date_added)}</span>
<h1>Order #{$order.id}</h1>
<p>Thank you for your order!</p>
<hr>
<p>
Phone: {$order.buyer_phone}<br>
Email: {$order.buyer_email}
</p>
<div class="row">
<div class="tile long first">
<h2>Buyer</h2>
<p class="lead no-bottom-margin">{$order.buyer_name}</p>
</div>
<div class="tile">
<h2>Payment</h2>
<p class="lead no-bottom-margin">{$order.total} {$core.config.currency}</p>
</div>
</div>
<table class="table">
<tr>
<th class="text-left">Product</th>
<th width="50">Qty</th>
<th class="text-right">Price</th>
</tr>
{foreach $products as $item}
<tr>
<td>{$item.title}</td>
<td class="text-center">{$item.qty}</td>
<td class="text-right">{$item.price_total|number_format} {$core.config.currency}</td>
</tr>
{/foreach}
</table>
<div class="row well text-right">
<strong>Total Amount: {$order.total}</strong>
</div>
]]>
</email>
<email name="commerce_order_placed_admin"
description="New order placed - notification to administrators"
subject="New order">
<![CDATA[
<span class="pull-right muted small">{'F j, Y H:i'|date:strtotime($order.date_added)}</span>
<h1>Order #{$order.id}</h1>
<p>Cheers! New order has been placed on the site.</p>
<hr>
<h2>Order Details</h2>
<table class="table">
<tr>
<td width="120"><strong>Buyer</strong></td>
<td>{$order.buyer_name}</td>
</tr>
<tr>
<td></td>
<td>
{$order.buyer_email}<br>
{$order.buyer_phone}<br>
</td>
</tr>
{if $order.comment}
<tr>
<td><strong>Comment</strong></td>
<td>{$order.comment|nl2br}</td>
</tr>
{/if}
<tr>
<td><strong>Total</strong></td>
<td>Total: {$order.total}</td>
</tr>
</table>
<h2>Products Ordered</h2>
<table class="table">
<tr>
<th class="text-left">Product</th>
<th>Price</th>
<th>Qty</th>
<th class="text-right">Subtotal</th>
</tr>
{foreach $products as $item}
<tr>
<td>{$item.title}</td>
<td>{$item.price}</td>
<td width="90" class="text-center">{$item.qty}</td>
<td class="text-right">{$item.price_total}</td>
</tr>
{/foreach}
</table>
<div class="row well text-right"><strong>Total: {$order.total}</strong></div>
]]>
</email>
</emails>
<fields_groups>
<group item="products" name="general" title="General"><![CDATA[]]></group>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment