Commit 6e1c4444 authored by Vasily Bezruchkin's avatar Vasily Bezruchkin

Merge branch 'develop' into 'master'

Develop

See merge request !4
parents f3374a21 ba8b58ab
......@@ -107,6 +107,7 @@ class iaBackendController extends iaAbstractControllerModuleBackend
protected function _setDefaultValues(array &$entry)
{
$entry = [
'member_id' => iaUsers::getIdentity()->id,
'category_id' => 0,
'date_added' => date(iaDb::DATETIME_SHORT_FORMAT),
'slug' => '',
......
<?php
/******************************************************************************
*
* Subrion E-commerce Software
* Copyright (C) 2017 Intelliants, LLC <https://intelliants.com>
*
* This file is part of Subrion E-commerce Software.
*
* This program is a commercial software and any kind of using it must agree
* to the license, see <https://subrion.pro/license.html>.
*
* This copyright notice may not be removed from the software source without
* the permission of Subrion respective owners.
*
*
******************************************************************************/
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
if (1 != count($iaCore->requestPath)) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
$iaCurrency = $iaCore->factoryModule('currency', IA_CURRENT_MODULE);
$iaCurrency->set($iaCore->requestPath[0]);
$redirectUrl = isset($_SERVER['HTTP_REFERER'])
? $_SERVER['HTTP_REFERER']
: IA_URL;
iaUtil::go_to($redirectUrl);
}
\ No newline at end of file
......@@ -17,6 +17,7 @@
class iaProduct extends abstractModuleAdmin
{
const STATUS_HIDDEN = 'hidden';
const STATUS_OUT_OF_STOCK = 'out_of_stock';
protected static $_table = 'products';
......@@ -25,7 +26,7 @@ class iaProduct extends abstractModuleAdmin
protected $_itemName = 'products';
protected $_statuses = [iaCore::STATUS_ACTIVE, self::STATUS_OUT_OF_STOCK, iaCore::STATUS_INACTIVE];
protected $_statuses = [iaCore::STATUS_ACTIVE, iaCore::STATUS_APPROVAL, self::STATUS_OUT_OF_STOCK, self::STATUS_HIDDEN, iaCore::STATUS_INACTIVE];
public $dashboardStatistics = ['icon' => 'cart'];
......
......@@ -157,7 +157,7 @@ class iaCart extends abstractModuleFront
return [];
}
$iaCategory = $this->iaCore->factoryModule('category', $this->getModuleName(), 'common');
$iaCategory = $this->iaCore->factoryModule('category', $this->getModuleName());
$iaProduct = $this->iaCore->factoryModule('product', $this->getModuleName());
$sql = 'SELECT '
......
......@@ -17,6 +17,9 @@
class iaCategory extends iaAbstractFrontHelperCategoryFlat
{
const COUNTER_ACTION_INCREMENT = '+';
const COUNTER_ACTION_DECREMENT = '-';
protected static $_table = 'categories';
protected $_itemName = 'categories';
......@@ -42,10 +45,9 @@ class iaCategory extends iaAbstractFrontHelperCategoryFlat
return $this->getUrl($data);
}
// TODO: make it work
public function coreSearch($stmt, $start, $limit, $order)
{
$rows = $this->getAll($stmt, null, $start, $limit);
$rows = $this->getAll($stmt, iaDb::STMT_CALC_FOUND_ROWS . $stmt, $start, $limit);
$count = $this->getFoundRows();
return [$count, $rows];
......@@ -59,6 +61,29 @@ class iaCategory extends iaAbstractFrontHelperCategoryFlat
return $this->getOne($where);
}
public function recount(array $newData, array $oldData)
{
if (!isset($newData['status'])) {
return;
}
if (isset($oldData['status'])) {
if ($newData['status'] == iaCore::STATUS_ACTIVE && $oldData['status'] != iaCore::STATUS_ACTIVE) {
$this->_editCounter($newData['category_id'], self::COUNTER_ACTION_INCREMENT);
} elseif ($oldData['status'] == iaCore::STATUS_ACTIVE && $newData['status'] != iaCore::STATUS_ACTIVE) {
$this->_editCounter($oldData['category_id'], self::COUNTER_ACTION_DECREMENT);
} elseif ($newData['status'] == iaCore::STATUS_ACTIVE && $oldData['status'] == iaCore::STATUS_ACTIVE) {
if ($newData['category_id'] != $oldData['category_id']) {
$this->_editCounter($newData['category_id'], self::COUNTER_ACTION_INCREMENT);
$this->_editCounter($oldData['category_id'], self::COUNTER_ACTION_DECREMENT);
}
}
} else {
if ($newData['status'] == iaCore::STATUS_ACTIVE) {
$this->_editCounter($newData['category_id'], self::COUNTER_ACTION_INCREMENT);
}
}
}
public function getList()
{
......@@ -74,4 +99,54 @@ class iaCategory extends iaAbstractFrontHelperCategoryFlat
return $this->getAll($stmt, null, 0, $this->iaCore->get('commerce_priority_categories_limit'));
}
public function getParentsList($id, $additionalFields = false)
{
$result = [];
if (!$additionalFields) {
$result[] = (int)$id;
}
if ($categoryData = $this->getById($id)) {
$result[] = $additionalFields ? $categoryData : $categoryData['parent_id'];
while (isset($categoryData['parent_id'])) {
$categoryData = $this->getById($categoryData['parent_id']);
if (empty($categoryData)) {
break;
}
if ($additionalFields) {
$result[] = $categoryData;
} elseif ($categoryData['parent_id']) {
$result[] = (int)$categoryData['parent_id'];
}
}
}
$this->getRootId() == end($result) && array_pop($result);
return array_reverse(array_filter($result));
}
protected function _editCounter($categoryId, $action)
{
$parentsList = $this->getParentsList($categoryId);
if (empty($parentsList)) {
return false;
}
$parentsList = implode(',', $parentsList);
$sql = <<<SQL
UPDATE `:table` SET `num_listings` = IF((cast(`num_listings` AS signed) :action 1) < 0, 0, `num_listings` :action 1)
WHERE `id` IN (:categories)
SQL;
$sql = iaDb::printf($sql, [
'table' => self::getTable(true),
'action' => $action,
'categories' => $parentsList
]);
return $this->iaDb->query($sql);
}
}
\ No newline at end of file
......@@ -22,6 +22,9 @@ class iaProduct extends abstractModuleFront
const STATUS_HIDDEN = 'hidden';
const STATUS_OUT_OF_STOCK = 'out_of_stock';
const COLUMN_ID = 'id';
const COLUMN_URL = 'url';
protected static $_table = 'products';
protected $_itemName = 'products';
......@@ -54,19 +57,33 @@ class iaProduct extends abstractModuleFront
$this->_iaCategory = $this->iaCore->factoryModule('category', $this->getModuleName());
}
public function getUrl(array $item)
public function getUrl(array $data)
{
return $this->url('view', $data);
}
public function url($action, array $item, $relativeToRoot = false)
{
$base = $this->getInfo('url');
$patterns = [
'default' => ':action/:id/',
'view' => ':alias.html',
'my' => 'profile/commerce/'
];
$baseUrl = ('my' == $action) ? IA_URL : $this->getInfo('url');
$categorySlug = isset($item['category_slug']) ? $item['category_slug'] : '';
$productSlug = isset($item['slug']) ? $item['slug'] : '';
return $base . $categorySlug . $productSlug . '.html';
}
$uri = iaDb::printf(
isset($patterns[$action]) ? $patterns[$action] : $patterns['default'],
[
'action' => $action,
'alias' => $categorySlug . $productSlug,
'id' => isset($item[self::COLUMN_ID]) ? $item[self::COLUMN_ID] : ''
]
);
public function url($action, array $data)
{
return $this->getUrl($data);
return $baseUrl . $uri;
}
public function coreSearch($stmt, $start, $limit, $order)
......@@ -79,13 +96,14 @@ class iaProduct extends abstractModuleFront
public function getByCategory($categoryId, $start, $limit, $order)
{
$where = '';
$where = 'p.`status` != :approval';
$this->iaDb->bind($where, ['approval' => iaCore::STATUS_APPROVAL]);
if ($categoryId != $this->_iaCategory->getRootId()) {
$subQuery = sprintf('SELECT `child_id` FROM `%s` WHERE `parent_id` = %d',
$this->_iaCategory->getTableFlat(true), $categoryId);
$where = 'p.`category_id` IN (' . $subQuery . ')';
$where.= ' AND p.`category_id` IN (' . $subQuery . ')';
}
return $this->_get($where, $start, $limit, $order);
......@@ -103,19 +121,20 @@ class iaProduct extends abstractModuleFront
public function getById($id, $decorate = true)
{
if ($row = $this->_get('p.`id` = ' . (int)$id, 0, 1)) {
$row = $row[0];
}
$row = $this->_get('p.`id` = ' . (int)$id, 0, 1, null);
$decorate && $this->_processValues($row, true);
return $row ? $row[0] : false;
}
return $row;
public function getByMemberId($id, $start, $limit, $order)
{
return $this->_get('p.`member_id` = ' . (int)$id, $start, $limit, $order);
}
protected function _get($where = null, $start, $limit, $order = null)
{
$where || $where = iaDb::EMPTY_CONDITION;
$where .= ' AND p.`status` != :hidden';
$this->iaDb->bind($where, ['hidden' => self::STATUS_HIDDEN]);
if (!$order) {
......@@ -169,7 +188,11 @@ class iaProduct extends abstractModuleFront
$currency = $iaCurrency->get();
foreach ($rows as &$row) {
foreach ($rows as $key => &$row) {
if (iaUsers::hasIdentity() && $row['status'] == iaProduct::STATUS_HIDDEN && iaUsers::getIdentity()->id !== $row['member_id'] || !iaUsers::hasIdentity() && $row['status'] == iaProduct::STATUS_HIDDEN) {
unset($rows[$key]);
continue;
}
$row['price_formatted'] = $iaCurrency->format($row['price']);
$row['currency'] = $currency;
}
......@@ -213,6 +236,16 @@ class iaProduct extends abstractModuleFront
];
}
public function insert(array $itemData)
{
$itemData['date_added'] = date(iaDb::DATETIME_FORMAT);
$itemData['date_modified'] = date(iaDb::DATETIME_FORMAT);
$itemData['member_id'] = iaUsers::hasIdentity() ? iaUsers::getIdentity()->id : 0;
$itemId = parent::insert($itemData);
return $itemId;
}
public function getBlockFeatured()
{
......
......@@ -19,8 +19,10 @@ if ($iaView->url && 'commerce' == $iaCore->get('default_package')) {
switch ($iaView->get('extension')) {
case '.html':
// product
$stmt = '`slug` = :slug AND `status` != :status';
$iaDb->bind($stmt, ['slug' => end($iaView->url), 'status' => 'hidden']);
$stmt = '`slug` = :slug';
$iaDb->bind($stmt, ['slug' => end($iaView->url)]);
if ($iaDb->exists($stmt, null, 'products')) {
$pageSlug = $iaDb->one_bind('alias', '`name` = :page AND `status` = :status',
......
......@@ -15,15 +15,25 @@
*
******************************************************************************/
$iaCategory = $iaCore->factoryModule('category', IA_CURRENT_MODULE);
if (iaView::REQUEST_JSON == $iaView->getRequestType()) {
if (isset($_GET['pid']) && is_numeric($_GET['pid'])) {
$iaView->jsonp($iaCategory->getChildren($_GET['pid'], empty($_GET['id']) ? null : $_GET['id']));
// TODO: add a flag to indicate that there is no children
}
}
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$iaProduct = $iaCore->factoryModule('product', IA_CURRENT_MODULE);
$iaCategory = $iaCore->factoryModule('category', IA_CURRENT_MODULE);
switch ($iaView->name()) {
case 'storefront':
case 'products_index_member':
$iaView->display('index');
$limit = $iaCore->get('commerce_products_per_page', 20);
$pageActions = [];
$pagination = [
'limit' => $limit,
......@@ -35,6 +45,17 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? max((int)$_GET['page'], 1) : 1;
$pagination['start'] = ($page - 1) * $pagination['limit'];
$iaPage = $iaCore->factory('page', iaCore::FRONT);
if ($iaAcl->isAccessible('add_product', iaCore::ACTION_ADD)) {
$pageActions[] = [
'icon' => 'plus-square',
'title' => iaLanguage::get('page_title_add_product'),
'url' => $iaPage->getUrlByName('add_product'),
'classes' => 'btn-success'
];
}
if ($iaCore->requestPath) {
$slug = implode(IA_URL_DELIMITER, $iaCore->requestPath) . IA_URL_DELIMITER;
$category = $iaCategory->getBySlug($slug);
......@@ -54,12 +75,24 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$category = $iaCategory->getRoot();
}
$items = [];
$sorting = $iaProduct->getSortingParams();
$sorting['options'] = $iaProduct->getSortingOptions();
$subcategories = $iaCategory->getChildren($category['id']);
$items = $iaProduct->getByCategory($category['id'], $pagination['start'], $pagination['limit'], $sorting);
if ($iaView->name() == 'storefront') {
$items = $iaProduct->getByCategory($category['id'], $pagination['start'], $pagination['limit'], $sorting);
}
if ($iaView->name() == 'products_index_member') {
if (!iaUsers::hasIdentity()) {
return iaView::accessDenied();
}
$items = $iaProduct->getByMemberId(iaUsers::getIdentity()->id, $pagination['start'], $pagination['limit'], $sorting);
}
$pagination['total'] = $iaProduct->getFoundRows();
......@@ -69,10 +102,12 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$iaView->assign('sorting', $sorting);
$iaView->assign('subcategories', $subcategories);
$iaView->set('actions', $pageActions);
$iaView->set('keywords', $category['meta_keywords']);
$iaView->set('description', $category['meta_description']);
$title = $iaView->title();
if ($page > 1) {
$iaView->title($title . ' (#' . $page . ')');
$iaView->caption($title);
......
......@@ -15,7 +15,7 @@
<items>
<item payable="0" pages="storefront,categories,product_details">products</item>
<item pages="storefront,categories" payable="0">categories</item>
<item pages="storefront,categories" payable="0" table_name="categories">categories</item>
<item payable="0">orders</item>
</items>
......@@ -42,6 +42,10 @@
<pages>
<page group="commerce" name="storefront" url="|PACKAGE|" menus="main">Storefront</page>
<page group="commerce" name="add_product" url="|PACKAGE|add/" menus="main" filename="manage" action="add" parent="view_product" fields_item="products">Add Product</page>
<page group="commerce" name="edit_product" url="|PACKAGE|edit/" filename="manage" action="edit" parent="view_product" fields_item="products">Edit Product</page>
<page group="commerce" name="delete_product" url="|PACKAGE|delete/" filename="manage" action="delete" parent="view_product" service="1">Delete Product</page>
<page group="commerce" name="products_index_member" url="profile/products/" menus="account" nofollow="1" parent="profile" fields_item="products">My Products</page>
<page group="commerce" name="categories" url="|PACKAGE|categories/" menus="main">Categories</page>
<page group="commerce" name="view_product" url="|PACKAGE|product/" filename="view" readonly="1">Product Details</page>
<page group="commerce" name="cart" url="|PACKAGE|cart/" filename="cart" readonly="1">Cart</page>
......@@ -59,10 +63,16 @@
<configgroup name="commerce">Commerce</configgroup>
<config group="commerce" type="divider">Limits</config>
<config group="commerce" name="commerce_auto_approval" type="radio" values="1,0" description="Products auto approval">0</config>
<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>
<tooltips>
<tooltip key="commerce_auto_approval">Should the newly submitted product be approved automatically?</tooltip>
<tooltip key="commerce_guests_posting">Should guests be allowed to post product?</tooltip>
</tooltips>
<emails>
<email name="commerce_divider" description="Commerce" divider="1"><![CDATA[]]></email>
<email name="commerce_order_placed"
......@@ -186,13 +196,13 @@
</fields_groups>
<fields>
<field item="products" group="general" name="title" type="text" required="1" searchable="1" link_to="1" multilingual="1" length="255">Title</field>
<field item="products" group="general" name="snippet" type="textarea" editor="0" editable="0" searchable="1" multilingual="1">Snippet</field>
<field item="products" group="general" name="description" type="textarea" editor="1" editable="0" multilingual="1" searchable="1">Description</field>
<field item="products" group="pricing" name="price" type="currency" length="8" editable="0">Price</field>
<field item="products" group="pictures" name="pictures" type="pictures" thumb_height="228" height="600" length="12" folder_name="products" mode="crop">Pictures</field>
<field item="products" group="seo" name="meta_description" type="textarea" length="255" adminonly="1" editable="0" multilingual="1">Meta-Description</field>
<field item="products" group="seo" name="meta_keywords" type="text" length="255" adminonly="1" editable="0" multilingual="1">Meta-Keywords</field>
<field item="products" group="general" name="title" type="text" required="1" searchable="1" link_to="1" multilingual="1" length="255" page="add_product,edit_product">Title</field>
<field item="products" group="general" name="snippet" type="textarea" editor="0" editable="0" searchable="1" multilingual="1" page="add_product,edit_product">Snippet</field>
<field item="products" group="general" name="description" type="textarea" editor="1" editable="0" multilingual="1" searchable="1" page="add_product,edit_product">Description</field>
<field item="products" group="pricing" name="price" type="currency" length="8" editable="0" page="add_product,edit_product">Price</field>
<field item="products" group="pictures" name="pictures" type="pictures" thumb_width="320" thumb_height="180" width="1600" height="900" length="12" folder_name="products" mode="crop" page="add_product,edit_product">Pictures</field>
<field item="products" group="seo" name="meta_description" type="textarea" length="255" adminonly="1" editable="0" multilingual="1" page="add_product,edit_product">Meta-Description</field>
<field item="products" group="seo" name="meta_keywords" type="text" length="255" adminonly="1" editable="0" multilingual="1" page="add_product,edit_product">Meta-Keywords</field>
<field item="categories" group="general" name="title" type="text" required="1" length="255" multilingual="1">Title</field>
<field item="categories" group="general" name="description" type="textarea" editor="1" editable="0" searchable="1" multilingual="1">Description</field>
......@@ -219,17 +229,21 @@
<phrase category="admin" key="edit_product">Edit Product</phrase>
<phrase category="admin" key="order_removed">Order removed.</phrase>
<phrase category="admin" key="priority">Priority</phrase>
<phrase category="admin" key="product_with_similar_slug_exists_in_category">Product with the same slug already exists in category.</phrase>
<phrase category="common" key="commerce">Commerce</phrase>
<phrase category="common" key="category">Category</phrase>
<phrase category="common" key="_not_selected_">Not selected</phrase>
<phrase category="common" key="order_details">Order Details</phrase>
<phrase category="common" key="orders">Orders</phrase>
<phrase category="common" key="out_of_stock">Out of Stock</phrase>
<phrase category="common" key="hidden">Hidden</phrase>
<phrase category="common" key="price">Price</phrase>
<phrase category="common" key="product">Product</phrase>
<phrase category="common" key="products">Products</phrase>
<phrase category="common" key="quantity">Quantity</phrase>
<phrase category="common" key="subtotal">Sub-Total</phrase>
<phrase category="common" key="total">Total</phrase>
<phrase category="common" key="product_with_similar_slug_exists_in_category">Product with the same slug already exists in category.</phrase>
<phrase category="frontend" key="add_to_cart">Add to Cart</phrase>
<phrase category="frontend" key="buyer_info">Buyer Info</phrase>
......@@ -251,6 +265,15 @@
<phrase category="frontend" key="sorting_option_title">Title</phrase>
<phrase category="frontend" key="thank_you_for_order">Thank you for your order!</phrase>
<phrase category="frontend" key="update_cart">Update Cart</phrase>
<phrase category="frontend" key="submission_is_not_allowed_for_guests">Product submission is not allowed for guests. You have to &lt;a href=":base_urllogin/"&gt;sign in&lt;/a&gt; or &lt;a href=":base_urlregistration/"&gt;register&lt;/a&gt; in order to place your product.</phrase>
<phrase category="frontend" key="you_have_to_be_owner_to_edit">You have to be an owner of this product in order to be able to edit the data.</phrase>
<phrase category="frontend" key="product_successfully_added">Thanks. Product has been successfully added.</phrase>
<phrase category="frontend" key="product_successfully_updated">Thanks. Product details have been successfully updated.</phrase>
<phrase category="frontend" key="product_successfully_submitted">Product successfully submitted.</phrase>
<phrase category="frontend" key="product_successfully_removed">Product successfully removed.</phrase>
<phrase category="frontend" key="product_is_approval">Product is waiting for admin approval and will be displayed after admin review.</phrase>
<phrase category="frontend" key="product_is_hidden">Product is inactive and will not be listed.</phrase>
</phrases>
<blocks>
......@@ -294,10 +317,11 @@ i.i-commerce:before {
<![CDATA[
CREATE TABLE `{prefix}products` (
`id` int(9) unsigned NOT NULL auto_increment,
`member_id` mediumint(8) unsigned NOT NULL,
`category_id` mediumint(7) unsigned NOT NULL,
`date_added` datetime NOT NULL,
`date_modified` datetime NOT NULL,
`status` enum('active', 'out_of_stock', 'hidden') NOT NULL default 'active',
`status` enum('active', 'approval', 'out_of_stock', 'hidden') NOT NULL default 'approval',
`price` decimal(10,2) unsigned NOT NULL,
`slug` varchar(96) NOT NULL,
`num_viewed` int(11) unsigned NOT NULL,
......
......@@ -55,7 +55,7 @@ intelli.titleCache = '';
intelli.fillUrlBox = function () {
var id = $('#input-id').val();
var slug = $('#input-slug').val();
var title = slug || $('#field_categories_title').val();
var title = slug || $('#field_category_title').val();
var category = $('#input-tree').val();
var cache = title + '%%' + category;
......@@ -86,8 +86,8 @@ intelli.fillUrlBox = function () {
};
$(function () {
$('#field_categories_title').keyup(function() {
$('#field_category_title').keyup(function() {
$('#field-slug').show();
});
$('#field_categories_title, #input-slug').on('blur', intelli.fillUrlBox).trigger('blur');
$('#field_category_title, #input-slug').on('blur', intelli.fillUrlBox).trigger('blur');
});
\ No newline at end of file
......@@ -4,7 +4,7 @@ Ext.onReady(function () {
{
columns: [
'selection',
{name: 'pictures', title: _t('field_products_pictures'), icon: 'image', click: function(record, field){
{name: 'pictures', title: _t('field_product_pictures'), icon: 'image', click: function(record, field){
$.fancybox.open(record.get(field));
}},
{name: 'title', title: _t('title'), width: 1, editor: 'text'},
......@@ -16,7 +16,7 @@ Ext.onReady(function () {
'delete'
],
sorters: [{property: 'date_modified', direction: 'DESC'}],
statuses: ['active', 'out_of_stock', 'hidden'],
statuses: ['active', 'approval', 'out_of_stock', 'hidden'],
texts: {
delete_multiple: _t('do_you_want_to_delete_selected_products'),
delete_single: _t('do_you_want_to_delete_this_product')
......@@ -73,7 +73,7 @@ Ext.onReady(function () {
intelli.titleCache = '';
intelli.fillUrlBox = function () {
var slug = $('#input-slug').val();
var title = slug || $('#field_products_title').val();
var title = slug || $('#field_product_title').val();
var category = $('#input-tree').val();
var cache = title + '%%' + location + '%%' + category;
......@@ -92,8 +92,8 @@ intelli.fillUrlBox = function () {
};
$(function () {
$('#field_products_title').keyup(function () {
$('#field_product_title').keyup(function () {
$('#field-slug').show();
});
$('#field_products_title, #input-slug').blur(intelli.fillUrlBox).blur();
$('#field_product_title, #input-slug').blur(intelli.fillUrlBox).blur();
});
\ No newline at end of file
......@@ -20,11 +20,11 @@
var data = $.extend({}, e, {product: id})
var url = baseUrl + 'cart/' + event + '.json'
$.ajax({type: 'post', url: url, data: data, success: function(response){
intelli.post(url, data, function(response){
if ('function' === typeof fn2){
fn2(response)
}
}})
})
},
utils: {
......
<?php
/******************************************************************************
*
* Subrion E-commerce Software
* Copyright (C) 2017 Intelliants, LLC <https://intelliants.com>
*
* This file is part of Subrion E-commerce Software.
*
* This program is a commercial software and any kind of using it must agree
* to the license, see <https://subrion.pro/license.html>.
*
* This copyright notice may not be removed from the software source without
* the permission of Subrion respective owners.
*
*
******************************************************************************/
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$iaProduct = $iaCore->factoryModule('product', IA_CURRENT_MODULE);
$iaCategory = $iaCore->factoryModule('category', IA_CURRENT_MODULE);
$iaUtil = $iaCore->factory('util');
$product = [];
switch ($pageAction) {
case iaCore::ACTION_DELETE:
case iaCore::ACTION_EDIT:
$id = (int)(isset($_GET['id']) ? $_GET['id'] : end($iaCore->requestPath));
if (!$id) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
$product = $iaProduct->getById($id);
if (empty($product)) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
if ($product['member_id'] != iaUsers::getIdentity()->id) {
return iaView::accessDenied(iaLanguage::get('you_have_to_be_owner_to_edit'));
}
if (iaCore::ACTION_DELETE == $pageAction) {
$iaCategory->recount(['status' => iaCore::STATUS_INACTIVE], $product);
$result = $iaProduct->delete($id);
iaUtil::redirect(
iaLanguage::get($result ? 'thanks' : 'error'),
iaLanguage::get($result ? 'product_successfully_removed' : 'db_error'),
$iaProduct->getInfo('url') . 'commerce/'
);
}
break;
default:
if (!iaUsers::hasIdentity()) {
return iaView::accessDenied(iaLanguage::getf('submission_is_not_allowed_for_guests', ['base_url' => IA_URL]));
}
$product['category_id'] = 0;
}
$iaField = $iaCore->factory('field');
$iaPlan = $iaCore->factory('plan');
$plans = $iaPlan->getPlans($iaProduct->getItemName());
if (isset($_POST['data-product'])) {
$error = false;
$messages = [];
$categoryData = [];
list($item, $error, $messages) = $iaField->parsePost($iaProduct->getItemName(), $product);
$id = isset($product['id']) ? $product['id'] : 0;
$item['slug'] = null;
$item['category_id'] = 0;
if (!iaUsers::hasIdentity() && !iaValidate::isCaptchaValid()) {
$error = true;
$messages[] = iaLanguage::get('confirmation_code_incorrect');
}
if (empty($_POST['category_id']) || !is_numeric($_POST['category_id'])) {
$error = true;
$messages[] = iaLanguage::getf('field_is_not_selected', ['field' => iaLanguage::get('category')]);
} else {
$categoryData = $iaCategory->getById((int)$_POST['category_id']);
$item[<