gurl_o/plugins/tps/birzha/components/Singleoffer.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2023-07-23 05:57:06 +00:00
<?php namespace TPS\Birzha\Components;
use Cms\Classes\ComponentBase;
use TPS\Birzha\Models\Product;
2023-10-03 12:36:41 +00:00
use TPS\Birzha\Models\Comment;
use RainLab\User\Facades\Auth;
use Flash;
2023-07-23 05:57:06 +00:00
class Singleoffer extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'Single offer',
'description' => 'Selected offer'
];
}
public function defineProperties()
{
return [
'productSlug' => [
'title' => 'Product slug',
'description' => 'Product slug',
'type' => 'string',
'default' => '{{ :slug }}'
],
'offerId' => [
'title' => 'Offer id',
'description' => 'Offer id',
'type' => 'string',
'default' => '{{ :id }}'
]
];
}
2023-10-03 12:36:41 +00:00
public function onCommentSave(){
$data = post();
$comment = new Comment;
$comment->user_id = \Auth::user()->id;
$comment->product_id = $data["product_id"];
$comment->rating = $data["star"];
$comment->comment = $data["comment"];
$comment->save();
Flash::success("Teswir goshuldy");
}
2023-07-23 05:57:06 +00:00
public function onRun() {
$this->offer = $this->loadOffer();
}
2023-10-03 12:00:10 +00:00
protected function loadOffer() {
$product = Product::withCount("comments")->find($this->property('offerId'));
if($product && $product->status == 'approved') {
2023-07-23 05:57:06 +00:00
$product->number_of_views = $product->number_of_views + 1;
$product->save();
return $product;
}
return null;
}
public $offer;
}