shoppingmallv2 init...

This commit is contained in:
최준흠 2023-08-02 18:02:11 +09:00
parent 072e584a82
commit fd24fc032b
19 changed files with 60 additions and 48 deletions

View File

@ -39,6 +39,10 @@ $routes->get('/login', 'AuthController::login');
$routes->post('/signup', 'AuthController::signup/local');
$routes->get('/signup/(:alpha)', 'AuthController::signup/$1');
$routes->get('/logout', 'AuthController::logout');
$routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) {
$routes->post('addCart', 'CartController::addCart');
$routes->get('cancelCart', 'CartController::cancelCart');
});;
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
});
// authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함
@ -152,10 +156,6 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou
$routes->get('', 'OrderController::index');
$routes->get('view/(:uuid)', 'OrderController::view/$1');
});;
$routes->group('cart', static function ($routes) {
$routes->post('addCart', 'CartController::addCart');
$routes->post('cancelCart', 'CartController::cancelCart');
});;
});
/*
* --------------------------------------------------------------------

View File

@ -39,6 +39,10 @@ $routes->get('/login', 'AuthController::login');
$routes->post('/signup', 'AuthController::signup/local');
$routes->get('/signup/(:alpha)', 'AuthController::signup/$1');
$routes->get('/logout', 'AuthController::logout');
$routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) {
$routes->post('addCart', 'CartController::addCart');
$routes->get('cancelCart', 'CartController::cancelCart');
});;
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
});
// authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함
@ -151,11 +155,7 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou
$routes->group('order', static function ($routes) {
$routes->get('', 'OrderController::index');
$routes->get('view/(:uuid)', 'OrderController::view/$1');
});;
$routes->group('cart', static function ($routes) {
$routes->post('addCart', 'CartController::addCart');
$routes->post('cancelCart', 'CartController::cancelCart');
});;
});
});
/*
* --------------------------------------------------------------------

View File

@ -2,17 +2,17 @@
namespace App\Controllers\Admin;
use App\Models\BoardConfigModel;
use App\Models\BoardModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Models\BoardConfigModel;
class BoardController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_model = new BoardModel($this->getFields());
$this->_model = new BoardModel();
parent::initController($request, $response, $logger);
$this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title');
$this->_viewPath .= strtolower($this->_model->getClassName());

View File

@ -11,7 +11,7 @@ class OrderController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_model = new OrderModel($this->getFields());
$this->_model = new OrderModel();
parent::initController($request, $response, $logger);
$this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title');
$this->_viewPath .= strtolower($this->_model->getClassName());

View File

@ -2,17 +2,17 @@
namespace App\Controllers\Admin;
use App\Models\CategoryModel;
use App\Models\ProductModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Models\CategoryModel;
class ProductController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_model = new ProductModel($this->getFields());
$this->_model = new ProductModel();
parent::initController($request, $response, $logger);
$this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title');
$this->_viewPath .= strtolower($this->_model->getClassName());

View File

@ -11,7 +11,7 @@ class UserController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_model = new UserModel($this->getFields());
$this->_model = new UserModel();
parent::initController($request, $response, $logger);
$this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title');
$this->_viewPath .= strtolower($this->_model->getClassName());

View File

@ -11,7 +11,7 @@ class UserSNSController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_model = new UserSNSModel($this->getFields());
$this->_model = new UserSNSModel();
parent::initController($request, $response, $logger);
$this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title');
$this->_viewPath .= strtolower($this->_model->getClassName());

View File

@ -51,22 +51,15 @@ class CartController extends Controller
}
private function getOrderModel()
{
return $this->_orderModel = $this->_orderModel ?: new OrderModel();
return $this->_orderModel = $this->_orderModel ?: new OrderModel(["product_uid", "quantity", "price", "status"]);
}
private function getProductModel()
{
return $this->_productModel = $this->_productModel ?: new ProductModel();
}
final public function init()
{
$this->_viewDatas['fields'] = ["product_uid", "quantity", "price", "status"];
$this->_viewDatas['fieldRules'] = $this->getOrderModel()->getFieldRules($this->_viewDatas['fields']);
return $this->_viewDatas;
}
//주문
protected function addCart_validate()
private function addCart_validate()
{
//fieldData Rule 검사
if (!$this->validate($this->_viewDatas['fieldRules'])) {
@ -75,7 +68,7 @@ class CartController extends Controller
//fieldData 적용
$this->_viewDatas['fieldDatas'] = array();
foreach ($this->_viewDatas['fields'] as $field) {
$this->_viewDatas['fieldDatas'] = $this->request->getVar($field);
$this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
}
}
@ -83,7 +76,8 @@ class CartController extends Controller
{
$msg = "";
try {
$this->_viewDatas = $this->init(__FUNCTION__);
$this->_viewDatas['fields'] = ["product_uid", "quantity", "price", "status"];
$this->_viewDatas['fieldRules'] = $this->getOrderModel()->getFieldRules($this->_viewDatas['fields']);
//Transaction 시작
$this->getOrderModel()->transStart();
//장바구니정보 검증
@ -103,6 +97,8 @@ class CartController extends Controller
$this->_viewDatas['fieldDatas'][$this->getOrderModel()->getTitleField()] = $product->getTitle();
//주문추가
$entity = $this->getOrderModel()->addCart($this->_viewDatas['fieldDatas']);
echo var_export($entity, true);
exit;
//상품재고감소
$this->getProductModel()->addCart($product, $this->_viewDatas['fieldDatas']['quantity']);
//주문정보 세션에 넣기

View File

@ -40,8 +40,4 @@ class OrderEntity extends BaseEntity
{
return $this->attributes['quantity'];
}
public function geSession_Id()
{
return $this->attributes['sess_id'];
}
}

View File

@ -47,7 +47,7 @@ abstract class BaseModel extends Model
{
$this->_className = $className;
parent::__construct();
$this->allowedFields = ["updated_at", "created_at"];
$this->allowedFields = ["uid", "updated_at", "created_at"];
if (!$this->useAutoIncrement) {
array_push($this->allowedFields, $this->primaryKey);
}

View File

@ -9,10 +9,14 @@ class BoardConfigModel extends BaseModel
protected $table = "tw_board_config";
protected $useAutoIncrement = false;
protected $returnType = BoardConfigEntity::class;
public function __construct(array $fields = array())
public function __construct()
{
parent::__construct('BoardConfig');
$this->allowedFields = [...$this->allowedFields, ...$fields];
$this->allowedFields = [
...$this->allowedFields,
'name', "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload",
"head", "tail", "status"
];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
public function getTitleField(): string

View File

@ -9,10 +9,15 @@ class BoardModel extends BaseHierarchyModel
private $_boardconfig_options = null;
protected $table = "tw_board";
protected $returnType = BoardEntity::class;
public function __construct(array $fields = array())
public function __construct()
{
parent::__construct('Board');
$this->allowedFields = [...$this->allowedFields, "user_uid", ...$fields];
$this->allowedFields = [
...$this->allowedFields,
"board_config_uid",
"user_uid", 'title', "content",
"passwd", "board_file", "view_cnt", "status"
];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
public function getTitleField(): string

View File

@ -9,10 +9,10 @@ class CategoryModel extends BaseHierarchyModel
//BaseHierarchyModel를 확장하면 grpno가 숫자이고, primarykey를 대분류 생성시 copy하여 grpno에 넣고 sorting하므로
protected $table = "tw_category";
protected $returnType = CategoryEntity::class;
public function __construct(array $fields = array())
public function __construct()
{
parent::__construct('Category');
$this->allowedFields = [...$this->allowedFields, ...$fields];
$this->allowedFields = [...$this->allowedFields, 'name', "head", "tail", "status"];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
public function getTitleField(): string

View File

@ -11,10 +11,10 @@ class OrderModel extends BaseModel
protected $useAutoIncrement = false;
protected $returnType = OrderEntity::class;
protected $useSoftDeletes = true;
public function __construct(array $fields = array())
public function __construct()
{
parent::__construct('Order');
$this->allowedFields = ["uid", "user_uid", "name", ...$this->allowedFields, ...$fields];
$this->allowedFields = [...$this->allowedFields, 'product_uid', "user_uid", "name", "quantity", "price", "status"];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
final public function getTitleField(): string

View File

@ -11,10 +11,15 @@ class ProductModel extends BaseModel
protected $useAutoIncrement = false;
protected $returnType = ProductEntity::class;
protected $useSoftDeletes = true;
public function __construct(array $fields = array())
public function __construct()
{
parent::__construct('Product');
$this->allowedFields = ["uid", "user_uid", ...$this->allowedFields, ...$fields];
$this->allowedFields = [
...$this->allowedFields,
"category_uid", "user_uid",
'name', "photo", "cost", "price", "sale",
"stock", "view_cnt", "content", "status"
];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
public function getTitleField(): string

View File

@ -10,10 +10,13 @@ class UserModel extends BaseModel
protected $useAutoIncrement = false;
protected $returnType = UserEntity::class;
protected $useSoftDeletes = true;
public function __construct(array $fields = array())
public function __construct()
{
parent::__construct('User');
$this->allowedFields = ["uid", ...$this->allowedFields, ...$fields];
$this->allowedFields = [
...$this->allowedFields,
"id", "passwd", 'name', "email", "role", "status"
];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
public function getTitleField(): string

View File

@ -8,10 +8,13 @@ class UserSNSModel extends BaseModel
{
protected $table = "tw_user_sns";
protected $returnType = UserSNSEntity::class;
public function __construct(array $fields = array())
public function __construct()
{
parent::__construct('UserSNS');
$this->allowedFields = [...$this->allowedFields, "user_uid", ...$fields];
$this->allowedFields = [
...$this->allowedFields,
"site", "id", 'name', "email", "detail", "status"
];
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
}
public function getTitleField(): string

View File

@ -26,7 +26,7 @@
<?php endforeach; ?>
<td>
<?php if ($entity->getStatus() == DEFAULTS['STATUS']) : ?>
<?= anchor('/front/cart/cancelCart/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
<?= anchor('cart/cancelCart/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
<?php endif; ?>
</td>
</tr>

View File

@ -1,4 +1,4 @@
<?= form_open("front/cart/addCart", ['method' => 'post']) ?>
<?= form_open("cart/addCart", ['method' => 'post']) ?>
<?= form_hidden("product_uid", $entity->getPrimaryKey()) ?>
<input type="hidden" id="price" name="price" value="<?= ($entity->getPrice() - $entity->getSale()) * 1 ?>">
<?php