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(); }
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 renderProduct() { // recent products if (!isset(Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent)) { Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent = array(); } array_unshift(Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent, $this->template->product); $already_in = array(); foreach (Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent as &$_) { $id = $_->getId(); if (isset($already_in[$id])) { $_ = FALSE; } $already_in[$id] = TRUE; } Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent = array_slice(array_filter(Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent), 0, 5); // visited products array_push(Environment::getSession(SESSION_ORDER_NS)->visited, array($this->template->product, time())); // fill template $this->template->nav = mapper::categories()->findForNavByProductId($this->template->product->getId()); }
public function onCategoryEditSubmit(Form $form) { if (!$form->isValid()) { return; } mapper::categories()->updateOne($form->getValues()); adminlog::log(__('Updated category "%s"'), $form['nice_name']->getValue()); $this->redirect('categories'); $this->terminate(); }
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(); }