cms = 'Joomla';
if (!defined('JPATH_ADMINISTRATOR') || !file_exists(rtrim(JPATH_ADMINISTRATOR, DS).DS.'components'.DS.'com_hikashop'.DS)) {
$this->installed = false;
}
$this->name = 'hikashop';
}
public function insertOptions()
{
$plugin = new stdClass();
$plugin->name = 'HikaShop';
$plugin->icon = ACYM_DYNAMICS_URL.basename(__DIR__).'/icon.ico';
$plugin->plugin = __CLASS__;
return $plugin;
}
public function contentPopup()
{
acym_loadLanguageFile('com_hikashop', JPATH_SITE);
$this->categories = acym_loadObjectList("SELECT category_id AS id, category_parent_id AS parent_id, category_name AS title FROM `#__hikashop_category` WHERE category_type = 'product'", 'id');
$tabHelper = acym_get('helper.tab');
$tabHelper->startTab(acym_translation('ACYM_ONE_BY_ONE'));
$displayOptions = [
[
'title' => 'ACYM_DISPLAY',
'type' => 'radio',
'name' => 'type',
'options' => [
'title' => 'ACYM_TITLE_ONLY',
'intro' => 'ACYM_INTRO_ONLY',
'full' => 'ACYM_FULL_TEXT',
],
'default' => 'full',
],
[
'title' => 'ACYM_PRICE',
'type' => 'radio',
'name' => 'price',
'options' => [
'full' => 'ACYM_APPLY_DISCOUNTS',
'no_discount' => 'ACYM_NO_DISCOUNT',
'none' => 'ACYM_NO',
],
'default' => 'full',
],
];
echo $this->acympluginHelper->displayOptions($displayOptions, $this->name);
echo $this->getFilteringZone();
$this->displayListing();
$tabHelper->endTab();
$tabHelper->startTab(acym_translation('ACYM_BY_CATEGORY'));
$catOptions = [
[
'title' => 'ACYM_ORDER_BY',
'type' => 'select',
'name' => 'order',
'options' => [
'product_id' => 'ACYM_ID',
'product_created' => 'ACYM_DATE_CREATED',
'product_modified' => 'ACYM_MODIFICATION_DATE',
'product_name' => 'ACYM_TITLE',
'rand' => 'ACYM_RANDOM',
],
],
[
'title' => 'ACYM_COLUMNS',
'type' => 'text',
'name' => 'cols',
'default' => 1,
],
[
'title' => 'ACYM_MAX_NB_ELEMENTS',
'type' => 'text',
'name' => 'max',
'default' => 20,
],
];
$displayOptions = array_merge($displayOptions, $catOptions);
echo $this->acympluginHelper->displayOptions($displayOptions, 'auto'.$this->name, 'grouped');
echo $this->getCategoryListing();
$tabHelper->endTab();
$tabHelper->startTab(acym_translation('HIKA_ABANDONED_CART'));
$methods = acym_loadObjectList('SELECT payment_id, payment_name FROM #__hikashop_payment', 'payment_id');
$paymentMethods = ['' => 'ALL_PAYMENT_METHODS'];
foreach ($methods as $method) {
$paymentMethods[$method->payment_id] = $method->payment_name;
}
$displayOptions = [
[
'title' => 'ACYM_DISPLAY',
'type' => 'radio',
'name' => 'type',
'options' => [
'title' => 'ACYM_TITLE_ONLY',
'intro' => 'ACYM_INTRO_ONLY',
'full' => 'ACYM_FULL_TEXT',
],
'default' => 'full',
],
[
'title' => 'PAYMENT_METHOD',
'type' => 'select',
'name' => 'paymentcart',
'options' => $paymentMethods,
],
[
'title' => 'ACYM_DATE_CREATED',
'type' => 'intextfield',
'name' => 'nbdayscart',
'text' => 'DAYS_AFTER_ORDERING',
'default' => 1,
],
];
echo $this->acympluginHelper->displayOptions($displayOptions, 'hikashop_abandonedcart', 'simple');
$tabHelper->endTab();
$tabHelper->startTab(acym_translation('ACYM_COUPON'));
$query = "SELECT `product_id`, CONCAT(product_name, ' ( ', product_code, ' )') AS `title`
FROM #__hikashop_product
WHERE `product_type`='main' AND `product_published` = 1
ORDER BY `product_code` ASC";
$results = acym_loadObjectList($query);
$products = [0 => 'ACYM_NONE'];
foreach ($results as $result) {
$products[$result->product_id] = $result->title;
}
$parent = acym_loadResult('SELECT category_id FROM #__hikashop_category WHERE category_parent_id = 0');
$query = 'SELECT a.category_id, a.category_name
FROM #__hikashop_category AS a
WHERE a.category_type = "tax"
AND a.category_published = 1
AND a.category_parent_id != '.intval($parent).'
ORDER BY a.category_ordering ASC';
$results = acym_loadObjectList($query);
$taxes = [0 => 'ACYM_NONE'];
foreach ($results as $result) {
$taxes[$result->category_id] = $result->category_name;
}
$query = 'SELECT currency_id AS value, CONCAT(currency_symbol, " ", currency_code) AS text FROM #__hikashop_currency WHERE currency_published = 1';
$currencies = acym_loadObjectList($query);
$displayOptions = [
[
'title' => 'DISCOUNT_CODE',
'type' => 'text',
'name' => 'code',
'default' => '[name][key][value]',
'class' => 'acym_plugin__larger_text_field',
'large' => true,
],
[
'title' => 'DISCOUNT_FLAT_AMOUNT',
'type' => 'custom',
'name' => 'flat',
'output' => '
'.acym_select($currencies, 'currencyhikashop_coupon', null, 'onchange="updateDynamichikashop_coupon();" style="width: 80px;"'),
'js' => 'otherinfo += "| flat:" + jQuery(\'input[name="flathikashop_coupon"]\').val();
otherinfo += "| currency:" + jQuery(\'[name="currencyhikashop_coupon"]\').val();',
],
[
'title' => 'DISCOUNT_PERCENT_AMOUNT',
'type' => 'text',
'name' => 'percent',
'default' => '0',
],
[
'title' => 'DISCOUNT_START_DATE',
'type' => 'date',
'name' => 'start',
'default' => '',
],
[
'title' => 'DISCOUNT_END_DATE',
'type' => 'date',
'name' => 'end',
'default' => '',
],
[
'title' => 'MINIMUM_ORDER_VALUE',
'type' => 'text',
'name' => 'min',
'default' => '0',
],
[
'title' => 'DISCOUNT_QUOTA',
'type' => 'text',
'name' => 'quota',
'default' => '',
],
[
'title' => 'PRODUCT',
'type' => 'select',
'name' => 'product',
'options' => $products,
'default' => '0',
],
[
'title' => 'TAXATION_CATEGORY',
'type' => 'select',
'name' => 'tax',
'options' => $taxes,
'default' => '0',
],
];
echo $this->acympluginHelper->displayOptions($displayOptions, 'hikashop_coupon', 'simple');
$tabHelper->endTab();
$tabHelper->display('plugin');
}
public function displayListing()
{
$query = 'SELECT SQL_CALC_FOUND_ROWS a.* FROM #__hikashop_product AS a ';
$filters = [];
$this->pageInfo = new stdClass();
$this->pageInfo->limit = acym_getCMSConfig('list_limit');
$this->pageInfo->page = acym_getVar('int', 'pagination_page_ajax', 1);
$this->pageInfo->start = ($this->pageInfo->page - 1) * $this->pageInfo->limit;
$this->pageInfo->search = acym_getVar('string', 'plugin_search', '');
$this->pageInfo->filter_cat = acym_getVar('int', 'plugin_category', 0);
$this->pageInfo->order = 'a.product_id';
$this->pageInfo->orderdir = 'DESC';
$searchFields = ['a.product_id', 'a.product_name', 'a.product_code'];
if (!empty($this->pageInfo->search)) {
$searchVal = '%'.acym_getEscaped($this->pageInfo->search, true).'%';
$filters[] = implode(" LIKE ".acym_escapeDB($searchVal)." OR ", $searchFields)." LIKE ".acym_escapeDB($searchVal);
}
if (!empty($this->pageInfo->filter_cat)) {
$query .= 'JOIN #__hikashop_product_category AS b ON a.product_id = b.product_id';
$filters[] = "b.category_id = ".intval($this->pageInfo->filter_cat);
}
if (!empty($filters)) {
$query .= ' WHERE ('.implode(') AND (', $filters).')';
}
if (!empty($this->pageInfo->order)) {
$query .= ' ORDER BY '.acym_secureDBColumn($this->pageInfo->order).' '.acym_secureDBColumn($this->pageInfo->orderdir);
}
$rows = acym_loadObjectList($query, '', $this->pageInfo->start, $this->pageInfo->limit);
$this->pageInfo->total = acym_loadResult('SELECT FOUND_ROWS()');
$listingOptions = [
'header' => [
'product_name' => [
'label' => 'ACYM_TITLE',
'size' => '7',
],
'product_created' => [
'label' => 'ACYM_DATE_CREATED',
'size' => '4',
'type' => 'date',
],
'product_id' => [
'label' => 'ACYM_ID',
'size' => '1',
'class' => 'text-center',
],
],
'id' => 'product_id',
'rows' => $rows,
];
echo $this->getElementsListing($listingOptions);
}
public function replaceContent(&$email)
{
$this->_replaceAuto($email);
$this->_replaceOne($email);
}
public function _replaceAuto(&$email)
{
$this->generateByCategory($email);
if (empty($this->tags)) {
return;
}
$this->acympluginHelper->replaceTags($email, $this->tags, true);
}
public function generateByCategory(&$email)
{
$tags = $this->acympluginHelper->extractTags($email, 'auto'.$this->name);
$return = new stdClass();
$return->status = true;
$return->message = '';
$this->tags = [];
if (empty($tags)) {
return $return;
}
foreach ($tags as $oneTag => $parameter) {
if (isset($this->tags[$oneTag])) continue;
$allcats = explode('-', $parameter->id);
$selectedArea = [];
foreach ($allcats as $oneCat) {
if (empty($oneCat)) continue;
$selectedArea[] = intval($oneCat);
}
$query = 'SELECT DISTINCT b.`product_id` FROM #__hikashop_product_category AS a
LEFT JOIN #__hikashop_product AS b ON a.product_id = b.product_id';
$where = [];
if (!empty($selectedArea)) {
$where[] = 'a.category_id IN ('.implode(',', $selectedArea).')';
}
$where[] = "b.`product_published` = 1";
if (!empty($parameter->filter) && !empty($email->params['lastgenerateddate'])) {
$condition = 'b.`product_created` > '.acym_escapeDB($email->params['lastgenerateddate']);
if ($parameter->filter == 'modify') {
$condition .= ' OR b.`product_modified` > '.acym_escapeDB($email->params['lastgenerateddate']);
}
$where[] = $condition;
}
$query .= ' WHERE ('.implode(') AND (', $where).')';
if (!empty($parameter->order)) {
$ordering = explode(',', $parameter->order);
if ($ordering[0] == 'rand') {
$query .= ' ORDER BY rand()';
} else {
$query .= ' ORDER BY b.`'.acym_secureDBColumn(trim($ordering[0])).'` '.acym_secureDBColumn(trim($ordering[1]));
}
}
if (!empty($parameter->max)) {
$query .= ' LIMIT '.intval($parameter->max);
}
$allArticles = acym_loadResultArray($query);
if (!empty($parameter->min) && count($allArticles) < $parameter->min) {
$return->status = false;
$return->message = 'Not enough products for the tag '.$oneTag.' : '.count($allArticles).' / '.$parameter->min;
}
$this->tags[$oneTag] = $this->finalizeCategoryFormat($this->name, $allArticles, $parameter);
}
return $return;
}
private function _replaceOne(&$email)
{
$tags = $this->acympluginHelper->extractTags($email, $this->name);
if (empty($tags)) return;
$this->readmore = empty($email->template->readmore) ? JText::_('ACYM_READ_MORE') : '';
if (!include_once(rtrim(JPATH_ADMINISTRATOR, DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return;
$this->hikaConfig = hikashop_config();
$this->productClass = hikashop_get('class.product');
$this->imageHelper = hikashop_get('helper.image');
$this->currencyClass = hikashop_get('class.currency');
$this->translationHelper = hikashop_get('helper.translation');
$tagsReplaced = [];
foreach ($tags as $i => $oneTag) {
if (isset($tagsReplaced[$i])) continue;
$tagsReplaced[$i] = $this->_replaceContent($oneTag, $email);
}
$this->acympluginHelper->replaceTags($email, $tagsReplaced, true);
}
public function _replaceContent($tag, &$email)
{
if (empty($tag->lang) && !empty($email->language)) {
$tag->lang = $email->language;
}
$query = 'SELECT b.*, a.*
FROM #__hikashop_product AS a
LEFT JOIN #__hikashop_file AS b ON a.product_id = b.file_ref_id AND file_type = "product"
WHERE a.product_id = '.intval($tag->id).'
ORDER BY b.file_ordering ASC, b.file_id ASC';
$product = acym_loadObject($query);
if (empty($product)) {
if (acym_isAdmin()) {
acym_enqueueMessage('The product "'.$tag->id.'" could not be loaded', 'notice');
}
return '';
}
if ($product->product_type == 'variant') {
$query = 'SELECT *
FROM #__hikashop_variant AS a
LEFT JOIN #__hikashop__characteristic AS b ON a.variant_characteristic_id = b.characteristic_id
WHERE a.variant_product_id = '.intval($tag->id).'
ORDER BY a.ordering';
$product->characteristics = acym_loadObjectList($query);
$query = 'SELECT b.*, a.*
FROM #__hikashop_product AS a
LEFT JOIN #__hikashop_file AS b ON a.product_id = b.file_ref_id AND file_type = "product"
WHERE a.product_id = '.intval($product->product_parent_id).'
ORDER BY b.file_ordering ASC, b.file_id ASC';
$parentProduct = acym_loadObject($query);
$this->productClass->checkVariant($product, $parentProduct);
}
if ($this->translationHelper->isMulti(true, false)) {
$this->acympluginHelper->translateItem($product, $tag, 'hikashop_product');
}
$varFields = [];
foreach ($product as $fieldName => $oneField) {
$varFields['{'.$fieldName.'}'] = $oneField;
}
$tag->itemid = 0;
$main_currency = $currency_id = (int)$this->hikaConfig->get('main_currency', 1);
$zone_id = explode(',', $this->hikaConfig->get('main_tax_zone', 0));
$zone_id = count($zone_id) ? array_shift($zone_id) : 0;
$ids = [$product->product_id];
$discount_before_tax = (int)$this->hikaConfig->get('discount_before_tax', 0);
$this->currencyClass->getPrices($product, $ids, $currency_id, $main_currency, $zone_id, $discount_before_tax);
$finalPrice = '';
if (empty($tag->price) || $tag->price == 'full') {
$finalPrice = @$this->currencyClass->format($product->prices[0]->price_value_with_tax, $product->prices[0]->price_currency_id);
if (!empty($product->discount)) {
$finalPrice = ''.$this->currencyClass->format($product->prices[0]->price_value_without_discount_with_tax, $product->prices[0]->price_currency_id).' '.$finalPrice;
}
} elseif ($tag->price == 'no_discount') {
$finalPrice = $this->currencyClass->format($product->prices[0]->price_value_without_discount_with_tax, $product->prices[0]->price_currency_id);
}
$varFields['{finalPrice}'] = $finalPrice;
if (empty($tag->type) || $tag->type == 'full') {
$description = $product->product_description;
} else {
$pos = strpos($product->product_description, '