/**
  * setup initial game data when player play the game for the first time.
  * invoked by: Controller.GameServer.setup_data()
  * @param $game_data
  * @return bool
  */
 public function setup_game_data($game_data)
 {
     $game_data["gme_player"] = $_SESSION['ply_id'];
     $this->Create(Utility::TABLE_GAME_DATA, $game_data);
     $product = Product::getInstance();
     $product->initialize_product();
     $asset = Asset::getInstance();
     $asset->initialize_asset();
     return true;
 }
 /**
  * update product price.
  *
  * role: player
  */
 public function update_product_price()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_product = Product::getInstance();
             $product = $_POST['product_data'];
             $result = $this->model_product->update_player_product($product);
             $binding = array("result_var" => "session_ready", "status_var" => $result);
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
Example #3
0
/**
 * retrieve message for when someone tries to add an expired item to cart
 *
 * @return string message
 */
function OnlineStore_getExpiryNotification()
{
    $id = (int) $_REQUEST['id'];
    $p = dbRow('select * from products where id=' . $id);
    $product = Product::getInstance($id, $p, true);
    $typeid = $p['product_type_id'];
    $nfile = USERBASE . '/ww.cache/products/templates/expiry_notification_' . $typeid;
    if (!file_exists($nfile)) {
        $t = dbRow('select template_expired_notification from products_types where id=' . $typeid);
        $template = strlen($t['template_expired_notification']) > 4 ? $t['template_expired_notification'] : '' . __('This product has expired. You cannot add it to the cart.') . '';
        file_put_contents($nfile, $template);
    }
    require_once SCRIPTBASE . '/ww.incs/common.php';
    $smarty = Products_setupSmarty();
    $smarty->assign('product', $product);
    $smarty->assign('product_id', $product->get('id'));
    $smarty->assign('_name', __FromJson($product->name));
    $smarty->assign('_stock_number', $product->stock_number);
    return $smarty->fetch($nfile);
}
 /**
  * retrieve inventory data.
  * role: player
  */
 public function retrieve_inventory()
 {
     if (Authenticate::is_player()) {
         if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_product = Product::getInstance();
             $this->model_material = Material::getInstance();
             $this->model_asset = Asset::getInstance();
             $product = $this->model_product->get_player_product();
             $material = $this->model_material->get_player_material();
             $asset = $this->model_asset->get_player_asset();
             $binding = array("result_var" => "session_ready", "product_var" => json_encode($product, JSON_PRETTY_PRINT), "material_var" => json_encode($material, JSON_PRETTY_PRINT), "asset_var" => json_encode($asset, JSON_PRETTY_PRINT));
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
Example #5
0
/**
 * generates a formatted price, including currency symbol
 *
 * @param array  $params parameters for the function
 * @param object $smarty the current Smarty object
 *
 * @return string HTML of the price
 */
function OnlineStore_productPriceFull2($params, $smarty)
{
    $params = array_merge(array('vat' => 0), $params);
    if (!$params['vat'] && $_SESSION['onlinestore_prices_shown_post_vat']) {
        $params['vat'] = 1;
    }
    $pid = $smarty->smarty->tpl_vars['product']->value->id;
    $product = Product::getInstance($pid);
    $vat = $params['vat'] ? (100 + $_SESSION['onlinestore_vat_percent']) / 100 : 1;
    $vatclass = $params['vat'] ? ' vat' : '';
    $sale_price = $product->getPriceSale();
    if ($sale_price) {
        $tmp = '<strike class="os_price">' . OnlineStore_numToPrice($product->getPrice() * $vat) . '</strike> <strong class="os_price with-sale-price' . $vatclass . '">' . OnlineStore_numToPrice($sale_price * $vat) . '</strong>';
    } else {
        $tmp = '<strong class="os_price' . $vatclass . '">' . OnlineStore_numToPrice($product->getPriceBase() * $vat) . '</strong>';
    }
    list($bp, $ba) = $product->getPriceBulkAll();
    if ($bp && $ba) {
        $tmp .= '<br />' . OnlineStore_numToPrice($bp * $vat) . ' for ' . $ba . ' or more';
    }
    $tmp = '<span class="os_full_price">' . $tmp . '</span>';
    return $tmp;
}
Example #6
0
 }
 $c .= '<th>' . __('Price', 'core') . '</th>' . '<th>' . __('Amount', 'core') . '</th>' . '<th class="totals">' . __('Total') . '</th>' . '</tr>';
 // }
 // { set up variables
 $grandTotal = 0;
 $deliveryTotal = 0;
 $discountableTotal = 0;
 $vattable = 0;
 $has_vatfree = false;
 // }
 foreach ($_SESSION['online-store']['items'] as $md5 => $item) {
     $c .= '<tr product="' . $md5 . '" class="os_item_numbers ' . $md5 . '">';
     // { item name and details
     $c .= '<td class="products-itemname">';
     if (isset($item['id']) && $item['id']) {
         $p = Product::getInstance($item['id']);
         if ($p) {
             $img = $p->getDefaultImage();
             if ($img) {
                 $c .= '<a href="/f/' . $img . '" target="popup" ' . 'class="online-store-thumb-wrapper">' . '<img src="/a/f=getImg/w=auto/h=125/' . $img . '"/>' . '</a>';
             }
         }
     }
     if (isset($item['url']) && !empty($item['url'])) {
         $c .= '<a href="' . $item['url'] . '">';
     }
     $c .= htmlspecialchars(__FromJson($item['short_desc']));
     if (isset($item['url']) && !empty($item['url'])) {
         $c .= '</a>';
     }
     if (!$item['vat'] && !$user_is_vat_free) {
Example #7
0
<?php

/**
 * export products to CSV
 *
 * PHP version 5.2
 *
 * @category None
 * @package  None
 * @author   Kae Verens <*****@*****.**>
 * @license  GPL 2.0
 * @link     http://kvsites.ie/
 */
require_once 'datatable-libs.php';
require_once dirname(__FILE__) . '/../api.php';
$i = 0;
header('Content-type: text/csv; Charset=utf-8');
header('Content-Disposition: attachment; filename="nfgws-export.csv"');
echo '"' . join('","', $columns) . "\"\n";
for (; $i < $total_records; ++$i) {
    $arr = array();
    $p = Product::getInstance($products->product_ids[$i]);
    foreach ($columns as $name) {
        $arr[] = $p->getString($name);
    }
    echo Products_arrayToCSV($arr);
}
Example #8
0
function OnlineStore_updateProductSales($id, $items = false, $date_created = false)
{
    if (!$items) {
        $r = dbRow('select date_created, items from online_store_orders where id=' . $id);
        $items = json_decode($r['items'], true);
        $date_created = $r['date_created'];
    }
    dbQuery('delete from online_store_sales where order_id=' . $id);
    foreach ($items as $k => $v) {
        $p = Product::getInstance($v['id']);
        $profit = 0;
        if ($p) {
            $profit = $p->vals['os_base_price'] - $p->vals['os_supplier_price'];
        }
        $sql = 'insert into online_store_sales set order_id=' . $id . ', source="eBay", product_id=' . $v['id'] . ', profit=' . $profit * $v['amt'] . ', quantity=' . $v['amt'] . ', cdate="' . addslashes($date_created) . '"';
        dbQuery($sql);
    }
}
 /**
  * load game data every play game.
  * role: player
  * @return string
  */
 public function load_data()
 {
     if (Authenticate::is_player()) {
         if (true || isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) {
             $this->model_product = Product::getInstance();
             $this->model_material = Material::getInstance();
             $this->model_asset = Asset::getInstance();
             $this->model_supplier = Supplier::getInstance();
             $this->model_employee = Employee::getInstance();
             $this->model_achievement = Achievement::getInstance();
             $this->model_journal = Journal::getInstance();
             $this->model_memorycard = Memorycard::getInstance();
             $this->model_leaderboard = Leaderboard::getInstance();
             /*
              * retrieve data each component.
              * log this event, wrap it up and convert to json format.
              */
             $game = $this->model_memorycard->load_game_data();
             $work_history = $this->model_memorycard->get_work_stress_history();
             $total_work = $this->model_memorycard->get_total_work();
             $candidate = $this->model_employee->get_candidate();
             $employee = $this->model_employee->get_player_employee();
             $material = $this->model_material->get_material_data();
             $player_material = $this->model_material->get_player_material();
             $asset = $this->model_asset->get_asset_data();
             $player_asset = $this->model_asset->get_player_asset();
             $product = $this->model_product->get_product_data();
             $player_product = $this->model_product->get_player_product();
             $product_material = $this->model_product->get_product_material();
             $supplier = $this->model_supplier->get_supplier_data();
             $achievement = $this->model_achievement->get_achievement();
             $account = $this->model_journal->get_account();
             $simulation = $this->model_memorycard->get_simulation();
             $star = $this->model_leaderboard->get_player_ranking();
             $binding = array("result_var" => "session_ready", "game_var" => json_encode($game, JSON_PRETTY_PRINT), "candidate_var" => json_encode($candidate, JSON_PRETTY_PRINT), "employee_var" => json_encode($employee, JSON_PRETTY_PRINT), "product_var" => json_encode($product, JSON_PRETTY_PRINT), "player_product_var" => json_encode($player_product, JSON_PRETTY_PRINT), "product_material_var" => json_encode($product_material, JSON_PRETTY_PRINT), "material_var" => json_encode($material, JSON_PRETTY_PRINT), "player_material_var" => json_encode($player_material, JSON_PRETTY_PRINT), "asset_var" => json_encode($asset, JSON_PRETTY_PRINT), "player_asset_var" => json_encode($player_asset, JSON_PRETTY_PRINT), "supplier_var" => json_encode($supplier, JSON_PRETTY_PRINT), "achievement_var" => json_encode($achievement, JSON_PRETTY_PRINT), "account_var" => json_encode($account, JSON_PRETTY_PRINT), "simulation_var" => json_encode($simulation, JSON_PRETTY_PRINT), "work_history_var" => json_encode($work_history, JSON_PRETTY_PRINT), "work_total_var" => $total_work, "star" => $star["star"]);
             $log = Log::getInstance();
             $log->logging_game_load(json_encode($binding));
             binding_data($binding);
         } else {
             transport("error404");
         }
     } else {
         $binding = array("result_var" => "no_session");
         binding_data($binding);
     }
 }
Example #10
0
/**
 * edit a single value of a product
 *
 * @return array status
 */
function Products_adminProductEditVal()
{
    $id = (int) $_REQUEST['id'];
    $name = strtolower($_REQUEST['name']);
    $value = $_REQUEST['val'];
    if ($name == 'id') {
        return array('error' => 'field not allowed');
    }
    Product::getInstance($id, false, true)->set($name, $value);
    if ($name == 'enabled') {
        if ($value == '0') {
            dbQuery('update products set activates_on=now() where id=' . $id . ' and activates_on>now()');
            dbQuery('update products set expires_on=now() where id=' . $id . ' and expires_on>now()');
        } else {
            dbQuery('update products set expires_on=null where id=' . $id . ' and expires_on<now()');
        }
    }
    Core_cacheClear();
    return array('ok' => 1);
}
Example #11
0
function OnlineStoreEbay_adminLinkProductToEbay()
{
    $id = (int) $_REQUEST['id'];
    $ebay_id = (int) $_REQUEST['ebay_id'];
    Product::getInstance($id)->set(array('ebay_currently_active' => 1, 'ebay_id' => $ebay_id));
}
Example #12
0
<?php

/**
 * set default image
 *
 * PHP version 5.2
 *
 * @category None
 * @package  None
 * @author   Kae Verens <*****@*****.**>
 * @license  GPL 2.0
 * @link     http://kvsites.ie/
 */
require $_SERVER['DOCUMENT_ROOT'] . '/ww.incs/basics.php';
if (!Core_isAdmin()) {
    die(__('access denied'));
}
$product_id = (int) $_REQUEST['product_id'];
$imgsrc = '/' . $_REQUEST['imgsrc'];
Product::getInstance($product_id)->set('image_default', $imgsrc);
echo 'ok';
Example #13
0
/**
 * show an image of a QR code leading to a product
 *
 * @return null
 */
function Products_showQrCode()
{
    $pid = (int) $_REQUEST['pid'];
    $product = Product::getInstance($pid);
    if (!$product) {
        redirect('/i/blank.gif');
    }
    $fname = USERBASE . '/ww.cache/products/qr' . $pid;
    if (!file_exists($fname)) {
        require_once SCRIPTBASE . '/ww.incs/phpqrcode.php';
        @mkdir(USERBASE . '/ww.cache/products');
        QRcode::png('http://' . $_SERVER['HTTP_HOST'] . $product->getRelativeUrl(), $fname);
    }
    header('Content-type: image/png');
    header('Cache-Control: max-age=2592000, public');
    header('Expires-Active: On');
    header('Expires: Fri, 1 Jan 2500 01:01:01 GMT');
    header('Pragma:');
    header('Content-Length: ' . filesize($fname));
    readfile($fname);
    Core_quit();
}
Example #14
0
    foreach ($rs as $r) {
        dbQuery('update products_categories set' . ' link="' . addslashes(transcribe($r['name'])) . '"' . 'where id=' . $r['id']);
    }
    $version = 35;
}
if ($version == 35) {
    // fix a bug that has popped up again
    dbQuery('alter table products_types change stock_management stock_control ' . 'smallint default 0');
    $version = 36;
}
if ($version == 36) {
    // change default image to text
    dbQuery('alter table products change image_default image_default text');
    $rs = dbAll('select id from products');
    foreach ($rs as $r) {
        $product = Product::getInstance($r['id']);
        $url = $product->getDefaultImage();
        if (!$url) {
            $url = '';
        }
        dbQuery('update products set' . ' image_default="' . addslashes($url) . '"' . ' where id=' . $r['id']);
    }
    $version = 37;
}
if ($version == 37) {
    // add EAN number to products
    dbQuery('alter table products add ean char(13) default ""');
    $version = 38;
}
if ($version == 38) {
    // periodic imports
Example #15
0
/**
 * exports to file if the status is right
 *
 * @param int   $id    ID of the order
 * @param array $order details of the order
 *
 * @return null
 */
function OnlineStore_exportToFile($id)
{
    $order = dbRow("SELECT * FROM online_store_orders WHERE id={$id}");
    $sendAt = (int) dbOne('select val from online_store_vars where name="export_at_what_point"', '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']);
    // { start export
    $export = dbOne('select val from online_store_vars where name="export_dir"', 'val');
    // TODO: ability to edit these values in the admin
    $exportcsv = array('"Phone Number","Customer Name","Address 1","Address 2","Postcode",' . '"Email","Stock Number","Amt","Price","Item ID"');
    // }
    // { handle item-specific stuff (vouchers, stock control)
    foreach ($items as $item_index => $item) {
        if (!$item->id) {
            continue;
        }
        $p = Product::getInstance($item->id);
        $exportcsv[] = '"' . str_replace('"', '""', @$form_vals->Billing_Phone) . '","' . str_replace('"', '""', @$form_vals->Billing_FirstName . ' ' . @$form_vals->Billing_Surname) . '","' . str_replace('"', '""', @$form_vals->Billing_Street) . '","' . str_replace('"', '""', @$form_vals->Billing_Street2) . '","' . str_replace('"', '""', @$form_vals->Billing_Postcode) . ' ' . str_replace('"', '""', @$form_vals->Billing_Town) . '","' . str_replace('"', '""', @$form_vals->Billing_Email) . '","' . str_replace('"', '""', @$p->Billing_stock_number) . '","' . $item->amt . '","' . $item->cost . '","' . $item->id . '"';
        // }
    }
    // }
    Core_cacheClear('products');
    if ($export && strpos($export, '..') === false) {
        $customer = dbOne('select val from online_store_vars where name="export_customers"', 'val');
        if ($customer && strpos($customer, '..') === false) {
            $customer_filename = dbOne('select val from online_store_vars' . ' where name="export_customer_filename"', 'val');
            if (!$customer_filename) {
                $customer_filename = 'customer-{{$Billing_Email}}.csv';
            }
            $customer_filename = str_replace(array('/', '..'), '', $customer_filename);
            $bits = preg_match_all('/{{\\$([^}]*)}}/', $customer_filename, $matches, PREG_SET_ORDER);
            foreach ($matches as $bit) {
                $customer_filename = str_replace('{{$' . $bit[1] . '}}', @$form_vals->{$bit[1]}, $customer_filename);
            }
            $customer_filename = str_replace(array('..', '/'), '', $customer_filename);
            @mkdir(USERBASE . '/' . $customer, 0777, true);
            $phone = preg_replace('/[^0-9\\(\\)\\+]/', '', @$form_vals->Billing_Phone);
            // TODO: must be able to edit values in the admin
            $fcontent = '"Name","Street","Street 2","Postcode","Email","Phone"' . "\n" . '"' . str_replace('"', '""', @$form_vals->Billing_FirstName . ' ' . @$form_vals->Billing_Surname) . '","' . str_replace('"', '""', @$form_vals->Billing_Street) . '","' . str_replace('"', '""', @$form_vals->Billing_Street2) . '","' . str_replace('"', '""', @$form_vals->Billing_Postcode) . '","' . str_replace('"', '""', @$form_vals->Billing_Email) . '","' . str_replace('"', '""', $form_vals->Billing_Phone) . '"';
            file_put_contents(USERBASE . '/' . $customer . '/' . $customer_filename, "" . $fcontent);
        }
        @mkdir(USERBASE . '/' . $export, 0777, true);
        file_put_contents(USERBASE . '/' . $export . '/order' . $id . '.csv', "" . join("\r\n", $exportcsv));
    }
}
final class Product
{
    //@var self
    private static $instance;
    //@var mixed
    public $mix;
    /**
     * Return self instance
     * @return self
     */
    public static function getInstance()
    {
        if (!self::$instance instanceof self) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    public function __construct()
    {
    }
    public function __clone()
    {
    }
}
$firstProduct = Product::getInstance();
$firstProduct->mix = 'first';
var_dump($firstProduct->mix);
$secondProduct = Product::getInstance();
$secondProduct->mix = 'second';
var_dump($firstProduct->mix);
var_dump($secondProduct->mix);
Example #17
0
/**
 * show owner's name
 *
 * @param array  $params parameters
 * @param object $smarty Smarty object
 *
 * @return string HTML
 */
function Products_user2($params, $smarty)
{
    $pid = $smarty->smarty->tpl_vars['product']->value->id;
    $product = Product::getInstance($pid);
    $uid = (int) $product->get($params['pfield']);
    $user = User::getInstance($uid, false, false);
    if ($user) {
        return $user->get($params['ufield']);
    }
}
Example #18
0
 *
 * @category None
 * @package  None
 * @author   Kae Verens <*****@*****.**>
 * @license  GPL 2.0
 * @link     None
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/ww.incs/basics.php';
$md5 = $_REQUEST['md5'];
$id = preg_replace('/^products_([0-9]*)(,.*)?$/', '\\1', $md5);
$md5 = preg_replace('/^products_[0-9]*/', '', $md5);
if (!isset($_SESSION['online-store']['items']['products_' . $id . $md5])) {
    // TODO: translation needed
    die(__('No such item'));
}
$product = Product::getInstance($id);
require_once '../libs.php';
$amount = (int) $_REQUEST['amt'] - $_SESSION['online-store']['items']['products_' . $id . $md5]['amt'];
// { does the amount requested bring it over the maximum allowed per purchase
$max_allowed = isset($product->vals['os_amount_allowed_per_purchase']) ? (int) $product->vals['os_amount_allowed_per_purchase'] : 0;
// }
list($price, $amount, $vat) = Products_getProductPrice($product, $amount, $md5, false);
if ($max_allowed && $amount > $max_allowed) {
    $amount = $max_allowed;
}
if ($amount < 1) {
    unset($_SESSION['online-store']['items']['products_' . $id . $md5]);
} else {
    $_SESSION['online-store']['items']['products_' . $id . $md5]['cost'] = $price;
    $_SESSION['online-store']['items']['products_' . $id . $md5]['amt'] = $amount;
}
Example #19
0
 /**
  * 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;
 }
 public function pendingProducts()
 {
     $objProductModel = Product::getInstance();
     $pendingProducts = $objProductModel->getAllProductsWhereStatus('0');
     return view('Admin/Views/product/pending-produtcs', ['pendingProducts' => $pendingProducts]);
 }
Example #21
0
$rs = ProductsCategoriesProducts::getByProductId($id);
echo '<ul id="categories-wrapper">';
foreach ($rs as $r) {
    $cat = ProductCategory::getInstance($r);
    if (!$cat) {
        continue;
    }
    echo '<li><input type="checkbox" name="product_categories[' . $cat->vals['id'] . ']" checked="checked"/>' . $cat->getBreadcrumbs() . '</li>';
}
echo '</ul><button id="category-add">Add Category</button>';
// }
$cid = (int) @$pdata['default_category'];
if (!$cid) {
    $cid = 1;
}
$default_category = Product::getInstance($cid)->vals['name'];
echo '<br/><label>Default Category: <select name="products_default_category">' . '<option value="' . (int) @$pdata['products_default_category'] . '">' . $default_category . '</option></select></label>';
echo '</div>';
// }
// { related items
if (count($relations)) {
    echo '<h2>' . __('Relations') . '</h2><div id="relations">' . '<table id="product-relations"><tr><th>Relation Type</th><th>Related P' . 'roduct</th></tr>';
    foreach ($relations as $relation) {
        $ps = dbAll('select * from products_relations where relation_id=' . $relation['id'] . ' and from_id=' . $id);
        $options = '<option value=""> -- ' . __('Choose') . ' -- </option>';
        foreach ($relations as $r) {
            $options .= '<option value="' . $r['id'] . '"';
            if ($r['id'] == $relation['id']) {
                $options .= ' selected="selected"';
            }
            $options .= '>' . htmlspecialchars($r['name']) . '</option>';