public function updaterAction()
 {
     $currencyMapper = new Application_Model_CurrencyMapper();
     $currencyMapper->updater();
     //var_dump($currencies);
     $this->_helper->redirector('dashboard', 'users');
 }
Ejemplo n.º 2
0
 /**
  * Удаление валюты по идентификатору
  */
 public function deleteAction()
 {
     $currencyId = $this->_request->getParam('currencyId');
     $provider = $this->_getExchangeRatesProvider();
     $currencyMapper = new Application_Model_CurrencyMapper();
     $currencyMapper->delete($currencyId);
     $result = $provider->updateQuotations();
     echo Zend_Json::encode($result);
     Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
 }
Ejemplo n.º 3
0
 /**
  * @param mixed $currency
  */
 public function setCurrency($price, $userCurrencyId = null)
 {
     $cy = new Application_Model_CurrencyMapper();
     $currency_id = $cy->getDefaultCurrency()->id;
     $code = $cy->find($currency_id)->code;
     $currency = null;
     if ($userCurrencyId) {
         $userCode = $cy->find($userCurrencyId)->code;
         $currency = new Zend_Currency(array('value' => 1, 'currency' => $userCode, 'display' => Zend_Currency::USE_SHORTNAME, 'position' => Zend_Currency::RIGHT, 'format' => '#0.# '));
         $exService = new My_Class_ExchangeService();
         $currency->setService($exService);
         $currency->setValue($price, $code);
     } else {
         $currency = new Zend_Currency(array('value' => $price, 'currency' => $code, 'display' => Zend_Currency::USE_SHORTNAME, 'position' => Zend_Currency::RIGHT, 'format' => '#0.# '));
     }
     $this->currency = $currency;
 }
Ejemplo n.º 4
0
 /**
  * Добавить валюту по значению буквенного кода
  * 
  * @param string $currencyLetterCode буквенный код валюты
  * @return string
  */
 public function addCurrency($currencyLetterCode)
 {
     $currencyMapper = new Application_Model_CurrencyMapper();
     $existsCurrency = $currencyMapper->fetchByName($currencyLetterCode);
     if ($existsCurrency) {
         return 'exists';
     }
     $currencyModel = new Application_Model_Currency();
     $quotations = $this->_prepareData();
     foreach ($quotations as $data) {
         if ($data['name'] !== $currencyLetterCode) {
             continue;
         }
         $currencyModel->setOptions($data);
         break;
     }
     if (!$currencyModel->getProviderCurrencyId()) {
         return 'notFound';
     }
     $currencyMapper->save($currencyModel);
     $result = $this->updateQuotations();
     return $result;
 }
 public function init()
 {
     // Set the method for the display form to POST
     $this->setMethod('post');
     $this->setAttribs(array('class' => 'form-horizontal'));
     $decoratorField = new My_Decorator_FieldLogin();
     $elements = array();
     // Add code field
     $input = new Zend_Form_Element_Text('code', array('required' => true, 'label' => 'Currency Code:', 'id' => 'currency_code', 'placeholder' => 'Example USD', 'class' => 'form-control', 'list' => 'currencies', 'autocomplete' => 'off'));
     $validator = new Zend_Validate_StringLength(array('max' => 3));
     $input->addValidators(array($validator, new Zend_Validate_NotEmpty()));
     $currencyMapper = new Application_Model_CurrencyMapper();
     $decoratorCurrency = new My_Decorator_CurrencyAutocomplete(null, $currencyMapper->getAvailableCurrencies());
     $input->addDecorator($decoratorCurrency);
     $elements[] = $input;
     //add rate file
     $input = new Zend_Form_Element_Text('rate', array('required' => true, 'label' => 'Rate:', 'id' => 'rate', 'placeholder' => '...', 'class' => 'form-control', 'step' => 'any', 'type' => 'number'));
     $input->addValidators(array(new Zend_Validate_Float(), new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add checkbox field
     $input = new Zend_Form_Element_Checkbox('def', array('label' => 'Default', 'id' => 'def', 'class' => 'checkbox', 'type' => 'checkbox'));
     $decoratorCheckBox = new My_Decorator_CheckBox();
     $input->addDecorator($decoratorCheckBox);
     $elements[] = $input;
     // Add checkbox field
     $input = new Zend_Form_Element_Checkbox('active', array('label' => 'Active', 'id' => 'active', 'class' => 'checkbox', 'type' => 'checkbox'));
     $decoratorCheckBox = new My_Decorator_CheckBox();
     $input->addDecorator($decoratorCheckBox);
     $elements[] = $input;
     //Add Submit button
     $input = new Zend_Form_Element_Submit('submit', array('Label' => '', 'class' => 'btn btn-default', 'value' => 'Save'));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     $this->addElements($elements);
     $this->addDisplayGroup(array('code', 'rate', 'def', 'active', 'submit'), 'displgrp', array('decorators' => array('FormElements', 'Fieldset')));
 }
Ejemplo n.º 6
0
 public function init()
 {
     // Set the method for the display form to POST
     $this->setMethod('post');
     $this->setAttribs(array('class' => 'form-horizontal'));
     $decoratorField = new My_Decorator_FieldLogin();
     $elements = array();
     // Add name field
     $input = new Zend_Form_Element_Text('email', array('required' => true, 'label' => 'Email Address:', 'id' => 'email', 'placeholder' => 'Your email..', 'class' => 'form-control', 'type' => 'email'));
     $input->addValidators(array(new Zend_Validate_EmailAddress(), new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add category field
     $input = new Zend_Form_Element_Password('password1', array('required' => true, 'label' => 'Password:'******'id' => 'password1', 'class' => 'form-control', 'placeholder' => 'Your password..'));
     $input->addValidators(array(new Zend_Validate_Alnum(), new Zend_Validate_StringLength(array('min' => 8)), new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add category field
     $input = new Zend_Form_Element_Password('password2', array('required' => true, 'label' => 'Password Again:', 'id' => 'password2', 'class' => 'form-control', 'placeholder' => 'Your password again..', 'validators' => array(array('identical', false, array('token' => 'password1')))));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add code field
     $input = new Zend_Form_Element_Text('currency_code', array('required' => true, 'label' => 'Currency Code:', 'id' => 'currency_code', 'placeholder' => 'Example USD', 'class' => 'form-control', 'list' => 'currencies', 'autocomplete' => 'off'));
     $validator = new Zend_Validate_StringLength(array('max' => 3));
     $input->addValidators(array($validator, new Zend_Validate_NotEmpty()));
     $currencyMapper = new Application_Model_CurrencyMapper();
     $currencies = $currencyMapper->fetchAllActive();
     $decoratorCurrency = new My_Decorator_CurrencyAutocomplete(null, $currencies);
     $input->addDecorator($decoratorCurrency);
     $elements[] = $input;
     //Add Submit button
     $input = new Zend_Form_Element_Submit('submit', array('Label' => '', 'class' => 'btn btn-default', 'value' => 'SignUp'));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     $this->addElements($elements);
     $this->addDisplayGroup(array('email', 'password1', 'password2', 'currency_code', 'submit'), 'displgrp', array('decorators' => array('FormElements')));
 }
 public function getRate($from, $to)
 {
     $currencyMapper = new Application_Model_CurrencyMapper();
     if (!$to) {
         $to = $currencyMapper->getDefaultCurrency()->code;
     }
     $rate_from = $currencyMapper->getDbTable()->fetchRow($currencyMapper->getDbTable()->select()->where('code = ?', $from))->rate;
     $rate_to = $currencyMapper->getDbTable()->fetchRow($currencyMapper->getDbTable()->select()->where('code = ?', $to))->rate;
     if (!($rate_from || $rate_to)) {
         new Exception('Currency Code is not in database');
     }
     return $rate_to / $rate_from;
 }
 public function signupAction()
 {
     $form = new Application_Form_SignUp();
     $request = $this->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $data = $form->getValues();
             $data['password'] = md5($data['password1']);
             // MD5
             unset($data['password1']);
             unset($data['password2']);
             $data['hash'] = md5(rand(1, 1000));
             $currencyMapper = new Application_Model_CurrencyMapper();
             $currency = $currencyMapper->findByCode($data['currency_code']);
             if (!$currency->id) {
                 $data['currency_id'] = $currencyMapper->getDefaultCurrency()->id;
             } else {
                 $data['currency_id'] = $currency->id;
             }
             $user = new Application_Model_User($data);
             $userMapper = new Application_Model_UserMapper();
             try {
                 $userMapper->insert($user);
                 $mailMapper = new Application_Model_MailsettingMapper();
                 $default_config_id = $mailMapper->getDefault();
                 $mailsetting = $mailMapper->getConfig($default_config_id);
                 $obj = new My_Class_Cript();
                 $config = array('auth' => 'login', 'username' => $mailsetting->email, 'password' => $obj->decript($mailsetting->password), 'ssl' => $mailsetting->stype, 'port' => $mailsetting->port);
                 $transport = new Zend_Mail_Transport_Smtp($mailsetting->host, $config);
                 $mail = new Zend_Mail();
                 $message = "<p>\n                                Thanks for signing up!\n                                Your account has been created, activate your account by pressing the url below.\n                            </p>\n                            <p>-----------------------</p>\n                            <p><a href='http://" . SITE_NAME . "/auth/verify?email=" . $user->email . "&hash=" . $user->hash . "'>Click Here</a> to activate your account</p>";
                 $mail->setBodyHtml($message);
                 $mail->setFrom('*****@*****.**', 'Products-Pilot');
                 $mail->addTo($data['email'], 'You');
                 $mail->setSubject('Account Validation');
                 if ($mail->send($transport)) {
                     $this->_helper->getHelper('FlashMessenger')->addMessage('Your account has been made please verify it by clicking the activation link that has been send to your email.', 'info');
                     return $this->_helper->redirector('login');
                 } else {
                     $userMapper->delete($user);
                 }
             } catch (Exception $e) {
                 $message = $e->getMessage();
                 if ($e instanceof Zend_Db_Statement_Mysqli_Exception) {
                     if ($e->getCode() == 1062) {
                         $message = 'This email is already registered';
                     } else {
                         $message = 'Something goes wrong';
                     }
                 } else {
                     $userMapper->delete($user);
                     $message = 'Mail service error: ' . $e->getMessage();
                 }
                 $this->_helper->getHelper('FlashMessenger')->addMessage($message, 'error');
                 $this->_helper->redirector('signup');
             }
         } else {
             foreach ($form->getMessages() as $error) {
                 $this->_helper->getHelper('FlashMessenger')->addMessage(array_shift(array_values($error)), 'error');
                 $this->_helper->redirector('signup');
                 //var_dump(array_shift(array_values($error)));
             }
         }
     }
     $this->view->form = $form;
 }
 public function getSaveProductForm($id)
 {
     $form = new Zend_Form();
     //get product whitch want update
     $productMapper = new Application_Model_ProductMapper();
     $product = new Application_Model_Product();
     if ($id) {
         $product = $productMapper->getProductById($id);
     }
     // Set the method for the display form to POST
     $form->setMethod('post');
     $form->setAttribs(array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data'));
     $decoratorField = new My_Decorator_Field();
     $elements = array();
     //Add id hidden field
     $input = new Zend_Form_Element_Hidden('id', array('value' => $id));
     $elements[] = $input;
     // Add name field
     $input = new Zend_Form_Element_Text('name', array('required' => true, 'label' => 'Name:', 'id' => 'name', 'placeholder' => 'Type something..', 'value' => $product->getName(), 'class' => 'form-control'));
     $input->addValidators(array(new Zend_Validate_Alnum(), new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add category field
     $select = new Zend_Form_Element_Select('category_id', array('required' => true, 'label' => 'Category:', 'id' => 'category', 'class' => 'form-control'));
     $categoryMapper = new Application_Model_CategoryMapper();
     $categories = $categoryMapper->fetchAll();
     foreach ($categories as $category) {
         $select->addMultiOption($category->getId(), $category->getName());
     }
     // set selected option
     $select->setValue($product->getCategoryId());
     $select->addDecorator($decoratorField);
     $elements[] = $select;
     $currencyMapper = new Application_Model_CurrencyMapper();
     $currency = $currencyMapper->getDefaultCurrency();
     // Add Price field
     $input = new Zend_Form_Element_Text('price', array('required' => true, 'label' => 'Price in ' . $currency->getCode() . ':', 'id' => 'price', 'placeholder' => 'Type something..', 'value' => number_format((double) $product->price, 2), 'class' => 'form-control', 'min' => self::MIN, 'max' => self::MAX, 'step' => 'any', 'type' => 'number'));
     $min = new Zend_Validate_LessThan(self::MAX);
     $max = new Zend_Validate_GreaterThan(self::MIN);
     $input->addValidators(array(new Zend_Validate_Float(), $min, $max, new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     if ($id) {
         //Add File field
         if ($product->file) {
             $input = new Zend_Form_Element('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control', 'value' => $product->file));
             $input->addDecorator(new My_Decorator_AnchoraFileForm());
             $elements[] = $input;
         } else {
             $input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
             $input->addDecorator($decoratorField);
             $elements[] = $input;
         }
         //Add Image field
         if ($product->image) {
             $input = new Zend_Form_Element('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control', 'value' => $product->image));
             $input->addDecorator(new My_Decorator_ImageForm());
             $elements[] = $input;
         } else {
             $input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
             $input->addDecorator($decoratorField);
             $elements[] = $input;
         }
     } else {
         //Add File field
         $input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
         $input->addDecorator($decoratorField);
         $elements[] = $input;
         //Add Image field
         $input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
         $input->addDecorator($decoratorField);
         $elements[] = $input;
     }
     //Add Description field
     $input = new Zend_Form_Element_Textarea('description', array('label' => 'Description:', 'id' => 'description', 'class' => 'form-control', 'value' => $product->description));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     //Add Submit button
     if (!$id) {
         $input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-success', 'value' => 'Add New Product'));
     } else {
         $input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-info', 'value' => 'Update Product'));
     }
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     $form->addElements($elements);
     $form->addDisplayGroup(array('name', 'category_id', 'price', 'currency_id', 'file', 'image', 'description', 'submit'), 'displgrp', array('legend' => 'Add Products', 'decorators' => array('FormElements', 'Fieldset')));
     return $form;
 }
 public function getAvailableCurrencies()
 {
     $XML = simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
     //the file is updated daily between 2.15 p.m. and 3.00 p.m. CET
     $currencyMapper = new Application_Model_CurrencyMapper();
     $def_currency = $currencyMapper->getDefaultCurrency();
     $currencies = array();
     foreach ($XML->Cube->Cube->Cube as $rate) {
         //var_dump((string)$rate["currency"], (string)$rate["rate"]);
         $currencies[(string) $rate["currency"]] = (double) $rate["rate"];
     }
     $currencies['EUR'] = 1.0;
     $cys[] = array();
     $j = 0;
     if ($def_currency != 'EUR') {
         $rap = 1 / $currencies[$def_currency->code];
         foreach ($currencies as $i => &$currency) {
             $currency *= $rap;
             $cys[$j++] = new Application_Model_Currency(array('code' => $i, 'rate' => $currency));
         }
     }
     return $cys;
 }
 public function paypalAction()
 {
     //Zend_Loader::loadFile('paypal_bootstrap.php', APPLICATION_PATH . "/../library/My/", true);
     require_once APPLICATION_PATH . "/../library/My/paypal_bootstrap.php";
     $error = false;
     $approvalLink = null;
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $currentUser = $auth->getIdentity();
         $userMapper = new Application_Model_UserMapper();
         $db_adapter = $userMapper->getDbTable()->getAdapter();
         $db = Zend_Db::factory('Mysqli', $db_adapter->getConfig());
         $results = $userMapper->getShoppingCart($currentUser);
         $user = $userMapper->getDbTable()->find($currentUser->id)->current();
         $currencyMapper = new Application_Model_CurrencyMapper();
         $defaultCurrency = $currencyMapper->getDefaultCurrency();
         $data = array('user_id' => $currentUser->id, 'state' => 'created', 'email' => $user->email);
         $db->insert('orders', $data);
         $lastOrderId = $db->lastInsertId('orders', 'id');
         $items = array();
         $subTotal = 0;
         foreach ($results as $i => $result) {
             $item = new Item();
             $item->setName($result->name)->setCurrency($defaultCurrency->code)->setQuantity($result->quantity)->setSku($i + 1)->setPrice($result->price);
             //->setDescription($result->c_id);
             $db->insert('ordered_products', array('product_id' => $result->id, 'name' => $result->name, 'category_id' => $result->getCategoryId(), 'currency' => $defaultCurrency->code, 'price' => $result->price, 'quantity' => $result->quantity, 'order_id' => $lastOrderId));
             $items[] = $item;
             $subTotal += $result->quantity * (double) number_format($result->price, 2);
         }
         $itemList = new ItemList();
         $itemList->setItems($items);
         $shippingTax = 0;
         //
         $details = new Details();
         $details->setShipping($shippingTax)->setTax(0)->setSubtotal($subTotal);
         $total = $shippingTax + $subTotal;
         $amount = new Amount();
         $amount->setCurrency($defaultCurrency->code)->setTotal($total)->setDetails($details);
         $transaction = new Transaction();
         $transaction->setAmount($amount)->setCustom($lastOrderId)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
         $baseUrl = getBaseUrl();
         $redirectUrls = new RedirectUrls();
         $redirectUrls->setReturnUrl($baseUrl . '/users/exepaypal/?success=true');
         $redirectUrls->setCancelUrl($baseUrl . '/users/exepaypal/?cancel=true');
         $payment = new Payment();
         $payment->setIntent("sale");
         $payment->setPayer($payer);
         $payment->setRedirectUrls($redirectUrls);
         $payment->setTransactions(array($transaction));
         try {
             $result = $payment->create($apiContext);
         } catch (Exception $ex) {
             $error = true;
         }
         $approvalLink = $payment->getApprovalLink();
     } else {
         $error = true;
     }
     $response = array('error' => $error, 'approvalLink' => $approvalLink);
     //Send as JSON
     header("Content-Type: application/json", true);
     //Return JSON
     echo json_encode($response);
     //Stop Execution
     exit;
 }