Example #1
0
 /**
  * @covers ZfcUser\Authentication\Storage\Db::read
  */
 public function testReadWithoutResolvedEntitySetIdentityIntUserNotFound()
 {
     $this->storage->expects($this->once())->method('read')->will($this->returnValue(1));
     $this->db->setStorage($this->storage);
     $this->mapper->expects($this->once())->method('findById')->with(1)->will($this->returnValue(false));
     $this->db->setMapper($this->mapper);
     $result = $this->db->read();
     $this->assertNull($result);
 }
 public function renderDefault()
 {
     $this->template->categories_count = mapper::categories()->countAll();
     $this->template->manufacturers_count = mapper::manufacturers()->countAll();
     $this->template->pages_count = mapper::pages()->countNotRef();
     $this->template->products_count = mapper::products()->countAll();
     $this->template->pictures_count = mapper::pictures()->countAll();
     $this->template->orders_count = mapper::orders()->countAll();
     $this->template->orders_initial_count = mapper::orders()->countWithInitialStatus();
 }
Example #3
0
 public function beforeRender()
 {
     // curly brackets
     $this->template->registerFilter('Nette\\Templates\\CurlyBracketsFilter::invoke');
     // texy
     $texy = new Texy();
     $this->template->registerHelper('texy', array($texy, 'process'));
     // user
     $this->template->user = Environment::getUser();
     // order statuses
     $this->template->order_statuses = mapper::order_statuses()->findAll();
     // date
     $this->template->registerHelper('date', array(__CLASS__, 'date'));
 }
Example #4
0
 public function beforeRender()
 {
     // curly brackets
     $this->template->registerFilter('Nette\\Templates\\CurlyBracketsFilter::invoke');
     // texy
     $texy = new Texy();
     $this->template->registerHelper('texy', array($texy, 'process'));
     // side
     $side = array();
     $side['categories'] = mapper::categories()->findMain();
     $side['manufacturers'] = mapper::manufacturers()->findAll();
     $side['pages'] = mapper::pages()->findNotRef();
     $side['cart'] = Environment::getSession(SESSION_ORDER_NS);
     $side['recent_products'] = Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent;
     $this->template->side = (object) $side;
 }
 public function renderDefault($q, $page = 1)
 {
     try {
         $ids = array();
         foreach (fulltext::index()->find($q) as $hit) {
             $ids[] = $hit->getDocument()->id;
         }
         $this->template->paginator = new Paginator();
         $this->template->paginator->setItemCount(count($ids));
         $this->template->paginator->setItemsPerPage(Environment::getVariable('itemsPerPage', 30));
         $this->template->paginator->setPage($page);
         $this->template->products = mapper::products()->findByIds(array_slice($ids, $this->template->paginator->getOffset(), $this->template->paginator->getLength()));
         $this->template->title = __('Search results for ``%s"', $q);
         $this->template->q = $q;
         Environment::getSession(SESSION_SEARCH_NS)->last = $q;
         searchlog::log($q);
     } catch (Exception $e) {
         $this->template->products = array();
     }
 }
Example #6
0
 public function listLatestActualities($count)
 {
     $template = clone $this->template;
     $template->setFile(Environment::expand('%templatesDir%/FrontModule/@actualities.phtml'));
     $template->presenter = $this;
     $template->control = $this;
     $template->actualities = mapper::actualities()->findLatest($count);
     return "/---html\n" . $template->__toString() . "\n\\---\n";
 }
Example #7
0
 /**
  * Deletes page by given nice name
  * @param string
  * @return something
  */
 public function deleteOne($nice_name)
 {
     return parent::delete(array('nice_name' => $nice_name));
 }
 public function onAvailabilityEditSubmit(Form $form)
 {
     if (!$form->isValid()) {
         return;
     }
     mapper::product_availabilities()->updateOne($form->getValues());
     adminlog::log(__('Updated availability "%s"'), $form['name']->getValue());
     $this->redirect('availabilities');
     $this->terminate();
 }
Example #9
0
 protected function setAuthenticationUser()
 {
     $this->mapper->expects($this->once())->method('findByUsername')->with('ZfcUser')->will($this->returnValue($this->user));
     $this->options->expects($this->once())->method('getAuthIdentityFields')->will($this->returnValue(array('username')));
 }
 public function onSendMailFormSubmit(Form $form)
 {
     if (!$form->isValid()) {
         return;
     }
     $active = FALSE;
     try {
         dibi::begin();
         $active = TRUE;
         mapper::order_emails()->insertOne(array('order_id' => $form['order_id']->getValue(), 'subject' => $form['subject']->getValue(), 'body' => $form['body']->getValue()));
         $mail = new Mail();
         $mail->setFrom(Environment::expand('%shopName% <%shopEmail%>'))->addTo($form['to']->getValue())->setSubject($form['subject']->getValue())->setBody($form['body']->getValue())->send();
         adminlog::log(__('Sent e-mail to "%s" with subject "%s"'), $form['to']->getValue(), $form['subject']->getValue());
         $this->redirect('this');
         $this->terminate();
     } catch (RedirectingException $e) {
         dibi::commit();
         throw $e;
     } catch (Exception $e) {
         if ($active) {
             dibi::rollback();
         }
         $form->addError(__('Cannot send e-mail.'));
     }
 }
Example #11
0
 /**
  * A little componen factory
  * @param string
  */
 public function createComponent($name)
 {
     switch ($name) {
         case 'dataForm':
             $data = isset(Environment::getSession(SESSION_ORDER_NS)->data) ? Environment::getSession(SESSION_ORDER_NS)->data : array();
             $form = new AppForm($this, $name);
             // contacts
             $form->addGroup(__('Contacts'));
             $form->addText('email', __('E-mail:'))->setEmptyValue('@')->addRule(Form::FILLED, __('You have to enter your e-mail.'))->addRule(Form::EMAIL, __('This is not an e-mail address.'));
             $form->addText('phone', __('Phone number:'))->addRule(Form::FILLED, __('You have to enter your phone number.'))->addRule(Form::NUMERIC, __('Phone number has to be number.'));
             // payer
             $form->addGroup(__('Payer'));
             $form->addText('payer_name', __('Name:'))->addRule(Form::FILLED, __('You have to enter your name.'));
             $form->addText('payer_lastname', __('Last name:'))->addRule(Form::FILLED, __('You have to enter your last name.'));
             $form->addText('payer_company', __('Company:'));
             $form->addText('payer_street', __('Street:'))->addRule(Form::FILLED, __('You have to enter your street.'));
             $form->addText('payer_city', __('City:'))->addRule(Form::FILLED, __('You have to enter your city.'));
             $form->addText('payer_postcode', __('Post code:'))->addRule(Form::FILLED, __('You have to enter your post code.'))->addRule(Form::NUMERIC, __('Post code has to be number.'));
             $form->addCheckbox('same_delivery', __('deliver at same address (you do not need to fill Delivery address below)'))->setValue(TRUE);
             // delivery address
             $form->addGroup(__('Delivery address'));
             $form->addText('delivery_name', __('Name:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your name.'));
             $form->addText('delivery_lastname', __('Last name:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your last name.'));
             $form->addText('delivery_street', __('Street:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your street.'));
             $form->addText('delivery_city', __('City:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your city.'));
             $form->addText('delivery_postcode', __('Post code:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your post code.'))->addRule(Form::NUMERIC, __('Post code has to be number.'));
             // delivery type
             $form->addGroup(__('Delivery type'));
             $delivery_types = array();
             foreach (mapper::order_delivery_types()->findAll() as $delivery_type) {
                 $delivery_types[$delivery_type->getId()] = $delivery_type->getName() . Environment::expand(' (' . $delivery_type->getPrice() . ' %currency%)');
             }
             $form->addSelect('delivery_type', __('Type:'), $delivery_types);
             // payment type
             $form->addGroup(__('Payment type'));
             $payment_types = array();
             foreach (mapper::order_payment_types()->findAll() as $payment_type) {
                 $payment_types[$payment_type->getId()] = $payment_type->getName() . Environment::expand(' (' . $payment_type->getPrice() . ' %currency%)');
             }
             $form->addSelect('payment_type', __('Type:'), $payment_types);
             // comment
             $form->addGroup(__('Comment'));
             $form->addTextarea('comment', __('Comment:'));
             // submit
             $form->setCurrentGroup(NULL);
             $form->addSubmit('ok', '(3/3) ' . __('Complete order ยป'));
             $form['ok']->setRendered(TRUE);
             $form->onSubmit[] = array($this, 'onDataFormSubmit');
             // defaults
             if (isset(Environment::getSession(SESSION_ORDER_NS)->data)) {
                 $form->setDefaults(Environment::getSession(SESSION_ORDER_NS)->data);
             }
             break;
         default:
             parent::createComponent($name);
     }
 }
 public function onImportManufacturersFormSubmit(Form $form)
 {
     if (!$form->isValid()) {
         return;
     }
     // read imported manufacturers
     if (!($handle = @fopen('safe://' . $form['file']->getValue()->getTemporaryFile(), 'r'))) {
         $form->addError(__('Cannot read file.'));
         return;
     }
     $import = array();
     while (($_ = fgetcsv($handle)) !== FALSE) {
         $manufacturer = array();
         list(, $manufacturer['name'], $manufacturer['nice_name']) = $_;
         $import[] = $manufacturer;
     }
     fclose($handle);
     adminlog::log(__('About to import manufacturers'));
     $manufacturers_added = 0;
     // import them
     foreach ($import as $manufacturer) {
         if (($_ = mapper::manufacturers()->findByNiceName($manufacturer['nice_name'])) === NULL) {
             mapper::manufacturers()->insertOne($manufacturer);
             $manufacturers_added++;
         }
     }
     adminlog::log(__('Added %d new manufacturers'), $manufacturers_added);
 }
Example #13
0
 /**
  * Save given order
  * @param order
  * @param array
  * @return bool
  */
 public function save(order $order, array $products, array $visited)
 {
     // order data
     $data = $order->__toArray();
     $data['at'] = date('Y-m-d H:i:s', time());
     $data['delivery_type_id'] = $data['delivery_type']->getId();
     unset($data['delivery_type']);
     $data['payment_type_id'] = $data['payment_type']->getId();
     unset($data['payment_type']);
     $data['status_id'] = $data['status']->getId();
     unset($data['status']);
     // start transaction
     dibi::begin();
     try {
         $this->insert($data);
         $order_id = dibi::query('SELECT LAST_INSERT_ID()')->fetchSingle();
         $order->setId($order_id);
         $order->dirty(order::UNDIRT);
         foreach (mapper::products()->findByIds(array_keys($products)) as $product) {
             dibi::query('INSERT INTO [:prefix:orders_products]', array('order_id' => $order_id, 'product_id' => $product->getId(), 'price' => $product->getPrice(), 'amount' => $products[$product->getId()]));
         }
         foreach ($visited as $_) {
             $values = array('order_id' => $order_id);
             $values['product_id'] = $_[0]->getId();
             $values['visited_at'] = date('Y-m-d H:i:s', $_[1]);
             dibi::query('INSERT INTO [:prefix:order_visited_products]', $values);
         }
         $mail = new Mail();
         $mail->setFrom(Environment::expand('%shopEmail%'))->addTo(Environment::expand('%shopEmail%'))->setSubject(__('New order'))->setBody(__('Hello, new order arrived'))->send();
         $mail = new Mail();
         $mail->setFrom(Environment::expand('%shopEmail%'))->addTo($data['email'])->setSubject(__('Your order at %s has been accepted', Environment::expand('%shopName%')))->setBody(str_replace('\\n', "\n", __('Hello, your order has been accepted.')))->send();
     } catch (Exception $e) {
         dibi::rollback();
         return FALSE;
     }
     dibi::commit();
     return TRUE;
 }