<?php /** * Products_datatable * * PHP version 5 * * @category None * @package None * @author Kae Verens <*****@*****.**> * @license GPL 2.0 * @link None */ $product = $smarty->smarty->tpl_vars['product']->value; $ptid = $product->get('product_type_id'); $type = ProductType::getInstance($ptid); if (!$type) { $c = __('Missing Product Type: %1', array($ptid), 'core'); } $datafields = $type->data_fields; if (!is_array($datafields)) { $datafields = array(); } $c = '<table>'; if (!isset($params['align']) || $params['align'] != 'horizontal') { foreach ($datafields as $data) { $name = $data->ti ? $data->ti : ucwords(str_replace('_', ' ', $data->n)); $c .= '<tr><th class="left">'; $c .= htmlspecialchars(ucfirst($name)); $c .= '</th><td>'; if (!isset($product->vals[$data->n])) {
/** * sends an invoice if the status is right * * @param int $id ID of the order * @param array $order details of the order * * @return null */ function OnlineStore_sendInvoiceEmail($id, $order = false) { if ($order === false) { $order = dbRow("SELECT * FROM online_store_orders WHERE id={$id}"); } $sendAt = (int) dbOne('select val from online_store_vars where name="invoices_by_email"', 'val'); if ($sendAt == 0 && $order['status'] != '1') { return; } if ($sendAt == 1) { // never send return; } if ($sendAt == 2 && $order['status'] != '2') { return; } if ($sendAt == 3 && $order['status'] != '4') { return; } $form_vals = json_decode($order['form_vals']); $items = json_decode($order['items']); $short_domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); // { work out from/to $page = Page::getInstanceByType('online-store'); $page->initValues(); $from = 'noreply@' . $short_domain; $bcc = ''; if ($page && isset($page->vars['online_stores_admin_email']) && $page->vars['online_stores_admin_email']) { $from = $page->vars['online_stores_admin_email']; $bcc = $page->vars['online_stores_admin_email']; } if (isset($form_vals->billing_email)) { $form_vals->Billing_Email = $form_vals->billing_email; } if (!isset($form_vals->Billing_Email) || !$form_vals->Billing_Email) { $form_vals->Billing_Email = $form_vals->Email; } $headers = ''; if ($bcc) { $sendToAdmin = (int) dbOne('select val from online_store_vars where name="invoices_by_email_admin"', 'val'); if (!$sendToAdmin) { $headers .= 'BCC: ' . $bcc . "\r\n"; } } // } Core_trigger('send-invoice', array($order)); // { send invoice if ($form_vals->Billing_Email != '*****@*****.**') { Core_mail($form_vals->Billing_Email, '[' . $short_domain . '] invoice #' . $id, $order['invoice'], $from, '_body', $headers); } // } // { handle item-specific stuff (vouchers, stock control) foreach ($items as $item_index => $item) { if (!$item->id) { continue; } $p = Product::getInstance($item->id); $pt = ProductType::getInstance($p->vals['product_type_id']); if ($pt->is_voucher) { $html = $pt->voucher_template; // { common replaces $html = str_replace('{{$_name}}', $p->name, $html); $html = str_replace('{{$description}}', $p->vals['description'], $html); $html = str_replace('{{$_recipient}}', $form_vals->Billing_Email, $html); $html = str_replace('{{$_amount}}', $p->vals['os_voucher_value'], $html); // } if (strpos($html, '{{PRODUCTS_QRCODE}}') !== false) { // qr code $url = 'http://' . $_SERVER['HTTP_HOST'] . '/a/p=online-store/f=checkQrCode/' . 'oid=' . $order['id'] . '/pid=' . $item_index . '/md5=' . md5($order['invoice']); $html = str_replace('{{PRODUCTS_QRCODE}}', '<img src="http://' . $_SERVER['HTTP_HOST'] . '/a/p=online-store/f=getQrCode/b64=' . urlencode(base64_encode($url)) . '"/>', $html); } Core_mail($form_vals->Billing_Email, '[' . $short_domain . '] voucher', $html, $from, '_body', $headers); } // { stock control if (isset($p->vals['online-store'])) { $valsOS = $p->vals['online-store']; $stock_amount = (int) @$valsOS['_stock_amt'] - $item->amt; $valsOS['_stock_amt'] = $stock_amount; $sold_amount = (int) @$valsOS['_sold_amt'] + $item->amt; $valsOS['_sold_amt'] = $sold_amount; dbQuery('update products set' . ' online_store_fields="' . addslashes(json_encode($valsOS)) . '"' . ', os_amount_in_stock=' . $stock_amount . ', os_amount_sold=' . $sold_amount . ', date_edited=now()' . ' where id=' . $item->id); } // } } Core_cacheClear('products'); // } }
* @link None */ $id = (int) $_REQUEST['product_id']; $product = Product::getInstance($id); if (!$product) { return; } $amount = 1; if (isset($_REQUEST['products-howmany'])) { $amount = (int) $_REQUEST['products-howmany']; } // { find "custom" values $price_amendments = 0; $vals = array(); $md5 = ''; $product_type = ProductType::getInstance($product->vals['product_type_id']); $long_desc = ''; foreach ($_REQUEST as $k => $v) { if (strpos($k, 'products_values_') === 0) { $n = str_replace('products_values_', '', $k); $data_field = $product_type->getField($n); if ($data_field === false || $data_field->u != 1) { continue; } switch ($data_field->t) { case 'selectbox': // { $ok = 0; if (@$product->vals[$n]) { // if product has custom values $strs = explode("\n", $product->vals[$n]);
/** * render a list of products to HTML * * @param object $PAGEDATA the page object * @param int $start offset * @param int $limit how many products to show * @param string $order_by what field to order the search by * @param int $order_dir order ascending or descending * @param int $limit_start lowest $start offset allowed * @param int $enabledFilter whether to allow enabled/disabled products * * @return string the HTML of the products list */ function render($PAGEDATA, $start = 0, $limit = 0, $order_by = '', $order_dir = 0, $limit_start = 0, $enabledFilter = 0) { global $cdnprefix; $c = ''; // { sort based on $order_by $md5 = md5('ps-sorted-' . join(',', $this->product_ids) . '|' . $order_by . '|' . $order_dir . '|' . $enabledFilter); $tmpprods = -1; if ($order_dir != 2) { $tmpprods = Core_cacheLoad('products', $md5, -1); } if ($tmpprods == -1) { if ($order_by != '') { $native = substr($order_by, 0, 1) === '_'; $tmpprods1 = array(); $prods = $this->product_ids; $sql = 'select id'; if (!$native) { $sql .= ',data_fields'; } $sql .= ' from products where id in (' . join(', ', $this->product_ids) . ')'; if ($enabledFilter == 0) { $sql .= ' and enabled'; } if ($enabledFilter == 1) { } if ($enabledFilter == 2) { $sql .= ' and !enabled'; } if ($native) { $sql .= ' order by ' . substr($order_by, 1, strlen($order_by) - 1); if ($order_dir == 1) { $sql .= ' desc'; } } $values = dbAll($sql, '', 'products'); if ($native) { $tmpprods = array(); if (is_array($values)) { foreach ($values as $v) { $tmpprods[] = $v['id']; } if ($order_dir == 2) { shuffle($tmpprods); } } } else { if (is_array($values)) { foreach ($values as $v) { $vals = json_decode($v['data_fields'], true); $key2 = ''; foreach ($vals as $v2) { if ($v2['n'] == $order_by) { $key2 = __FromJSON($v2['v']); } } if (!isset($tmpprods1[$key2])) { $tmpprods1[$key2] = array(); } $tmpprods1[$key2][] = $v['id']; } } if ($order_dir == 1) { krsort($tmpprods1); } else { if ($order_dir == 0) { ksort($tmpprods1); } else { if ($order_dir == 2) { shuffle($tmpprods1); } } } $tmpprods = array(); foreach ($tmpprods1 as $pids) { foreach ($pids as $pid) { $tmpprods[] = $pid; } } foreach ($prods as $key => $pid) { $tmpprods[] = $pid; } } } else { $tmpprods = $this->product_ids; } Core_cacheSave('products', $md5, $tmpprods); } // } // { sanitise the limits $cnt = count($tmpprods); if (!$limit) { $limit = $cnt; $start = 0; } else { if ($start && $start >= count($this->product_ids)) { $start = $cnt - $limit; } } // } // { build array of items $prevnext = ''; $total_found = count($tmpprods); if ($cnt == $limit) { $prods =& $tmpprods; } else { $prods = array(); for ($i = $start; $i < $limit + $start; ++$i) { if (isset($tmpprods[$i])) { $prods[] = $tmpprods[$i]; } } $prefix = ''; if ($PAGEDATA->vars['products_what_to_show'] == 2) { $cat = ProductCategory::getInstance($PAGEDATA->vars['products_category_to_show']); if ($cat) { $prefix = $cat->getRelativeUrl(); } } if (!$prefix) { $prefix = $PAGEDATA->getRelativeUrl(); } if ($start > $limit_start) { $prevnext .= '<a class="products-prev" href="' . $prefix . '?start=' . ($start - $limit) . '">' . __('Previous') . '</a>'; } if ($limit && $start + $limit < $cnt) { if ($start) { $prevnext .= ' | '; } $prevnext .= '<a class="products-next" href="' . $prefix . '?start=' . ($start + $limit) . '">' . __('Next') . '</a>'; } } $prevnext = '<div class="products-pagination">' . $prevnext . '</div>'; // } // { see if there are search results if (isset($PAGEDATA->vars['products_add_a_search_box']) && $PAGEDATA->vars['products_add_a_search_box']) { $c .= '<div class="products-num-results">' . __('<strong>%1</strong> results found.', array($total_found), 'core') . '</div>'; } // } if (!isset($PAGEDATA->vars['products_show_multiple_with'])) { $PAGEDATA->vars['products_show_multiple_with'] = 0; } $prods = array_unique($prods); switch ($PAGEDATA->vars['products_show_multiple_with']) { case 1: // { horizontal table, headers on top $c .= Product_datatableMultiple($prods, 'horizontal'); break; // } // } case 2: // { vertical table, headers on left $c .= Product_datatableMultiple($prods, 'vertical'); break; // } // } case 3: // { map view WW_addScript('products'); WW_addCSS('/ww.plugins/products/products.css'); return '<div id="products-mapview"></div>'; // } // } case 4: // { carousel WW_addScript('products'); $c = '<div id="products-carousel"><ul id="products-carousel-slider">'; foreach ($prods as $pid) { $product = Product::getInstance($pid, false, $enabledFilter); if ($product && isset($product->id) && $product->id) { $typeID = $product->get('product_type_id'); $type = ProductType::getInstance($typeID); if (!$type) { $c .= '<li>' . __('Missing Product Type: %1', array($typeID), 'core') . '</li>'; } else { $c .= '<li id="products-' . $product->id . '" class="products-product">' . $type->render($product, 'multiview', 0) . '</li>'; } } } $c .= '</ul></div>'; WW_addScript('/j/jsor-jcarousel-7bb2e0a/jquery.jcarousel.min.js'); WW_addCSS('/ww.plugins/products/products.css'); return $c; // } // } default: // { use template if (count($prods)) { // display the first item's header $product = Product::getInstance($prods[0], false, $enabledFilter); $type = ProductType::getInstance($product->get('product_type_id')); if ($type) { $smarty = Products_setupSmarty(); $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_header'); } } foreach ($prods as $pid) { $product = Product::getInstance($pid, false, $enabledFilter); if ($product && isset($product->id) && $product->id) { $typeID = $product->get('product_type_id'); $type = ProductType::getInstance($typeID); if (!$type) { $c .= __('Missing Product Type: %1', array($typeID), 'core'); } else { if (isset($_REQUEST['product_id'])) { $c .= $type->render($product, 'singleview'); } else { $c .= $type->render($product, 'multiview'); } } } } if (isset($type) && $type && count($prods)) { // display first item's header $smarty = Products_setupSmarty(); $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_footer'); } // } } $categories = ''; if (!isset($_REQUEST['products-search']) && isset($this->subCategories) && count($this->subCategories) && !@$PAGEDATA->vars['products_dont_show_sub_categories']) { $categories = '<ul class="products-categories categories">'; foreach ($this->subCategories as $cr) { $cat = ProductCategory::getInstance($cr['id']); $categories .= '<li><a href="' . $cat->getRelativeUrl() . '">'; $icon = '/products/categories/' . $cr['id'] . '/icon.png'; if (file_exists(USERBASE . 'f' . $icon)) { $subcatW = (int) $cat->vals['thumbsize_w']; $subcatH = (int) $cat->vals['thumbsize_h']; $categories .= '<img src="' . $cdnprefix . '/a/f=getImg/w=' . $subcatW . '/h=' . $subcatH . '/fmt=' . filemtime(USERBASE . 'f' . $icon) . $icon . '"/>'; } $categories .= '<span>' . htmlspecialchars($cr['name']) . '</span>' . '</a></li>'; } $categories .= '</ul>'; } return $categories . $prevnext . '<div class="products">' . $c . '</div>' . $prevnext; }
} $sql .= ',stockcontrol_total=' . $stockcontrol_total . ',stockcontrol_details="' . addslashes($stockcontrol_detail) . '"'; // } // } if ($id) { $sql = "update products {$sql} where id={$id}"; dbQuery($sql); } else { dbQuery("insert into products {$sql},date_created=now()"); $id = dbLastInsertId(); } // } // { save categories ProductsCategoriesProducts::deleteByProductId($id); if (!isset($_REQUEST['product_categories'])) { $type = ProductType::getInstance((int) $_REQUEST['product_type_id']); $_REQUEST['product_categories'] = array((string) $type->default_category => 'on'); } foreach ($_REQUEST['product_categories'] as $key => $val) { ProductsCategoriesProducts::insert($key, $id); } // } // { save product relations $rls = array(); foreach ($relations as $r) { $rls[$r['id']] = $r; if ($r['one_way']) { dbQuery('delete from products_relations where from_id=' . $id . ' and relation_id=' . $r['id']); } else { dbQuery('delete from products_relations where (from_id=' . $id . ' or to_id=' . $id . ') and relation_id=' . $r['id']); }