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

93 lines
2.6 KiB
PHP

<?php
namespace App\Backend;
class EcommerceBackend extends BaseBackend
{
private $_product = null;
private $_order = null;
public function __construct()
{
parent::__construct('Order');
$this->_product = new ProductBackend();
$this->_order = new OrderBackend();
}
final public function getOrderBackend()
{
$this->_order;
}
final public function getProductBackend()
{
$this->_product;
}
//초기선언부--------
//Title Field
public function getTitleField()
{
return "product_uid";
}
//Form Fields
public function getFields(string $action = ""): array
{
$fields = ['product_uid', "quantity", "price"];
switch ($action) {
default:
return $fields;
break;
}
}
public function getFieldFilters(): array
{
return ['product_uid', "user_uid"];
}
public function getFieldBatchFilters(): array
{
return ["status"];
}
public function getFieldRule(string $field, array $rules, string $action = ""): array
{
switch ($field) {
case $this->getTitleField():
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 'quantity':
case 'price':
$rules[$field] = "required|numeric";
break;
default:
throw new \Exception(__FUNCTION__ . "에서 오류발생: Field명:{$field}는 사용할수없습니다.");
break;
}
return $rules;
}
public function getFieldRules(array $fields, string $action)
{
$rules = array();
foreach ($fields as $field) {
$rules = $this->getFieldRule($field, $rules, $action);
}
return $rules;
}
//Entity값 가져오기
public function getEntity($uid)
{
throw new \Exception(__FUNCTION__ . "에서 오류발생: 사용할수없습니다.");
}
public function getEntitys($condition)
{
throw new \Exception(__FUNCTION__ . "에서 오류발생: 사용할수없습니다.");
}
//-------초기선언부
//장바구니에 담기
public function addCart(string $product_uid, int $quantity, int $price)
{
$product = $this->_product->getEntity($product_uid);
$this->_product->addCart($product, $quantity, $price);
$this->_order->addCart($product, $quantity, $price);
}
}