Commit f965be13 authored by Artem Malichev's avatar Artem Malichev

[WIP] Add products page on front.

parent fb27cb41
......@@ -62,4 +62,29 @@ 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 ($modelData = $this->getById($id)) {
$result[] = $additionalFields ? $modelData : $modelData['pid'];
while (isset($modelData['pid'])) {
$modelData = $this->getById($modelData['pid']);
if (empty($modelData)) {
break;
}
if ($additionalFields) {
$result[] = $modelData;
} elseif ($modelData['pid']) {
$result[] = (int)$modelData['pid'];
}
}
}
return array_reverse(array_filter($result));
}
}
\ No newline at end of file
<?php
//##copyright##
$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':
......
......@@ -42,6 +42,9 @@
<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="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 +62,17 @@
<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>
<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_height="228" height="600" 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>
......@@ -221,6 +231,9 @@
<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>
......@@ -251,6 +264,13 @@
<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>
</phrases>
<blocks>
......
<?php
/******************************************************************************
*
* Subrion Auto Classifieds Software
* Copyright (C) 2017 Intelliants, LLC <https://intelliants.com>
*
* This file is part of Subrion Web Directory Script.
*
* 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.
*
*
* @link https://subrion.pro/product/autos.html
*
******************************************************************************/
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
$iaProduct = $iaCore->factoryModule('product', 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) {
$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)
);
}
break;
default:
if (!iaUsers::hasIdentity() && !$iaCore->get('commerce_guests_posting')) {
return iaView::accessDenied(iaLanguage::getf('submission_is_not_allowed_for_guests', ['base_url' => IA_URL]));
}
$product['category_id'] = 0;
}
$iaField = $iaCore->factory('field');
$iaCategory = $iaCore->factoryModule('category', IA_CURRENT_MODULE);
$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);
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['category_id'] = (int)$_POST['category_id'];
}
if ($error) {
$product = $item;
$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['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);
}
$product = $iaProduct->getById($item['id'], false);
$url = $iaProduct->getUrl(['slug' => $item['slug'], 'category_slug' => $categoryData['slug']]);
if (isset($_POST['plan_id']) && $_POST['plan_id'] && $_POST['plan_id'] != $product['sponsored_plan_id']) {
$plan = $iaPlan->getById((int)$_POST['plan_id']);
if ($plan['cost'] > 0) {
$url = $iaPlan->prePayment($iaProduct->getItemName(), $item, $plan['id']);
} else {
$iaTransaction = $iaCore->factory('transaction');
$transactionId = $iaTransaction->create(null, 0, $iaProduct->getItemName(), $item, '', (int)$_POST['plan_id'], true);
$transaction = $iaTransaction->getBy('sec_key', $transactionId);
$iaPlan->setPaid($transaction);
}
}
$iaCore->startHook('phpAddItemAfterAll', [
'type' => iaCore::FRONT,
'listing' => $item['id'],
'item' => $iaProduct->getItemName(),
'data' => $item,
'old' => $product
]);
$iaView->setMessages($messages, $error ? iaView::ERROR : iaView::SUCCESS);
iaUtil::go_to($url);
}
}
$sections = $iaField->getTabs($iaProduct->getItemName(), $product);
if (iaCore::ACTION_EDIT == $pageAction && iaCore::STATUS_APPROVAL != $product['status']) {
// field emulation. TODO: refactor
$sections['common'][] = [
'collapsed' => false,
'name' => 'other',
'title' => iaLanguage::get('other'),
'description' => '',
'fields' => [
[
'item' => $iaProduct->getItemName(),
'name' => 'status',
'title' => iaLanguage::get('status'),
'class' => 'fieldzone',
'default' => $product['status'],
'for_plan' => 0,
'relation' => iaField::RELATION_REGULAR,
'required' => true,
'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)
]
]
]
];
}
$product['item'] = $iaProduct->getItemName();
$categoryPath = $iaCategory->getParentsList($product['category_id']);
$categoryPath = implode(',', $categoryPath);
$iaView->assign('children', $categoryPath);
$iaView->assign('item', $product);
$iaView->assign('categories', $iaCategory->getByLevel(1));
$iaView->assign('plans', $plans);
$iaView->assign('sections', $sections);
iaBreadcrumb::remove(-2);
$iaView->display('manage');
}
{if iaCore::ACTION_EDIT == $pageAction}
<div class="tool-buttons pull-right">
<a class="btn btn-sm btn-info" href="{ia_url type='url' item='products' action='view' data=$item}">{lang key='view'}</a>
</div>
{/if}
<form method="post" action="{$smarty.const.IA_SELF}" enctype="multipart/form-data" class="ia-form">
{preventCsrf}
{capture name='common' append='tabs_before'}
{include 'plans.tpl' item=$item}
<div class="fieldset">
<div class="fieldset__header">{lang key='category'} <span class="required">*</span></div>
<div class="fieldset__content">
<div class="form-group">
<input class="form-control" type="text" id="category-label" value="{lang key='_not_selected_'}" disabled>
<input type="hidden" name="category_id" value="{$item.category_id}">
</div>
<div class="form-group">
<select class="form-control js-iad" data-children="{$children}">
<option value="">{lang key='_select_'}</option>
{foreach $categories as $category}
<option value="{$category.id}">{$category.title}</option>
{/foreach}
</select>
</div>
</div>
</div>
{/capture}
{include 'item-view-tabs.tpl'}
<div class="ia-form__after-tabs">
{include 'captcha.tpl'}
<div class="fieldset__actions">
<button type="submit" name="data-product" class="btn btn-primary">{lang key='submit'}</button>
</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>-
</form>
{ia_hooker name='smartyListingSubmitBeforeFooter'}
{ia_add_media files='js:jquery/plugins/jquery.ia-dropdown.min'}
{ia_add_js}
$(function()
{
$('select.js-iad').iaDropdown({
label: 'category-label',
url: intelli.config.packages.commerce.url + 'categories.json',
valueHolder: 'category_id'
});
});
{/ia_add_js}
\ No newline at end of file
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