public function itemsAction()
 {
     $bAutoTrigger = null;
     $oUserSessionContainer = new UserSessionContainer();
     $nUserId = $oUserSessionContainer->getUserId();
     $nUserParamId = $this->getUserParamTable()->findRow(array('user_id' => $nUserId));
     if (isset($nUserId) && isset($nUserParamId)) {
         $oCart = $this->getCartTable()->getRow(array('user_id' => $nUserId));
         if (isset($oCart) && $oUserSessionContainer->getIsInit()) {
             $oCartSum = $this->getCartItemTable()->getCartSum();
             $oEditCartItemForm = $this->getServiceLocator()->get('EditCartItemFormService');
             $oNewPaymentForm = $this->getServiceLocator()->get('NewPaymentFormService');
             //$oNewPaymentForm->setData(array('amount' => $oCartSum->credit - $oCartSum->cart_sum_price_gross . ' PLN', 'first_name' => $oUserSessionContainer->getFirstName(), 'last_name' => $oUserSessionContainer->getLastName(), 'email_address' => $oUserSessionContainer->getEmailAddress(), 'phone_number' => $oUserSessionContainer->getPhoneNumber()));
             if ($oCartSum->credit > 0) {
                 $nAmount = $oCartSum->credit - $oCartSum->cart_sum_price_gross;
             } else {
                 $nAmount = $oCartSum->cart_sum_price_gross;
             }
             $oNewPaymentForm->setData(array('amount' => $nAmount . ' PLN', 'first_name' => $oUserSessionContainer->getFirstName(), 'last_name' => $oUserSessionContainer->getLastName(), 'email_address' => $oUserSessionContainer->getEmailAddress(), 'phone_number' => $oUserSessionContainer->getPhoneNumber(), 'location_key' => 'Alma Demo'));
             if ($this->getRequest()->isPost()) {
                 $oNewPaymentForm->setData($this->getRequest()->getPost());
                 if ($oNewPaymentForm->isValid()) {
                     try {
                         $this->getOrderPaymentTable()->beginTransaction();
                         $oOrderPaymentEntity = new OrderPaymentEntity();
                         $oOrderPaymentHistoryEntity = new OrderPaymentHistoryEntity();
                         $oUserEntity = new UserEntity();
                         $oUserParamEntity = new UserParamEntity();
                         $aValidatedData = $oNewPaymentForm->getData();
                         $sEmailAddress = $aValidatedData['email_address'];
                         $sFirstName = $aValidatedData['first_name'];
                         $sLastName = $aValidatedData['last_name'];
                         $sPhoneNumber = $aValidatedData['phone_number'];
                         $sPaymentDescription = '';
                         $oAllCartItems = $this->getCartItemTable()->getAll(array('cart_id' => $oCart->id));
                         if ($oAllCartItems) {
                             foreach ($oAllCartItems as $oItem) {
                                 $sPaymentDescription .= $this->getItemTable()->getRow(array('id' => $oItem->item_id))->name;
                                 if (count($oAllCartItems) > 1) {
                                     $sPaymentDescription .= '; ';
                                 }
                             }
                             $sPaymentDescription = trim($sPaymentDescription);
                         }
                         $aUserData = array('id' => $nUserId, 'user_param_id' => $nUserParamId, 'email_address' => $sEmailAddress, 'first_name' => $sFirstName, 'last_name' => $sLastName, 'phone_number' => $sPhoneNumber);
                         $oUserSessionContainer->setUserData($aUserData);
                         $oUserData = new \ArrayObject($aUserData);
                         $this->getUserTable()->changeEmailAddress($oUserEntity->setOptions($oUserData));
                         $this->getUserParamTable()->changeFirstName($oUserParamEntity->setOptions($oUserData));
                         $this->getUserParamTable()->changeLastName($oUserParamEntity->setOptions($oUserData));
                         $this->getUserParamTable()->changePhoneNumber($oUserParamEntity->setOptions($oUserData));
                         $oPayU = new \Shop\PayU($oUserSessionContainer->getLocationKey());
                         $oPayU->setSessionId();
                         $oPayU->setOrderId();
                         $oPayU->setAmount($nAmount);
                         $oPayU->setUserId($nUserId);
                         $oPayU->setFirstName($sFirstName);
                         $oPayU->setLastName($sLastName);
                         $oPayU->setEmailAddress($sEmailAddress);
                         $oPayU->setStreet('');
                         $oPayU->setPostCode('');
                         $oPayU->setCity('');
                         $oPayU->setPhone('');
                         $oPayU->setClientIp();
                         $oPayU->setDesc('Opłata biblioteczna ' . $oUserSessionContainer->getLocationKey());
                         $oPayU->setLocationKey($oUserSessionContainer->getLocationKey());
                         $oPayU->setSig();
                         $oPayUForm = $this->getServiceLocator()->get('PayUFormService');
                         $oPaymentForm = $oPayUForm->setPayment($oPayU);
                         $oOrderPaymentData = new \ArrayObject($oPayU->getPaymentParam());
                         $oOrderPaymentData->offsetSet('order_payment_id', $this->getOrderPaymentTable()->addRow($oOrderPaymentEntity->setOptions($oOrderPaymentData)));
                         $oAllCartItems = $this->getCartItemTable()->getAll(array('cart_id' => $oCart->id));
                         if ($oAllCartItems) {
                             foreach ($oAllCartItems as $oItem) {
                                 $oOrderPaymentData->offsetSet('item_id', $oItem->item_id);
                                 $this->getOrderPaymentHistoryTable()->addRow($oOrderPaymentHistoryEntity->setOptions($oOrderPaymentData));
                             }
                         }
                         $bAutoTrigger = true;
                         $this->getOrderPaymentTable()->commit();
                     } catch (\Exception $e) {
                         $this->getOrderPaymentTable()->rollBack();
                     }
                 }
             } else {
                 if ($oUserSessionContainer->getIsInit()) {
                     $oPaymentForm = $oNewPaymentForm;
                 }
             }
         }
         return new ViewModel(array('cart_sum' => $oCartSum, 'edit_cart_item_form' => $oEditCartItemForm, 'payment_form' => $oPaymentForm, 'auto_trigger' => $bAutoTrigger));
     }
 }