Exemplo n.º 1
0
 /**
  * Sets the necessary parameter values in the view.
  */
 public function process()
 {
     $view = $this->getView();
     $context = $this->_getContext();
     try {
         /** client/html/basket/standard/require-stock
          * Customers can order products only if there are enough products in stock
          *
          * @deprecated Use "client/html/basket/require-stock" instead
          * @see client/html/basket/require-stock
          */
         $reqstock = $view->config('client/html/basket/standard/require-stock', true);
         /** client/html/basket/standard/require-variant
          * A variant of a selection product must be chosen
          *
          * @deprecated Use "client/html/basket/require-variant" instead
          * @see client/html/basket/require-variant
          */
         $reqvariant = $view->config('client/html/basket/standard/require-variant', true);
         $options = array('stock' => $view->config('client/html/basket/require-stock', $reqstock), 'variant' => $view->config('client/html/basket/require-variant', $reqvariant));
         switch ($view->param('b-action')) {
             case 'add':
                 $this->_addProducts($view, $options);
                 break;
             case 'delete':
                 $this->_deleteProducts($view);
                 break;
             default:
                 $this->_editProducts($view, $options);
         }
         parent::process();
         $controller = Controller_Frontend_Factory::createController($context, 'basket');
         $controller->get()->check(MShop_Order_Item_Base_Abstract::PARTS_PRODUCT);
     } catch (Client_Html_Exception $e) {
         $error = array($context->getI18n()->dt('client/html', $e->getMessage()));
         $view->standardErrorList = $view->get('standardErrorList', array()) + $error;
     } catch (Controller_Frontend_Exception $e) {
         $error = array($context->getI18n()->dt('controller/frontend', $e->getMessage()));
         $view->standardErrorList = $view->get('standardErrorList', array()) + $error;
     } catch (MShop_Plugin_Provider_Exception $e) {
         $errors = array($context->getI18n()->dt('mshop', $e->getMessage()));
         $errors = array_merge($errors, $this->_translatePluginErrorCodes($e->getErrorCodes()));
         $view->summaryErrorCodes = $e->getErrorCodes();
         $view->standardErrorList = $view->get('standardErrorList', array()) + $errors;
     } catch (MShop_Exception $e) {
         $error = array($context->getI18n()->dt('mshop', $e->getMessage()));
         $view->standardErrorList = $view->get('standardErrorList', array()) + $error;
     } catch (Exception $e) {
         $context->getLogger()->log($e->getMessage() . PHP_EOL . $e->getTraceAsString());
         $error = array($context->getI18n()->dt('client/html', 'A non-recoverable error occured'));
         $view->standardErrorList = $view->get('standardErrorList', array()) + $error;
     }
 }
Exemplo n.º 2
0
 /**
  * Processes the input, e.g. store given values.
  * A view must be available and this method doesn't generate any output
  * besides setting view variables.
  */
 public function process()
 {
     $view = $this->getView();
     $context = $this->_getContext();
     switch ($view->param('b_action')) {
         case 'coupon-delete':
             if (($coupon = $view->param('b_coupon')) != '') {
                 $this->_clearCached();
                 $cntl = Controller_Frontend_Factory::createController($context, 'basket');
                 $cntl->deleteCoupon($coupon);
             }
             break;
         default:
             if (($coupon = $view->param('b_coupon')) != '') {
                 $this->_clearCached();
                 $cntl = Controller_Frontend_Factory::createController($context, 'basket');
                 /** client/html/basket/standard/coupon/allowed
                  * Number of coupon codes a customer is allowed to enter
                  *
                  * This configuration option enables shop owners to limit the number of coupon
                  * codes that can be added by a customer to his current basket. By default, only
                  * one coupon code is allowed per order.
                  *
                  * Coupon codes are valid until a payed order is placed by the customer. The
                  * "count" of the codes is decreased afterwards. If codes are not personalized
                  * the codes can be reused in the next order until their "count" reaches zero.
                  *
                  * @param integer Positive number of coupon codes including zero
                  * @since 2014.05
                  * @category User
                  * @category Developer
                  */
                 $allowed = $context->getConfig()->get('client/html/basket/standard/coupon/allowed', 1);
                 if ($allowed <= count($cntl->get()->getCoupons())) {
                     throw new Client_Html_Exception(sprintf('Number of coupon codes exceeds the limit'));
                 }
                 $cntl->addCoupon($coupon);
             }
             break;
     }
     parent::process();
 }