diff --git a/plugins/tps/birzha/Plugin.php b/plugins/tps/birzha/Plugin.php index 4e0faea41..999d84fc5 100644 --- a/plugins/tps/birzha/Plugin.php +++ b/plugins/tps/birzha/Plugin.php @@ -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', ]; } diff --git a/plugins/tps/birzha/components/MyOffers.php b/plugins/tps/birzha/components/MyOffers.php new file mode 100644 index 000000000..11f8558c2 --- /dev/null +++ b/plugins/tps/birzha/components/MyOffers.php @@ -0,0 +1,73 @@ + '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); + } + + +} diff --git a/plugins/tps/birzha/components/OfferForm.php b/plugins/tps/birzha/components/OfferForm.php index 79c667612..149e4ae77 100644 --- a/plugins/tps/birzha/components/OfferForm.php +++ b/plugins/tps/birzha/components/OfferForm.php @@ -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; + } } } \ No newline at end of file diff --git a/plugins/tps/birzha/components/myOffers/default.htm b/plugins/tps/birzha/components/myOffers/default.htm new file mode 100644 index 000000000..493d7324c --- /dev/null +++ b/plugins/tps/birzha/components/myOffers/default.htm @@ -0,0 +1,153 @@ +{% set offers = __SELF__.offers %} + + +
+
+
+
+
+ Мои объявления +
+
+
+ + + +
+
+ + + +
+
+
+
+
+ Лот №: +
+
+ Изображение +
+
+ Товар +
+
+ Количество: +
+
+ Стартовая цена: +
+
+ Дата окончания: +
+
+
+ {% for offer in offers %} +
+
+
+ {{ 'page.prod_id'|_ }} №: +
+
+ № {{offer.id}} +
+
+
+ № {{offer.id}} +
+
+ +
+
+
+ {{ offer.name }} +
+
+ {{ offer.name }} +
+
+
+
+ {{ 'page.prod_amount'|_ }}: +
+
+ {{ offer.quantity }} {{ offer.measure.code }}. +
+
+
+
+ {{ 'page.prod_price'|_ }}: +
+
+ {{ offer.price }} {{offer.currency.code}} / 1 {{ offer.measure.code }}. +
+
+
+
+ {{ 'page.prod_finishdate'|_ }}: +
+
+ {{ offer.ends_at|date('d.m.Y') }} +
+
+ + + {% if offer.status == "approved" %} + {{offer.status}} + + На сайте + + {% elseif offer.status == "denied" %} + {{offer.status}}
+ {{ offer.status_note }} + + Edit + + {% elseif offer.status == "draft" %} + {{offer.status}} + + Complete + + {% elseif offer.status == "new" %} + {{offer.status}} + + Admin is checking + + {% elseif offer.status == "disabled" %} + {{offer.status}} + + Продлить + + {% endif %} +
+ {% endfor %} +
+ + {% if offers.total > offers.perPage %} + +
+ + + +
+ +
+ + + +
+ {{ (offers.total / offers.perPage)|round(0,'ceil') }} {{ 'page.pages'|_ }} +
+
+ + {% endif %} + +
+
+
+ \ No newline at end of file diff --git a/plugins/tps/birzha/components/offerForm/default.htm b/plugins/tps/birzha/components/offerForm/default.htm index 53be484f1..78e7a3875 100644 --- a/plugins/tps/birzha/components/offerForm/default.htm +++ b/plugins/tps/birzha/components/offerForm/default.htm @@ -1,6 +1,7 @@ {% set categories = __SELF__.categories %} {% set countries = __SELF__.countries %} +{% set productForEditing = __SELF__.productForEditing %}
@@ -17,36 +18,58 @@ data-request-flash class="post_form post_form-2 first-step-form"> - + {% if productForEditing %} + + {% endif %}
- +
- +
- +
- +
- +
@@ -56,7 +79,11 @@ @@ -68,7 +95,11 @@ diff --git a/plugins/tps/birzha/components/offerForm/second_step_form.htm b/plugins/tps/birzha/components/offerForm/second_step_form.htm index 1372a1d1c..30dc65278 100644 --- a/plugins/tps/birzha/components/offerForm/second_step_form.htm +++ b/plugins/tps/birzha/components/offerForm/second_step_form.htm @@ -16,7 +16,11 @@ @@ -24,7 +28,8 @@
- +
@@ -34,7 +39,11 @@ @@ -42,7 +51,8 @@
- +
@@ -52,7 +62,11 @@ @@ -60,7 +74,8 @@
- +
@@ -69,8 +84,16 @@
@@ -81,31 +104,29 @@ - -
- +
- +
- +
@@ -116,7 +137,13 @@ {% for i in 0..2 %}
- + {% if product.images[i] %} +
+ photo + +
+ {% endif %} +
@@ -132,6 +159,11 @@ />
+ {% if product.images[i] %} +
+ +
+ {% endif %}
{% endfor %} diff --git a/themes/birzha/pages/kabinet/edit_post.htm b/themes/birzha/pages/kabinet/edit_post.htm new file mode 100644 index 000000000..111822563 --- /dev/null +++ b/themes/birzha/pages/kabinet/edit_post.htm @@ -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' %} \ No newline at end of file diff --git a/themes/birzha/pages/kabinet/my_offers.htm b/themes/birzha/pages/kabinet/my_offers.htm index 4c54dbc8d..92c7fc7fd 100644 --- a/themes/birzha/pages/kabinet/my_offers.htm +++ b/themes/birzha/pages/kabinet/my_offers.htm @@ -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' %} \ No newline at end of file diff --git a/themes/birzha/partials/header.htm b/themes/birzha/partials/header.htm index a8f2eb19b..d0f075696 100644 --- a/themes/birzha/partials/header.htm +++ b/themes/birzha/partials/header.htm @@ -125,7 +125,7 @@ code = "main-top" - +