shoppingmallv2/app/Backend/OrderBackend.php
최준흠git config git config --helpgit config --global user.name 최준흠 27d55ec628 shoppingmallv2 init...
2023-07-31 23:03:38 +09:00

49 lines
1.4 KiB
PHP

<?php
namespace App\Backend;
use App\Entities\OrderEntity;
use App\Entities\ProductEntity;
use App\Models\OrderModel;
use App\Models\ProductModel;
class OrderBackend extends BaseBackend
{
private $_productModel = null;
private $_product_uids = array();
public function __construct()
{
parent::__construct('Order');
$this->_model = new OrderModel();
}
//Porduct모델
final public function getProductModel(): ProductModel
{
return is_null($this->_productModel) ? new ProductModel() : $this->_productModel;
}
//Field별 Form Option용
public function getFieldFormOption(string $field): array
{
switch ($field) {
case 'product_uid':
$options = $this->_product_uids = $this->_product_uids ?: $this->getProductModel()->getFieldFormOptions([]);
break;
default:
return parent::getFieldFormOption($field);
break;
}
if (!is_array($options)) {
throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
}
return $options;
}
//장바구니에 담기 및 Product 재고 차감
public function addCart(ProductEntity $product, int $quantity, int $price): OrderEntity
{
return $this->_model->addCart($product, $quantity, $price);
}
}