64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Backend;
|
|
|
|
use App\Models\OrderModel;
|
|
use App\Models\ProductModel;
|
|
|
|
class EcommerceBackend extends BaseBackend
|
|
{
|
|
private $_product = null;
|
|
private $_order = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct('Ecommerce');
|
|
$this->_product = new ProductBackend();
|
|
$this->_order = new OrderBackend();
|
|
}
|
|
|
|
final public function getOrderBackend()
|
|
{
|
|
$this->_order;
|
|
}
|
|
final public function getProductBackend()
|
|
{
|
|
$this->_product;
|
|
}
|
|
|
|
//Form Fields
|
|
public function getFields(string $action): array
|
|
{
|
|
return ["product_uid", "quantity", "price", "status"];
|
|
}
|
|
//Field별 Form Rule용
|
|
public function getFieldRules(array $fields, string $action): array
|
|
{
|
|
$rules = array();
|
|
foreach ($fields as $field) {
|
|
switch ($field) {
|
|
case "product_uid":
|
|
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
|
|
break;
|
|
case "sess_id":
|
|
$rules[$field] = "required|string";
|
|
break;
|
|
case 'quantity':
|
|
case 'price':
|
|
$rules[$field] = "required|numeric";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return $rules;
|
|
}
|
|
|
|
//장바구니에 담기
|
|
public function addCart(array $fieldDatas)
|
|
{
|
|
$product = $this->_product->getEntity($fieldDatas['product_uid']);
|
|
$this->_product->addCart($product, $fieldDatas['quantity'], $fieldDatas['price']);
|
|
$this->_order->addCart($product, $fieldDatas['quantity'], $fieldDatas['price']);
|
|
}
|
|
}
|