コード例 #1
0
 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();
 }
コード例 #2
0
 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();
     }
 }
コード例 #3
0
 public function listRandomProducts($count)
 {
     $count = intval($count);
     $template = clone $this->template;
     $template->setFile(Environment::expand('%templatesDir%/FrontModule/@products.phtml'));
     $template->presenter = $this;
     $template->control = $this;
     $template->products = mapper::products()->findRandom($count);
     return "/---html\n" . $template->__toString() . "\n\\---\n";
 }
コード例 #4
0
 public function onProductEditSubmit(Form $form)
 {
     if (!$form->isValid()) {
         return;
     }
     mapper::products()->updateOne($form->getValues());
     adminlog::log(__('Updated product "%s"'), $form['nice_name']->getValue());
     $this->redirect('products');
     $this->terminate();
 }
コード例 #5
0
 /**
  * Complete order
  */
 public function renderComplete()
 {
     $order = Environment::getSession(SESSION_ORDER_NS);
     $this->template->title = __('Complete order');
     $this->template->products = mapper::products()->findByIds(array_keys($order->products));
     $this->template->product_counts = $order->products;
     $this->template->total = $order->total = 0;
     // products
     foreach ($this->template->products as $product) {
         $order->total += $product->getPrice() * $order->products[$product->getId()];
     }
     $this->template->total = $order->total;
     // delivery & payment
     $this->template->delivery_type = mapper::order_delivery_types()->findById($order->data['delivery_type']);
     $this->template->total += $this->template->delivery_type->getPrice();
     $this->template->payment_type = mapper::order_payment_types()->findById($order->data['payment_type']);
     $this->template->total += $this->template->payment_type->getPrice();
     // data
     $this->template->data = $order->data;
 }
コード例 #6
0
 public function onImportFormSubmit(Form $form)
 {
     if (!$form->isValid()) {
         return;
     }
     if (!($handle = @fopen('safe://' . $form['file']->getValue()->getTemporaryFile(), 'r'))) {
         $form->addError(__('Cannot read file.'));
         return;
     }
     adminlog::log(__('Attempt to import products'));
     // provision
     $provision = intval($form['provision']->getValue());
     // read file
     $import = array();
     $codes = array();
     while (($_ = fgetcsv($handle)) !== FALSE) {
         $product = array();
         list($product['code'], $product['manufacturer'], $product['name'], $product['category'], , , $product['price']) = $_;
         $product['price'] = intval(round($product['price'] / (100 - $provision) * 100));
         $import[$product['code']] = $product;
         $codes[] = $product['code'];
     }
     fclose($handle);
     $updated = 0;
     // update in db
     foreach (mapper::products()->findByCodes($codes) as $product) {
         $values = array('id' => $product->getId(), 'price' => $import[$product->getCode()]['price']);
         mapper::products()->updateOne($values);
         unset($import[$product->getCode()]);
         $updated++;
     }
     adminlog::log(__('Updated %d products'), $updated);
     // update only?
     if ($form['update_only']->getValue()) {
         adminlog::log(__('Import successful'));
         $this->redirect('this');
         $this->terminate();
         return;
     }
     // manufacturers & categories
     $manufacturers = array();
     $categories = array();
     foreach ($import as $k => $_) {
         $m_key = String::webalize($_['manufacturer']);
         $manufacturers[$m_key] = $_['manufacturer'];
         $import[$k]['manufacturer'] = $m_key;
         $c_key = String::webalize($_['category']);
         $categories[$c_key] = $_['category'];
         $import[$k]['category'] = $c_key;
     }
     $manufacturers_added = 0;
     foreach ($manufacturers as $nice_name => $name) {
         if (($_ = mapper::manufacturers()->findByNiceName($nice_name)) === NULL) {
             mapper::manufacturers()->insertOne(array('nice_name' => $nice_name, 'name' => $name));
             $manufacturers[$nice_name] = mapper::manufacturers()->findByNiceName($nice_name)->getId();
             $manufacturers_added++;
         } else {
             $manufacturers[$nice_name] = $_->getId();
         }
         $manufacturers[$nice_name] = intval($manufacturers[$nice_name]);
     }
     adminlog::log(__('Added %d new manufacturers'), $manufacturers_added);
     $categories_added = 0;
     foreach ($categories as $nice_name => $name) {
         if (($_ = mapper::categories()->findByNiceName($nice_name)) === NULL) {
             mapper::categories()->addOne(array('nice_name' => $nice_name, 'name' => $name));
             $categories[$nice_name] = mapper::categories()->findByNiceName($nice_name)->getId();
             $categories_added++;
         } else {
             $categories[$nice_name] = $_->getId();
         }
         $categories[$nice_name] = intval($categories[$nice_name]);
     }
     adminlog::log(__('Added %d new categories'), $categories_added);
     // other
     $other = array();
     if ($form['availability_id']->getValue() != 0) {
         $other['availability_id'] = intval($form['availability_id']->getValue());
     }
     $products_added = 0;
     // insert products
     foreach ($import as $_) {
         $_['manufacturer_id'] = $manufacturers[$_['manufacturer']];
         unset($_['manufacturer']);
         $_['category_id'] = $categories[$_['category']];
         unset($_['category']);
         $_['nice_name'] = String::webalize($_['name']);
         $_ = array_merge($_, $other);
         mapper::products()->insertOne($_);
         $products_added++;
     }
     adminlog::log(__('Added %d new products'), $products_added);
     adminlog::log(__('Import successful'));
     // all done
     $this->redirect('this');
     $this->terminate();
 }
コード例 #7
0
ファイル: orders.php プロジェクト: jakubkulhan/shopaholic
 /**
  * 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;
 }