88 lines
3.7 KiB
PHP
88 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class EcommerceController extends AdminController
|
|
{
|
|
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
$this->_backend = service('ecommerce');
|
|
parent::initController($request, $response, $logger);
|
|
$this->_viewPath .= strtolower($this->_backend->getClassName());
|
|
}
|
|
|
|
//장바구니에 담기
|
|
public function addCart()
|
|
{
|
|
$msg = "";
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
//Transaction 시작
|
|
$this->_backend->transStart();
|
|
$this->insert_process();
|
|
$this->_backend->addCart($this->_viewDatas['fieldDatas']);
|
|
//Transaction Commit
|
|
$this->_backend->transCommit();
|
|
$msg = sprintf(
|
|
"%s에서 해당 상품 %s개를 장바구니에 담았습니다.",
|
|
$this->_viewDatas['title'],
|
|
$this->_viewDatas['fieldDatas']['quantity']
|
|
);
|
|
} catch (\Exception $e) {
|
|
//Transaction Rollback
|
|
$this->_backend->transRollback();
|
|
$msg = sprintf(
|
|
"%s에서 다음 오류로 인해 장바구니에 담기를 실패하였습니다.\n%s",
|
|
$this->_viewDatas['title'],
|
|
$e->getMessage()
|
|
);
|
|
log_message("error", $e->getMessage());
|
|
log_message("error", var_export($this->_viewDatas['fieldDatas'], true));
|
|
} finally {
|
|
$this->_session->setFlashdata("return_message", $msg);
|
|
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']));
|
|
}
|
|
}
|
|
|
|
//View관련
|
|
public function viewCart($order_uid)
|
|
{
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
helper(['form']);
|
|
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
|
|
$this->_viewDatas['order'] = $this->_backend->getOrderBackend()->getEntity($order_uid);
|
|
$this->_viewDatas['product'] = $this->_backend->getProductBackend()->getEntity($this->_viewDatas['order']->getProduct_uid());
|
|
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
return view($this->_viewPath . '/view', $this->_viewDatas);
|
|
} catch (\Exception $e) {
|
|
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']))->with('return_message', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
helper(['form']);
|
|
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
|
|
foreach ($this->_viewDatas['fieldFilters'] as $field) {
|
|
$this->_viewDatas[$field] = $this->request->getVar($field) ?: DEFAULTS['EMPTY'];
|
|
}
|
|
//모델 처리
|
|
$this->_viewDatas['entitys'] = $this->_backend->getOrderBackend()->getEntitys(['status' => DEFAULTS['STATUS']]);
|
|
// log_message("debug", __METHOD__ . "에서 호출:" . $this->_backend->getLastQuery());
|
|
//setting return_url to session flashdata
|
|
$this->_session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: "");
|
|
return view($this->_viewPath . '/index', $this->_viewDatas);
|
|
} catch (\Exception $e) {
|
|
return redirect()->back()->with('return_message', $e->getMessage());
|
|
}
|
|
}
|
|
}
|