Handling images
This commit is contained in:
parent
c197e75f22
commit
dbe268c561
30
app/Classes/ImageTrait.php
Normal file
30
app/Classes/ImageTrait.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes;
|
||||
|
||||
use ApiLink;
|
||||
|
||||
trait ImageTrait {
|
||||
|
||||
public function getProductImage($id_image, $link_rewrite, $type = 'home') {
|
||||
$img = (new ApiLink())->getImageLink($link_rewrite, $id_image, $type);
|
||||
return str_replace($_SERVER['SERVER_NAME'], env('DOMAIN_STATIC'), $img);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image for a given sale
|
||||
*
|
||||
* @param $id_sale integer The id sales
|
||||
* @param $active boolean Whether to return inactive image of the sale
|
||||
*
|
||||
* @return string url to the sale image
|
||||
*/
|
||||
public function getSaleImage($id_sale, $active = true) {
|
||||
global $cookie;
|
||||
|
||||
$extension = $active === true ? 'liston' : 'listoff';
|
||||
return env('DOMAIN_STATIC') .
|
||||
__PS_BASE_URI__.'modules/privatesales/img/' . $id_sale . '/' .
|
||||
$extension . '_' . $cookie->id_lang . '.jpg';
|
||||
}
|
||||
}
|
36
app/Models/Product/ProductDetail.php
Normal file
36
app/Models/Product/ProductDetail.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Product;
|
||||
|
||||
use Antadis\API\Front\Models\Product\ProductDetail as BaseProductDetail;
|
||||
use App\Classes\ImageTrait;
|
||||
/**
|
||||
* @rest\model Product
|
||||
* @rest\property integer id_product
|
||||
* @rest\property string name
|
||||
* @rest\property string description
|
||||
* @rest\property string description_short
|
||||
* @rest\property string price
|
||||
* @rest\property string price_wo_reduction
|
||||
* @rest\property integer quantity
|
||||
* @rest\property boolean on_sale
|
||||
* @rest\property string reduction
|
||||
* @rest\property string ecotax
|
||||
* @rest\property array attributes
|
||||
* @rest\property array imgs
|
||||
*/
|
||||
class ProductDetail extends BaseProductDetail {
|
||||
use ImageTrait;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() {
|
||||
global $cookie;
|
||||
$product = parent::toArray();
|
||||
$images = $this->getImages($cookie->id_lang);
|
||||
foreach ($images as $image) {
|
||||
$product['imgs'][] = $this->getProductImage($image['id_image'], $this->link_rewrite, 'product_carre');
|
||||
}
|
||||
return $product;
|
||||
}
|
||||
}
|
@ -3,20 +3,18 @@
|
||||
namespace App\Models\Product;
|
||||
|
||||
use Antadis\API\Front\Models\Product\ProductList as BaseProduct;
|
||||
use App\Classes\ImageTrait;
|
||||
|
||||
class ProductList extends BaseProduct {
|
||||
use ImageTrait;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() {
|
||||
$product = parent::toArray();
|
||||
|
||||
$id_image = $this->getCover($this->id);
|
||||
$id_image = $id_image['id_image'];
|
||||
$img = (new \Link())->getImageLink($this->link_rewrite, $id_image, 'home');
|
||||
$img = str_replace($_SERVER['SERVER_NAME'], env('DOMAIN_STATIC'), $img);
|
||||
|
||||
$product['img'] = $img;
|
||||
$image = $this->getCover($this->id);
|
||||
$product['img'] = $this->getProductImage($image['id_image'], $this->link_rewrite, 'home');
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,17 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Antadis\API\Front\Models\Sale as BaseSale;
|
||||
use App\Classes\ImageTrait;
|
||||
|
||||
class Sale extends BaseSale {
|
||||
use ImageTrait;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() {
|
||||
$sale = parent::toArray();
|
||||
$sale['img'] = env('DOMAIN_STATIC') . 'modules/privatesales/img/' . $this->id . '/liston_2.jpg';
|
||||
$is_active = strtotime($this->date_start) < strtotime(date('Y-m-d 07:00:00'));
|
||||
$sale['img'] = $this->getSaleImage($this->id, $is_active);
|
||||
return $sale;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user