shoppingmallv2 init...
This commit is contained in:
parent
1085cd7bdc
commit
6b41a6c3d9
@ -122,14 +122,11 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
});
|
||||
$routes->group('order', static function ($routes) {
|
||||
$routes->get('', 'OrderController::index');
|
||||
$routes->post('insert/(:uuid)', 'OrderController::insert/$1');
|
||||
$routes->get('view/(:uuid)', 'OrderController::view/$1');
|
||||
$routes->post('batchjob', 'OrderController::batchjob`');
|
||||
$routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
});
|
||||
$routes->group('ecommerce', static function ($routes) {
|
||||
$routes->get('', 'EcommerceController::index');
|
||||
$routes->post('addcart', 'EcommerceController::addCart');
|
||||
});
|
||||
});
|
||||
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
|
||||
$routes->get('/', 'Home::index');
|
||||
|
||||
@ -29,12 +29,4 @@ class Services extends BaseService
|
||||
* return new \CodeIgniter\Example();
|
||||
* }
|
||||
*/
|
||||
|
||||
public static function ecommerce($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('ecommerce');
|
||||
}
|
||||
return new \App\Service\EcommerceService();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
/**
|
||||
* Services Configuration file.
|
||||
*
|
||||
* Services are simply other classes/libraries that the system uses
|
||||
* to do its job. This is used by CodeIgniter to allow the core of the
|
||||
* framework to be swapped out easily without affecting the usage within
|
||||
* the rest of your application.
|
||||
*
|
||||
* This file holds any application-specific services, or service overrides
|
||||
* that you might need. An example has been included with the general
|
||||
* method format you should use for your service methods. For more examples,
|
||||
* see the core Services file at system/Config/Services.php.
|
||||
*/
|
||||
class Services extends BaseService
|
||||
{
|
||||
/*
|
||||
* public static function example($getShared = true)
|
||||
* {
|
||||
* if ($getShared) {
|
||||
* return static::getSharedInstance('example');
|
||||
* }
|
||||
*
|
||||
* return new \CodeIgniter\Example();
|
||||
* }
|
||||
*/
|
||||
public static function user($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('user');
|
||||
}
|
||||
return new \App\Backend\UserBackend();
|
||||
}
|
||||
public static function usersns($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('usersns');
|
||||
}
|
||||
return new \App\Backend\UserSNSBackend();
|
||||
}
|
||||
public static function board($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('board');
|
||||
}
|
||||
return new \App\Backend\BoardBackend();
|
||||
}
|
||||
public static function boardconfig($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('boardconfig');
|
||||
}
|
||||
return new \App\Backend\BoardConfigBackend();
|
||||
}
|
||||
public static function category($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('category');
|
||||
}
|
||||
return new \App\Backend\CategoryBackend();
|
||||
}
|
||||
public static function product($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('product');
|
||||
}
|
||||
return new \App\Backend\ProductBackend();
|
||||
}
|
||||
public static function order($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('order');
|
||||
}
|
||||
return new \App\Backend\OrderBackend();
|
||||
}
|
||||
public static function ecommerce($getShared = true)
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('ecommerce');
|
||||
}
|
||||
return new \App\Backend\EcommerceBackend();
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class EcommerceController extends AdminController
|
||||
{
|
||||
private $_service = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
$this->_service = service('ecommerce');
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_viewPath .= strtolower($this->_service->getClassName());
|
||||
}
|
||||
|
||||
protected function addCart_process()
|
||||
{
|
||||
//fieldData Rule 검사
|
||||
if (!$this->validate($this->_viewDatas['fieldRules'])) {
|
||||
throw new \Exception("장비구니 검증 오류발생\n" . implode("\n", $this->validator->getErrors()));
|
||||
}
|
||||
//fieldData 적용
|
||||
$this->_viewDatas['fieldDatas'] = array();
|
||||
foreach ($this->_viewDatas['fields'] as $field) {
|
||||
$this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field);
|
||||
}
|
||||
}
|
||||
//장바구니에 담기
|
||||
public function addCart()
|
||||
{
|
||||
$msg = "";
|
||||
try {
|
||||
$this->_viewDatas['fields'] = $this->_service->getFields(__FUNCTION__);
|
||||
$this->_viewDatas['fieldRules'] = $this->_service->getFieldRules($this->_viewDatas['fields'], __FUNCTION__);
|
||||
//Transaction 시작
|
||||
$this->_service->transStart();
|
||||
$this->addCart_process();
|
||||
$this->_service->addCart($this->_viewDatas['fieldDatas']);
|
||||
//Transaction Commit
|
||||
$this->_service->transCommit();
|
||||
$msg = sprintf(
|
||||
"%s에서 해당 상품 %s개를 장바구니에 담았습니다.",
|
||||
$this->_viewDatas['title'],
|
||||
$this->_viewDatas['fieldDatas']['quantity']
|
||||
);
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->_service->transRollback();
|
||||
log_message("error", $e->getMessage());
|
||||
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
|
||||
$msg = sprintf(
|
||||
"%s에서 다음 오류로 인해 장바구니에 담기를 실패하였습니다.\n%s",
|
||||
$this->_viewDatas['title'],
|
||||
$e->getMessage()
|
||||
);
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
} finally {
|
||||
$this->_session->setFlashdata("return_message", $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,4 +16,39 @@ class OrderController extends AdminController
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_viewPath .= strtolower($this->_model->getClassName());
|
||||
}
|
||||
|
||||
//장바구니에 담기
|
||||
public function insert()
|
||||
{
|
||||
$msg = "";
|
||||
try {
|
||||
$this->_viewDatas['fields'] = $this->_model->getFields(__FUNCTION__);
|
||||
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], __FUNCTION__);
|
||||
//Transaction 시작
|
||||
$this->_model->transStart();
|
||||
$this->insert_process();
|
||||
$this->_model->addCart($this->_viewDatas['fieldDatas']);
|
||||
//Transaction Commit
|
||||
$this->_model->transCommit();
|
||||
$msg = sprintf(
|
||||
"%s에서 해당 상품 %s개를 장바구니에 담았습니다.",
|
||||
$this->_viewDatas['title'],
|
||||
$this->_viewDatas['fieldDatas']['quantity']
|
||||
);
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->_model->transRollback();
|
||||
log_message("error", $e->getMessage());
|
||||
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
|
||||
$msg = sprintf(
|
||||
"%s에서 다음 오류로 인해 장바구니에 담기를 실패하였습니다.\n%s",
|
||||
$this->_viewDatas['title'],
|
||||
$e->getMessage()
|
||||
);
|
||||
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
||||
} finally {
|
||||
$this->_session->setFlashdata("return_message", $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Models\OrderModel;
|
||||
use App\Models\ProductModel;
|
||||
|
||||
class EcommerceService
|
||||
{
|
||||
private $_productModel = null;
|
||||
private $_orderModel = null;
|
||||
public function __construct()
|
||||
{
|
||||
$this->_productModel = new ProductModel();
|
||||
$this->_orderModel = new OrderModel();
|
||||
}
|
||||
|
||||
//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->_productModel->getEntity($fieldDatas['product_uid']);
|
||||
$this->_productModel->addCart($product, $fieldDatas['quantity'], $fieldDatas['price']);
|
||||
$this->_orderModel->addCart($product, $fieldDatas['quantity'], $fieldDatas['price']);
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
<?= $this->extend('layouts/admin') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<div class="content">
|
||||
<div class="top">
|
||||
<?= form_open(current_url(), array("method" => "get")) ?>
|
||||
<ul class="nav">
|
||||
조건검색:<?php foreach ($fieldFilters as $field) : ?><li class="nav-item"><?= getFieldFilter_OrderHelper($field, $$field, $fieldFormOptions) ?></li><?php endforeach; ?>
|
||||
<?= $this->include('templates/admin/index_head'); ?>
|
||||
</ul>
|
||||
<?= form_close(); ?>
|
||||
</div>
|
||||
<?= form_open(current_url() . '/batchjob', $forms['attributes'], $forms['hiddens']) ?>
|
||||
<table class="table table-bordered table-hover table-striped">
|
||||
<tr>
|
||||
<th>번호</th>
|
||||
<?php foreach ($fields as $field) : ?><th><?= getFieldIndex_Column_OrderHelper($field, $order_field, $order_value) ?></th><?php endforeach; ?>
|
||||
<th>작업</th>
|
||||
</tr>
|
||||
<?php $i = 0; ?>
|
||||
<?php foreach ($entitys as $entity) : ?>
|
||||
<tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->getStatus() != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this);">
|
||||
<td>
|
||||
<?= form_checkbox(["id" => "checkbox_uid_{$entity->getPrimaryKey()}", "name" => "batchjob_uids[]", "value" => $entity->getPrimaryKey(), "class" => "batchjobuids_checkboxs"]); ?>
|
||||
<?= $total_count - (($page - 1) * $per_page + $i) ?>
|
||||
</td>
|
||||
<?php foreach ($fields as $field) : ?>
|
||||
<td nowrap><?= getFieldIndex_Row_OrderHelper($field, $entity, $fieldFilters, $fieldFormOptions) ?></td>
|
||||
<?php endforeach; ?>
|
||||
<td>
|
||||
<?= $entity->getStatus() == DEFAULTS['STATUS'] ? anchor(current_url() . '/delete/' . $entity->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) : "" ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $i++; ?>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<div class="bottom">
|
||||
<ul class="nav justify-content-center">
|
||||
<li class="nav-item"><?= form_checkbox(array("id" => "batchjobuids_checkbox")) ?>ALL</li>
|
||||
<?php foreach ($batchjobFilters as $field) : ?><li class="nav-item"><?= getFieldFilter_OrderHelper($field, DEFAULTS['EMPTY'], $fieldFormOptions) ?></li><?php endforeach; ?>
|
||||
<li class="nav-item"><?= form_submit('', '일괄처리', array("class" => "btn btn-outline btn-warning")); ?></li>
|
||||
</ul>
|
||||
<?= $pagination ?>
|
||||
</div>
|
||||
<?= form_close(); ?>
|
||||
</div>
|
||||
<?= $this->endSection() ?>
|
||||
@ -1,34 +0,0 @@
|
||||
<?= $this->extend('layouts/admin') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<?= $this->include('templates/admin/header'); ?>
|
||||
<table class="table table-bordered table-hover table-striped indexTable ">
|
||||
<tr>
|
||||
<td>제품명</td>
|
||||
<td><?= $product->getTitle() ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>판매가</td>
|
||||
<td><?= number_format($product->getPrice()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>할인가</td>
|
||||
<td><?= number_format($product->getSale()) ?>원</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>판매금액</td>
|
||||
<td><?= number_format($product->getPrice() - $product->getSale()) ?>원</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>구매수량</td>
|
||||
<td><?= $order->getQuantity() ?>개</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>구매금액</td>
|
||||
<td><?= number_format($order->getPrice()) ?>원</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><?= html_entity_decode($product->getContent()) ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?= $this->include('templates/admin/footer'); ?>
|
||||
<?= $this->endSection() ?>
|
||||
@ -1,4 +1,4 @@
|
||||
<?= form_open("admin/ecommerce/addcart", ['method' => 'post']) ?>
|
||||
<?= form_open("admin/order/insert", ['method' => 'post']) ?>
|
||||
<?= form_hidden("product_uid", $entity->getPrimaryKey()) ?>
|
||||
<?= form_hidden("price", $entity->getPrice() - $entity->getSale()) ?>
|
||||
구매 수량 : <?= getFieldForm_ProductHelper('quantity', 1, $fieldFormOptions) ?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user