Exemplo n.º 1
0
 /**
  * Creates a new voucher with the passed values
  *
  * @return void
  */
 public function saveVoucherAction()
 {
     $params = $this->Request()->getParams();
     $voucherId = empty($params['voucherID']) ? $params["id"] : $params['voucherID'];
     if (!empty($voucherId)) {
         if (!$this->_isAllowed('update', 'voucher')) {
             return;
         }
         //edit voucher
         $voucher = $this->getVoucherRepository()->find($voucherId);
     } else {
         if (!$this->_isAllowed('create', 'voucher')) {
             return;
         }
         //new voucher
         $voucher = new Voucher();
     }
     //save empty values
     if (empty($params['validFrom'])) {
         $params['validFrom'] = null;
     }
     if (empty($params['validTo'])) {
         $params['validTo'] = null;
     }
     if (empty($params['customerGroup'])) {
         $params['customerGroup'] = null;
     }
     if (empty($params['shopId'])) {
         $params['shopId'] = null;
     }
     if (empty($params['bindToSupplier'])) {
         $params['bindToSupplier'] = null;
     }
     $params['attribute'] = $params['attribute'][0];
     $voucher->fromArray($params);
     try {
         $this->getManager()->persist($voucher);
         $this->getManager()->flush();
         $data = $this->getVoucherRepository()->getVoucherDetailQuery($voucher->getId())->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
         $this->View()->assign(array('success' => true, 'data' => $data));
     } catch (Exception $e) {
         $this->View()->assign(array('success' => false, 'message' => $e->getMessage()));
     }
 }
Exemplo n.º 2
0
 /**
  * Test case voucher should be persisted
  */
 public function testVoucherShouldBePersisted()
 {
     $voucher = new Voucher();
     $voucher->fromArray($this->testData);
     $this->em->persist($voucher);
     $this->em->flush();
     $voucherId = $voucher->getId();
     // remove form from entity manager
     $this->em->detach($voucher);
     unset($voucher);
     $voucher = $this->repo->find($voucherId);
     foreach ($this->testData as $fieldname => $value) {
         $getMethod = 'get' . ucfirst($fieldname);
         $this->assertEquals($voucher->{$getMethod}(), $value);
     }
 }