public function preDispatch()
 {
     parent::preDispatch();
     $result = Plugin::getEventManager()->trigger('action.' . $this->getRequest()->getActionName(), $this, array("controller" => $this, "request" => $this->getRequest()), function ($v) {
         return is_array($v) && array_key_exists("action", $v) && array_key_exists("controller", $v) && array_key_exists("module", $v);
     });
     if ($result->stopped()) {
         $forward = $result->last();
         $this->_forward($forward['action'], $forward['controller'], $forward['module'], $forward['params']);
     }
 }
 protected function paymentSuccess(CoreShopPayment $payment)
 {
     $paymentSuccessHandled = false;
     $result = \CoreShop\Plugin::getEventManager()->trigger('payment.success', $this, array("payment" => $payment, "language" => $this->language), function ($v) {
         return is_bool($v);
     });
     if ($result->stopped()) {
         $paymentSuccessHandled = $result->last();
     }
     if (!$paymentSuccessHandled) {
         $order = $payment->getOrder();
         if ($order instanceof CoreShopOrder) {
             $stateAccepted = CoreShopOrderState::getByPath("/coreshop/order-states/01-order-accepted");
             //TODO: Make Order State per Type Configurable
             $stateAccepted->processStep($order);
             $statePaied = CoreShopOrderState::getByPath("/coreshop/order-states/02-payment-received");
             //TODO: Make Order State per Type Configurable
             $statePaied->processStep($order);
         }
     }
 }
 public function createFieldCollection($name, $jsonPath = null)
 {
     try {
         $fieldCollection = Object\Fieldcollection\Definition::getByKey($name);
     } catch (\Exception $e) {
         if ($jsonPath == null) {
             $jsonPath = PIMCORE_PLUGINS_PATH . "/CoreShop/install/fieldcollection-{$name}.json";
         }
         $fieldCollection = new Object\Fieldcollection\Definition();
         $fieldCollection->setKey($name);
         $json = file_get_contents($jsonPath);
         $result = Plugin::getEventManager()->trigger('install.fieldcollection.preCreate', $this, array("fieldcollectionName" => $name, "json" => $json), function ($v) {
             return !preg_match('/[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]/', preg_replace('/"(\\.|[^"\\\\])*"/', '', $v));
         });
         if ($result->stopped()) {
             $resultJson = $result->last();
             if ($resultJson) {
                 $json = $resultJson;
             }
         }
         Object\ClassDefinition\Service::importFieldCollectionFromJson($fieldCollection, $json, true);
     }
     return $fieldCollection;
 }
 public function attachEvents()
 {
     \CoreShop\Plugin::getEventManager()->attach("hook.product-detail-bottom", function ($e) {
         return $this;
     });
 }
 public function modifyAction()
 {
     $cartItem = $this->getParam("cartItem", null);
     $amount = $this->getParam("amount");
     $item = CoreShopCartItem::getById($cartItem);
     $isAllowed = true;
     $result = Plugin::getEventManager()->trigger('cart.preModify', $this, array("cartItem" => $item, "cart" => $this->cart, "request" => $this->getRequest()), function ($v) {
         return is_bool($v);
     });
     if ($result->stopped()) {
         $isAllowed = $result->last();
     }
     unset($this->session->order);
     if ($isAllowed) {
         if ($item instanceof CoreShopCartItem) {
             $this->cart->modifyItem($item, $amount);
             Plugin::getEventManager()->trigger('cart.postModify', $this, array("item" => $item, "cart" => $this->cart));
             $this->_helper->json(array("success" => true, "cart" => $this->cart->toArray()));
         }
     } else {
         $this->_helper->json(array("success" => false, "message" => 'not allowed'));
     }
     $this->_helper->json(array("success" => false, "cart" => $this->cart->toArray()));
 }
 public function attachEvents()
 {
     \CoreShop\Plugin::getEventManager()->attach("shipping.getProvider", function ($e) {
         return $this;
     });
 }
 public function registerAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getAllParams();
         $addressParams = array();
         $userParams = array();
         foreach ($params as $key => $value) {
             if (startsWith($key, "address_")) {
                 $addressKey = str_replace("address_", "", $key);
                 $addressParams[$addressKey] = $value;
             } else {
                 $userParams[$key] = $value;
             }
         }
         try {
             //Check User exists
             if (CoreShopUser::getUniqueByEmail($userParams['email']) instanceof CoreShopUser) {
                 throw new \Exception("E-Mail already exists");
             }
             $folder = "/users/" . strtolower(substr($userParams['lastname'], 0, 1));
             $adresses = new Object\Fieldcollection();
             $address = new CoreShopUserAddress();
             $address->setValues($addressParams);
             $address->setCountry(Country::getById($addressParams['country']));
             $adresses->add($address);
             $user = new CoreShopUser();
             $user->setKey(Pimcore\File::getValidFilename($userParams['email']));
             $user->setPublished(true);
             $user->setParent(Pimcore\Model\Object\Service::createFolderByPath($folder));
             $user->setValues($userParams);
             $user->setAddresses($adresses);
             $user->save();
             Plugin::getEventManager()->trigger('user.postAdd', $this, array("request" => $this->getRequest(), "user" => $user));
             $this->session->user = $user;
             if (array_key_exists("_redirect", $params)) {
                 $this->_redirect($params['_redirect']);
             }
         } catch (\Exception $ex) {
             $this->view->error = $ex->getMessage();
         }
     }
 }