Ejemplo n.º 1
0
 /**
  * Function to create a new payment
  */
 public function createPaymentsAction()
 {
     try {
         $params = $this->Request()->getParams();
         unset($params["action"]);
         $repository = Shopware()->Models()->getRepository('Shopware\\Models\\Payment\\Payment');
         $existingModel = $repository->findByName($params['name']);
         if ($existingModel) {
             throw new \Doctrine\ORM\ORMException('The name is already in use.');
         }
         if ($params['source'] == 0) {
             $params['source'] = null;
         }
         $paymentModel = new \Shopware\Models\Payment\Payment();
         $params['attribute'] = $params['attribute'][0];
         $countries = $params['countries'];
         $countryArray = array();
         foreach ($countries as $country) {
             $countryArray[] = Shopware()->Models()->find('Shopware\\Models\\Country\\Country', $country['id']);
         }
         $params['countries'] = $countryArray;
         $paymentModel->fromArray($params);
         Shopware()->Models()->persist($paymentModel);
         Shopware()->Models()->flush();
         $params['id'] = $paymentModel->getId();
         $this->View()->assign(array('success' => true, 'data' => $params));
     } catch (\Doctrine\ORM\ORMException $e) {
         $this->View()->assign(array('success' => false, 'errorMsg' => $e->getMessage()));
     }
 }