Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Eshop\Controller;
- class Cart extends \Controller\Base
- {
- public function action_index()
- {
- // check if cart is empty
- if(\Eshop\Cart::total_qty() == 0)
- {
- $view = \View::forge('modules/eshop/cart-empty');
- // breadcrumb
- $view->breadcrumb = array(
- array(
- 'url' => \Uri::current(),
- 'title' => __('eshop.cart.title_empty'),
- ),
- );
- return $view;
- }
- $view = \View::forge('modules/eshop/cart');
- // breadcrumb
- $view->breadcrumb = array(
- array(
- 'url' => \Uri::current(),
- 'title' => __('eshop.cart.title').' - '.__('eshop.checkout.title'),
- ),
- );
- // load assets
- // forms
- \Asset::css('compiled/page-forms.css', array(), 'styles');
- \Asset::css('page-forms.less', array('rel' => 'stylesheet/less'), 'dev_styles');
- \Asset::js('pureSelect/pureSelect.jquery.js', array(), 'scripts');
- \Asset::js('forms.js', array(), 'scripts');
- // page
- \Asset::css('compiled/page-cart-checkout.css', array(), 'styles');
- \Asset::css('page-cart-checkout.less', array('rel' => 'stylesheet/less'), 'dev_styles');
- \Asset::js('eshop/cart/js/cart.js', array(), 'scripts');
- $view->items = \Eshop\Cart::items();
- return $view;
- }
- public function action_insert()
- {
- // reset messages
- \Messages::reset();
- if (\Input::method() == 'POST')
- {
- \Eshop\Cart::add(array(
- 'name' => \Input::post('name'),
- 'id' => \Input::post('id'),
- 'qty' => \Input::post('qty', 1),
- 'url' => \Input::post('url'),
- ));
- \Messages::success(__('eshop.cart.item_was_inserted'));
- }
- \Response::redirect_back(\Router::get('eshop[cart]'));
- }
- public function action_remove($id)
- {
- // reset messages
- \Messages::reset();
- \Eshop\Cart::remove($id);
- \Messages::success(__('eshop.cart.item_was_removed'));
- if(\Input::is_ajax())
- {
- \Messages::reset();
- return $this->get_cart_contents();
- }
- \Response::redirect_back(\Router::get('eshop[cart]'));
- }
- public function action_update()
- {
- // reset messages
- \Messages::reset();
- if (\Input::method() == 'POST')
- {
- $qtys = \Input::post('qty');
- foreach($qtys as $id => $qty)
- {
- $item = \Eshop\Cart::item($id);
- $item->update('qty', $qty);
- }
- \Messages::success(__('eshop.cart.cart_was_updated'));
- }
- if(\Input::is_ajax())
- {
- \Messages::reset();
- return $this->get_cart_contents();
- }
- \Response::redirect_back(\Router::get('eshop[cart]'));
- }
- public function action_get_cart_header()
- {
- return \View::forge('modules/eshop/cart/header');
- }
- protected function get_cart_contents()
- {
- $view = \View::forge('modules/eshop/cart/contents');
- $view->items = \Eshop\Cart::items();
- return $view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement