add offer, admin check, my offers section

This commit is contained in:
saparatayev 2021-07-28 12:54:25 +05:00
parent 6d14e4939e
commit f63f3bd709
9 changed files with 394 additions and 34 deletions

View File

@ -176,7 +176,8 @@ class Plugin extends PluginBase
'TPS\Birzha\Components\Singleoffer' => 'singleoffer',
'TPS\Birzha\Components\OfferForm' => 'offerform',
'TPS\Birzha\Components\Messages' => 'messages',
'TPS\Birzha\Components\PaymentApi' => 'paymentapi'
'TPS\Birzha\Components\PaymentApi' => 'paymentapi',
'TPS\Birzha\Components\MyOffers' => 'myOffers',
];
}

View File

@ -0,0 +1,73 @@
<?php namespace TPS\Birzha\Components;
use Cms\Classes\ComponentBase;
use TPS\Birzha\Models\Product;
class MyOffers extends ComponentBase
{
/**
* @var Collection A collection of user's posts
*/
public $offers;
public function componentDetails()
{
return [
'name' => 'MyOffers List',
'description' => 'List of my offers'
];
}
public function defineProperties()
{
return [
'perPage' => [
'title' => 'Number of offers',
'description' => 'How many offers do you want to display',
'default' => 0,
'validationPattern' => '^[0-9]+$',
'validationMessage' => 'Only numbers allowed'
],
// 'productSlug' => [
// 'title' => 'Product Slug',
// 'description' => 'Similar offers (the same product)',
// 'type' => 'string',
// 'default' => ''
// ],
// 'offerId' => [
// 'title' => 'Offer id',
// 'description' => 'Offer id',
// 'type' => 'string',
// 'default' => ''
// ]
];
}
public function onRun() {
$this->offers = $this->loadOffers();
}
protected function loadOffers() {
$perPage = $this->property('perPage');
// $productSlug = $this->property('productSlug');
// $offerId = $this->property('offerId');
// $user = \Auth::user();
// $query = $user->products()->query();
// orderBy('created_at', $sortOrder)->paginate($perPage);
// $query = query()->
// if($productSlug != '' && $offerId != '') { // fetch offers with similar products
// $product = Product::transWhere('slug', $productSlug, Session::get('rainlab.translate.locale'))->first();
// if($product) {
// $query = Product::where('id','!=',$offerId)->where('status','approved')->where('ends_at','>=',DB::raw('curdate()'))->orderBy('created_at', $sortOrder)->paginate($perPage);
// }
// }
return \Auth::user()->products()
->orderBy('created_at', 'desc')
->paginate($perPage);
}
}

View File

@ -33,6 +33,16 @@ class OfferForm extends ComponentBase
* @var string A collection of countries in dropdown
*/
public $countries;
/**
* @var string A string with product id
*/
public $productIdOption;
/**
* @var string A product which is being edited
*/
public $productForEditing;
public function componentDetails() {
return [
@ -41,6 +51,17 @@ class OfferForm extends ComponentBase
];
}
public function defineProperties() {
return [
'productId' => [
'title' => 'Edit post :id',
'description' => 'Edit post :id',
'type' => 'string',
'default' => ''
],
];
}
// step1
public function onSave() {
$data = post();
@ -58,8 +79,13 @@ class OfferForm extends ComponentBase
$this->validateForm($data, $rules);
$category = Category::find($data['category_id']);
$product = new Product;
if(isset($data['productForEditing'])) {
$product = Product::find($data['productForEditing']);
} else {
$product = new Product;
}
$product->name = $data['name_tm'];
// Sets a single translated attribute for a language
$product->setAttributeTranslated('name', $data['name_ru'], 'ru');
@ -73,10 +99,18 @@ class OfferForm extends ComponentBase
$product->mark = $data['mark'];
$product->manufacturer = $data['manufacturer'];
$product->country_id = $data['country_id'];
$product->created_at = Carbon::now('Asia/Ashgabat');
$product->vendor_id = \Auth::user()->id;
$category->products()->save($product);
if(!isset($data['productForEditing'])) {
$product->created_at = Carbon::now('Asia/Ashgabat');
$category->products()->save($product);
} else {
$product->save();
}
// go to next step - next form
$this->page['measures'] = Measure::all();
@ -212,5 +246,15 @@ class OfferForm extends ComponentBase
public function onRun() {
$this->countries = Country::all();
$this->categories = Category::select('id','name','status')->where('status',1)->get();
$this->productIdOption = $this->property('productId');
// form will be filled with product's info if we have productIdOption
if($this->productIdOption) {
$this->productForEditing = Product::find($this->productIdOption);
// dd($this->productForEditing->categories->first()->id);
} else {
$this->productForEditing = null;
}
}
}

View File

@ -0,0 +1,153 @@
{% set offers = __SELF__.offers %}
<!-- My post ========================================================= -->
<section class="library">
<div class="auto_container">
<div class="library_wrap">
<div class="product_head">
<div class="product_title">
Мои объявления
</div>
<div class="sort_by">
<div class="sort_icon">
<svg id="inline" data-name="Иконка (Стиль 2)" xmlns="http://www.w3.org/2000/svg"
class="icon" viewBox="0 0 40 40">
<path id="Иконка_Стиль_2_2" data-name="Иконка (Стиль 2)"
d="M-177-64a2,2,0,0,1-2-2v-6a2,2,0,0,1,2-2h22a2,2,0,0,1,2,2v6a2,2,0,0,1-2,2Zm-14,0a2,2,0,0,1-2-2v-6a2,2,0,0,1,2-2h6a2,2,0,0,1,2,2v6a2,2,0,0,1-2,2Zm14-15a2,2,0,0,1-2-2v-6a2,2,0,0,1,2-2h22a2,2,0,0,1,2,2v6a2,2,0,0,1-2,2Zm-14,0a2,2,0,0,1-2-2v-6a2,2,0,0,1,2-2h6a2,2,0,0,1,2,2v6a2,2,0,0,1-2,2Zm14-15a2,2,0,0,1-2-2v-6a2,2,0,0,1,2-2h22a2,2,0,0,1,2,2v6a2,2,0,0,1-2,2Zm-14,0a2,2,0,0,1-2-2v-6a2,2,0,0,1,2-2h6a2,2,0,0,1,2,2v6a2,2,0,0,1-2,2Z"
transform="translate(193 104)" fill="#003197" />
</svg>
</div>
<div class="sort_icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" id="card" class="icon active">
<path id="Иконка_Стиль_1_" data-name="Иконка (Стиль 1)"
d="M-169-64a2,2,0,0,1-2-2V-80a2,2,0,0,1,2-2h14a2,2,0,0,1,2,2v14a2,2,0,0,1-2,2Zm-22,0a2,2,0,0,1-2-2V-80a2,2,0,0,1,2-2h14a2,2,0,0,1,2,2v14a2,2,0,0,1-2,2Zm22-22a2,2,0,0,1-2-2v-14a2,2,0,0,1,2-2h14a2,2,0,0,1,2,2v14a2,2,0,0,1-2,2Zm-22,0a2,2,0,0,1-2-2v-14a2,2,0,0,1,2-2h14a2,2,0,0,1,2,2v14a2,2,0,0,1-2,2Z"
transform="translate(193 104)" fill="#003197" />
</svg>
</div>
</div>
</div>
<div class="inline_head">
<div class="inline_item">
Лот №:
</div>
<div class="inline_item">
Изображение
</div>
<div class="inline_item">
Товар
</div>
<div class="inline_item">
Количество:
</div>
<div class="inline_item">
Стартовая цена:
</div>
<div class="inline_item">
Дата окончания:
</div>
</div>
<div class="product_box">
{% for offer in offers %}
<div class="product_item">
<div class="item_head">
<div class="item_lot">
{{ 'page.prod_id'|_ }} №:
</div>
<div class="item_num">
№ {{offer.id}}
</div>
</div>
<div class="inline_num">
№ {{offer.id}}
</div>
<div class="item_photo">
<img src="{{ offer.images[0].thumb(308,180,{'mode':'crop'}) }}" alt="">
</div>
<div class="item_group">
<div class="item_title">
{{ offer.name }}
</div>
<div class="item_sub_title">
{{ offer.name }}
</div>
</div>
<div class="item_group">
<div class="item_sub_name">
{{ 'page.prod_amount'|_ }}:
</div>
<div class="item_name">
{{ offer.quantity }} {{ offer.measure.code }}.
</div>
</div>
<div class="item_group">
<div class="item_sub_name">
{{ 'page.prod_price'|_ }}:
</div>
<div class="item_name">
{{ offer.price }} {{offer.currency.code}} / 1 {{ offer.measure.code }}.
</div>
</div>
<div class="item_group">
<div class="item_sub_name">
{{ 'page.prod_finishdate'|_ }}:
</div>
<div class="item_name">
{{ offer.ends_at|date('d.m.Y') }}
</div>
</div>
{% if offer.status == "approved" %}
<span style="color:green">{{offer.status}}</span>
<a href="{{ 'offer'|page({ slug: offer.slug, id: offer.id }) }}" class="item_btn">
На сайте
</a>
{% elseif offer.status == "denied" %}
<span style="color:red">{{offer.status}}</span> <br>
<span style="color:red">{{ offer.status_note }}</span>
<a href="{{ 'kabinet/edit_post'|page({ id: offer.id }) }}" class="item_btn">
Edit
</a>
{% elseif offer.status == "draft" %}
<span style="color:yellow">{{offer.status}}</span>
<a href="{{ 'kabinet/edit_post'|page({ id: offer.id }) }}" class="item_btn">
Complete
</a>
{% elseif offer.status == "new" %}
<span style="color:blue">{{offer.status}}</span>
<a href="#" style="pointer-events: none; background-color: cornflowerblue;" class="item_btn">
Admin is checking
</a>
{% elseif offer.status == "disabled" %}
<span style="color:black">{{offer.status}}</span>
<a href="#" class="item_btn">
Продлить
</a>
{% endif %}
</div>
{% endfor %}
</div>
{% if offers.total > offers.perPage %}
<div class="cat_end">
<a href="{{ offers.previousPageUrl|default('#') }}" class="cat_arrow left">
<img src="{{ 'assets/images/svg/arrow-right.svg'|theme }}" alt="">
</a>
<form method="get" class="cat_form">
<input type="text" value="{{offers.currentPage|default('1')}}" name="page">
</form>
<a href="{{ offers.nextPageUrl|default('#') }}" class="cat_arrow ">
<img src="{{ 'assets/images/svg/arrow-right.svg'|theme }}" alt="">
</a>
<div class="cat_page">
{{ (offers.total / offers.perPage)|round(0,'ceil') }} {{ 'page.pages'|_ }}
</div>
</div>
{% endif %}
</div>
</div>
</section>
<!-- My post end ===================================================== -->

View File

@ -1,6 +1,7 @@
{% set categories = __SELF__.categories %}
{% set countries = __SELF__.countries %}
{% set productForEditing = __SELF__.productForEditing %}
<!-- Add post ============================================================= -->
<section class="post">
@ -17,36 +18,58 @@
data-request-flash
class="post_form post_form-2 first-step-form">
<!-- <input type="hidden" name="product_id" data-belongsto="product"> -->
{% if productForEditing %}
<input type="hidden" name="productForEditing" value="{{productForEditing.id}}">
{% endif %}
<!-- ru name -->
<div class="post_input">
<label>Наименование лота (RU) <span>*</span></label>
<input type="text" name="name_ru" data-belongsto="product" placeholder="Пример: Гидравлическое масло">
<input type="text" name="name_ru" data-belongsto="product" placeholder="Пример: Гидравлическое масло"
{% if productForEditing %}
value="{{ productForEditing.lang('ru').name }}"
{% endif %}
>
<span data-validate-for="name_ru" style="color: red;"></span>
</div>
<!-- en name -->
<div class="post_input">
<label>Наименование лота (EN) <span>*</span></label>
<input type="text" name="name_en" data-belongsto="product" placeholder="Пример: Гидравлическое масло">
<input type="text" name="name_en" data-belongsto="product" placeholder="Пример: Гидравлическое масло"
{% if productForEditing %}
value="{{ productForEditing.lang('en').name }}"
{% endif %}
>
<span data-validate-for="name_en" style="color: red;"></span>
</div>
<!-- tm name -->
<div class="post_input">
<label>Наименование лота (TM) <span>*</span></label>
<input type="text" name="name_tm" data-belongsto="product" placeholder="Пример: Гидравлическое масло">
<input type="text" name="name_tm" data-belongsto="product" placeholder="Пример: Гидравлическое масло"
{% if productForEditing %}
value="{{ productForEditing.name }}"
{% endif %}
>
<span data-validate-for="name_tm" style="color: red;"></span>
</div>
<div class="post_input">
<label for="mark-goods">Марка товара <span>*</span></label>
<input type="text" name="mark" data-belongsto="product" placeholder="Пример: Гидравлическое масло ЛУКОЙЛ 46" id="mark-goods">
<input type="text" name="mark" data-belongsto="product" placeholder="Пример: Гидравлическое масло ЛУКОЙЛ 46" id="mark-goods"
{% if productForEditing %}
value="{{ productForEditing.mark }}"
{% endif %}
>
<span data-validate-for="mark" style="color: red;"></span>
</div>
<div class="post_input">
<label for="owner">Производитель <span>*</span></label>
<input type="text" name="manufacturer" data-belongsto="product" placeholder="Пример: ЛУКОЙЛ" id="owner">
<input type="text" name="manufacturer" data-belongsto="product" placeholder="Пример: ЛУКОЙЛ" id="owner"
{% if productForEditing %}
value="{{ productForEditing.manufacturer }}"
{% endif %}
>
<span data-validate-for="manufacturer" style="color: red;"></span>
</div>
@ -56,7 +79,11 @@
<select class="category-select" data-belongsto="product" name="category_id">
<option value="0">Category</option>
{% for c in categories %}
<option value="{{ c.id }}">{{ c.name }}</option>
<option value="{{ c.id }}"
{% if productForEditing and productForEditing.categories.first.id == c.id %}
selected
{% endif %}
>{{ c.name }}</option>
{% endfor %}
</select>
</div>
@ -68,7 +95,11 @@
<select name="country_id" data-belongsto="product">
<option value="0">Страна производителя</option>
{% for country in countries %}
<option value="{{ country.id }}">{{country.name}}</option>
<option value="{{ country.id }}"
{% if productForEditing and productForEditing.country.id == country.id %}
selected
{% endif %}
>{{country.name}}</option>
{% endfor %}
</select>
</div>

View File

@ -16,7 +16,11 @@
<select name="measure_id">
<option value="">Единицы измерения</option>
{% for m in measures %}
<option value="{{m.id}}">{{m.name}}</option>
<option value="{{m.id}}"
{% if product.measure.id == m.id %}
selected
{% endif %}
>{{m.name}}</option>
{% endfor %}
</select>
</div>
@ -24,7 +28,8 @@
<div class="post_input">
<label for="good-count">Количество товара <span>*</span> </label>
<input type="text" name="quantity" placeholder="Пример: 3 литра" id="good-count">
<input type="text" name="quantity" placeholder="Пример: 3 литра" id="good-count"
value="{{ product.quantity }}">
<span data-validate-for="quantity" style="color: red;"></span>
</div>
@ -34,7 +39,11 @@
<select name="currency_id">
<option value="">Валюта</option>
{% for currency in currencies %}
<option value="{{currency.id}}">{{currency.name}}</option>
<option value="{{currency.id}}"
{% if product.currency.id == currency.id %}
selected
{% endif %}
>{{currency.name}}</option>
{% endfor %}
</select>
</div>
@ -42,7 +51,8 @@
<div class="post_input">
<label for="good-cost">Стартовая цена за единицу <span>*</span> </label>
<input type="text" name="price" placeholder="Пример: 120" id="good-cost">
<input type="text" name="price" placeholder="Пример: 120" id="good-cost"
value="{{ product.price }}">
<span data-validate-for="price" style="color: red;"></span>
</div>
@ -52,7 +62,11 @@
<select name="delivery_term_id">
<option value="">Условия поставки</option>
{% for dt in deliveryTerms %}
<option value="{{dt.id}}">{{dt.name}}</option>
<option value="{{dt.id}}"
{% if product.delivery_term.id == dt.id %}
selected
{% endif %}
>{{dt.name}}</option>
{% endfor %}
</select>
</div>
@ -60,7 +74,8 @@
<div class="post_input">
<label for="good-cost">Пункт <span>*</span> </label>
<input type="text" name="place" placeholder="Пример: 120" id="good-cost">
<input type="text" name="place" placeholder="Пример: 120" id="good-cost"
value="{{ product.place }}">
<span data-validate-for="place" style="color: red;"></span>
</div>
@ -69,8 +84,16 @@
<div class="my-select">
<select name="packaging">
<option value="">Упаковка</option>
<option value="yes">Есть</option>
<option value="no">Нет</option>
<option value="yes"
{% if product.packaging == "yes" %}
selected
{% endif %}
>Есть</option>
<option value="no"
{% if product.packaging == "no" %}
selected
{% endif %}
>Нет</option>
</select>
</div>
</div>
@ -81,31 +104,29 @@
<select name="payment_term_id">
<option value="">Условия оплаты</option>
{% for pt in paymentTerms %}
<option value="{{pt.id}}">{{pt.name}}</option>
<option value="{{pt.id}}"
{% if product.payment_term.id == pt.id %}
selected
{% endif %}
>{{pt.name}}</option>
{% endfor %}
</select>
</div>
</div>
<!-- <div class="post_input">
<label for="good-cost">Ends at <span>*</span> </label>
<input type="datetime-local" name="ends_at">
<span data-validate-for="ends_at" style="color: red;"></span>
</div> -->
<div class="post_comment">
<label for="description_ru">Описание (RU) <span>*</span></label>
<textarea id="description_ru" name="description_ru"></textarea>
<textarea id="description_ru" name="description_ru">{{product.lang('ru').description}}</textarea>
<span data-validate-for="description_ru" style="color: red;"></span>
</div>
<div class="post_comment">
<label for="description_en">Описание (EN) <span>*</span></label>
<textarea id="description_en" name="description_en"></textarea>
<textarea id="description_en" name="description_en">{{product.lang('en').description}}</textarea>
<span data-validate-for="description_en" style="color: red;"></span>
</div>
<div class="post_comment">
<label for="description_tm">Описание (TM) <span>*</span></label>
<textarea id="description_tm" name="description_tm"></textarea>
<textarea id="description_tm" name="description_tm">{{product.lang('tm').description}}</textarea>
<span data-validate-for="description_tm" style="color: red;"></span>
</div>
@ -116,7 +137,13 @@
{% for i in 0..2 %}
<div class="post_upload_item">
{% if product.images[i] %}
<div class="post_upload_img">
<img src="{{ product.images[i].thumb(347,150,{'mode':'crop'}) }}" alt="photo">
<input type="hidden" name="old_imgs[{{i}}]">
</div>
{% endif %}
<div class="post_input">
<label>Загрузить фото #{{i+1}} <span>*</span></label>
<div class="upload_group">
@ -132,6 +159,11 @@
/>
</div>
</div>
{% if product.images[i] %}
<div class="select_delete" onclick="removeFunction()">
<img src="{{'assets/images/svg/red-close.svg'|theme}}" alt="">
</div>
{% endif %}
</div>
</div>
{% endfor %}

View File

@ -0,0 +1,13 @@
title = "Edit post"
url = "/edit-post/:id"
layout = "default"
is_hidden = 0
[viewBag]
localeUrl[en] = "/edit-post/:id"
localeUrl[ru] = "/edit-post/:id"
[offerform]
productId = "{{ :id }}"
==
{% component 'offerform' %}

View File

@ -1,2 +1,15 @@
title = "My offers"
title = "My posts"
url = "/my-posts"
layout = "default"
is_hidden = 0
[viewBag]
localeTitle[en] = "My posts"
localeTitle[ru] = "My posts"
localeUrl[en] = "/my-posts"
localeUrl[ru] = "/my-posts"
[myOffers]
perPage = 0
==
{% component 'myOffers' %}

View File

@ -125,7 +125,7 @@ code = "main-top"
</div>
</a>
<a href="my_post.html" class="profile_item">
<a href="{{'kabinet/my_offers'|page}}" class="profile_item">
<div class="profile_icon">
<img src="{{'assets/images/svg/clipboard.svg'|theme}}" alt="">
</div>