Commit de215dd2 authored by Artem Malichev's avatar Artem Malichev

Front products manager functionality added.

parent 40d6e726
......@@ -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' => '',
......
......@@ -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'];
......
......@@ -17,6 +17,9 @@
class iaCategory extends iaAbstractFrontHelperCategoryFlat
{
const COUNTER_ACTION_INCREMENT = '+';
const COUNTER_ACTION_DECREMENT = '-';
protected static $_table = 'categories';
protected $_itemName = 'categories';
......@@ -59,6 +62,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()
{
......@@ -82,21 +108,46 @@ class iaCategory extends iaAbstractFrontHelperCategoryFlat
$result[] = (int)$id;
}
if ($modelData = $this->getById($id)) {
$result[] = $additionalFields ? $modelData : $modelData['pid'];
while (isset($modelData['pid'])) {
$modelData = $this->getById($modelData['pid']);
if (empty($modelData)) {
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[] = $modelData;
} elseif ($modelData['pid']) {
$result[] = (int)$modelData['pid'];
$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,28 @@ class iaProduct extends abstractModuleFront
$this->_iaCategory = $this->iaCore->factoryModule('category', $this->getModuleName());
}
public function getUrl(array $item)
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 +91,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,20 +116,28 @@ 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 (iaUsers::hasIdentity()) {
$userId = iaUsers::getIdentity()->id;
$where .= ' AND p.`member_id` = :member_id';
} else {
$where .= ' AND p.`status` != :hidden';
}
$this->iaDb->bind($where, ['hidden' => self::STATUS_HIDDEN, 'member_id' => isset($userId) ? $userId : 0]);
if (!$order) {
$order = 'p.`date_modified` DESC';
......@@ -213,6 +234,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,15 @@ 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']);
if (iaUsers::hasIdentity()) {
$userId = iaUsers::getIdentity()->id;
$stmt = '`slug` = :slug AND `member_id` = :member_id';
} else {
$stmt = '`slug` = :slug AND `status` != :status';
}
$iaDb->bind($stmt, ['slug' => end($iaView->url), 'status' => 'hidden', 'member_id' => isset($userId) ? $userId : 0]);
if ($iaDb->exists($stmt, null, 'products')) {
$pageSlug = $iaDb->one_bind('alias', '`name` = :page AND `status` = :status',
......
......@@ -29,9 +29,11 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
switch ($iaView->name()) {
case 'storefront':
case 'products_index_member':
$iaView->display('index');
$limit = $iaCore->get('commerce_products_per_page', 20);
$pageActions = [];
$pagination = [
'limit' => $limit,
......@@ -43,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);
......@@ -62,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();
......@@ -77,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);
......
......@@ -45,6 +45,7 @@
<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>
......@@ -63,7 +64,6 @@
<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_guests_posting" type="radio" values="1,0" description="Guests are allowed to submit products">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>
......@@ -200,7 +200,7 @@
<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_height="228" height="600" length="12" folder_name="products" mode="crop" page="add_product,edit_product">Pictures</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>
......@@ -229,7 +229,6 @@
<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>
......@@ -237,12 +236,14 @@
<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>
......@@ -270,6 +271,8 @@
<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>
......@@ -314,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,
......
......@@ -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')
......
<?php
/******************************************************************************
*
* Subrion Auto Classifieds Software
* Subrion E-commerce Software
* Copyright (C) 2017 Intelliants, LLC <https://intelliants.com>
*
* This file is part of Subrion Web Directory Script.
* 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>.
......@@ -13,12 +13,11 @@
* the permission of Subrion respective owners.
*
*
* @link https://subrion.pro/product/autos.html
*
******************************************************************************/
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 = [];
......@@ -41,18 +40,21 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
}
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->url($result ? 'my' : 'view', $product)
$iaProduct->getInfo('url') . 'commerce/'
);
}
break;
default:
if (!iaUsers::hasIdentity() && !$iaCore->get('commerce_guests_posting')) {
if (!iaUsers::hasIdentity()) {
return iaView::accessDenied(iaLanguage::getf('submission_is_not_allowed_for_guests', ['base_url' => IA_URL]));
}
......@@ -60,7 +62,6 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
}
$iaField = $iaCore->factory('field');
$iaCategory = $iaCore->factoryModule('category', IA_CURRENT_MODULE);
$iaPlan = $iaCore->factory('plan');
$plans = $iaPlan->getPlans($iaProduct->getItemName());
......@@ -72,6 +73,11 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
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');
......@@ -85,34 +91,49 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$item['category_id'] = (int)$_POST['category_id'];
}
if (isset($item["title_{$iaCore->language['iso']}"])) {
$item['slug'] = strtolower(iaSanitize::alias($item["title_{$iaCore->language['iso']}"]));
}
if ($iaDb->exists('`category_id` = :category AND `slug` = :slug AND `id` != :id',
['category' => $item['category_id'], 'slug' => $item['slug'], 'id' => $id], iaProduct::getTable())) {
$error = true;
$messages[] = iaLanguage::get('product_with_similar_slug_exists_in_category');
}
if (isset($_POST['status']) && !empty($_POST['status'])) {
$item['status'] = $_POST['status'];
} else {
$item['status'] = isset($product['status']) ? $product['status'] : iaCore::STATUS_APPROVAL;
}
if ($error) {
$product = $item;
$product['id'] = $id;
$iaView->setMessages($messages);
} else {
$item['slug'] = strtolower(iaSanitize::alias($item["title_{$iaCore->language['iso']}"]));
if (iaCore::ACTION_ADD == $pageAction) {
$item['status'] = $iaCore->get('commerce_auto_approval') ? iaCore::STATUS_ACTIVE : iaProduct::STATUS_HIDDEN;
$item['status'] = $iaCore->get('commerce_auto_approval') ? iaCore::STATUS_ACTIVE : iaCore::STATUS_APPROVAL;
$item['id'] = $iaProduct->insert($item);
$result = (bool)$item['id'];
$messages[] = iaLanguage::get('product_successfully_added');
} else {
if (isset($_POST['status']) && $product['status'] != iaCore::STATUS_APPROVAL) {
$item['status'] = iaSanitize::sql($_POST['status']);
}
$item['id'] = $product['id'];
$result = $iaProduct->update($item, $item['id']);
$messages[] = iaLanguage::get('product_successfully_updated');
}
if ($result) {
// $iaCategory->recount($item, $product);
}
$result && $iaCategory->recount($item, $product);
$product = $iaProduct->getById($item['id'], false);
$url = $iaProduct->getUrl(['slug' => $item['slug'], 'category_slug' => $categoryData['slug']]);
if ($item['status'] == iaProduct::STATUS_HIDDEN) {
$url = IA_SELF;
} else {
$url = $iaProduct->url('view', $product);
}
if (isset($_POST['plan_id']) && $_POST['plan_id'] && $_POST['plan_id'] != $product['sponsored_plan_id']) {
$plan = $iaPlan->getById((int)$_POST['plan_id']);
......@@ -162,8 +183,8 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
'type' => iaField::COMBO,
'values' => [
iaCore::STATUS_ACTIVE => iaLanguage::get(iaCore::STATUS_ACTIVE),
iaAuto::STATUS_HIDDEN => iaLanguage::get(iaAuto::STATUS_HIDDEN),
iaAuto::STATUS_SOLD => iaLanguage::get(iaAuto::STATUS_SOLD)
iaProduct::STATUS_HIDDEN => iaLanguage::get(iaProduct::STATUS_HIDDEN),
iaProduct::STATUS_OUT_OF_STOCK => iaLanguage::get(iaProduct::STATUS_OUT_OF_STOCK)
]
]
]
......
......@@ -36,11 +36,12 @@
<div class="fieldset__actions">
<button type="submit" name="data-product" class="btn btn-primary">{lang key='submit'}</button>
{if iaCore::ACTION_EDIT == $pageAction}
<a href="{$smarty.const.IA_URL}delete/{$item.id}" class="btn btn-danger js-delete-article">{lang key='delete'}</a>
{/if}
</div>
{if iaCore::ACTION_EDIT == $pageAction}
<a href="{$smarty.const.IA_URL}delete/{$item.id}" class="btn btn-danger js-delete-article">{lang key='delete'}</a>
{/if}
</div>-
</div>
</form>
{ia_hooker name='smartyListingSubmitBeforeFooter'}
......
......@@ -43,6 +43,7 @@ if (iaView::REQUEST_JSON == $iaView->getRequestType()) {
}
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$iaItem = $iaCore->factory('item');
$iaCategory = $iaCore->factoryModule('category', IA_CURRENT_MODULE);
$categorySlug = $iaCore->requestPath;
......@@ -56,15 +57,23 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$categorySlug = implode(IA_URL_DELIMITER, $categorySlug) . IA_URL_DELIMITER;
$product = $iaProduct->getBySlug($productSlug);
$category = $iaCategory->getById($product['category_id']);
if (!$product || iaProduct::STATUS_HIDDEN == $product['status']) {
if (empty($category) || !$product) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
$category = $iaCategory->getById($product['category_id']);
if (iaUsers::hasIdentity() && iaUsers::getIdentity()->id == $product['member_id']) {
switch ($product['status']) {
case iaProduct::STATUS_HIDDEN:
$iaView->setMessages(iaLanguage::get('product_is_hidden'), iaView::ALERT);
break;
if (empty($category)) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
case iaCore::STATUS_APPROVAL:
$iaView->setMessages(iaLanguage::get('product_is_approval'), iaView::ALERT);
}
} else {
return iaView::accessDenied();
}
if ($categorySlug != $category['slug']) {
......@@ -80,6 +89,30 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
iaBreadcrumb::add($categoryParent['title'], $iaCategory->url(null, $categoryParent));
}
if (iaUsers::hasIdentity() && iaUsers::getIdentity()->id == $product['member_id']) {
$actionUrls = [
iaCore::ACTION_EDIT => $iaProduct->url(iaCore::ACTION_EDIT, $product),
iaCore::ACTION_DELETE => $iaProduct->url(iaCore::ACTION_DELETE, $product)
];
$iaView->assign('tools', $actionUrls);
$iaItem->setItemTools([
'id' => 'action-edit',
'title' => iaLanguage::get('edit_listing'),
'attributes' => [
'href' => $actionUrls[iaCore::ACTION_EDIT],
]
]);
$iaItem->setItemTools([
'id' => 'action-delete',
'title' => iaLanguage::get('delete_listing'),
'attributes' => [
'href' => $actionUrls[iaCore::ACTION_DELETE],
'class' => 'js-delete-listing'
]
]);
}
$iaView->assign('category', $category);
$iaView->assign('item', $product);
......
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