Exemplo n.º 1
0
function do_edit_save($aid, $params)
{
    $pid = cf\api\admin\doAction($aid, $params);
    if (array_key_exists('id', $params)) {
        $pid = $params['id'];
    }
    //update categories
    $pos = cf\query2arrays('SELECT group_id,sort_order FROM cf_products_in_groups WHERE product_id=:id', array('id' => $pid), false, 'group_id');
    cf\execQuery('DELETE FROM cf_products_in_groups WHERE product_id=:id', array('id' => $pid));
    $categories = cf\param::exist('category') ? cf\param::get('category') : array();
    $q = cf\createQuery('INSERT INTO cf_products_in_groups (group_id,product_id,sort_order) VALUES(:groupId,:productId,:sortOrder)', array('productId' => $pid));
    foreach ($categories as $catId) {
        $q->setParam('groupId', $catId);
        $q->setParam('sortOrder', array_key_exists($catId, $pos) ? $pos[$catId]['sort_order'] : 500);
        $q->execute();
    }
    //update attributes
    if (cf\param::exist('attributes')) {
        $attrValues = cf\param::get('attributes');
        $attributes = new cf\ProductAttributes($pid, true);
        foreach ($attributes as $attr) {
            if (array_key_exists($attr->id(), $attrValues)) {
                $attr->setValue($attrValues[$attr->id()]);
            }
        }
        $product = new cf\Product($pid);
        $product->setAttributes($attributes);
    }
}
Exemplo n.º 2
0
function findProductByPath($path)
{
    $pid = \cf\Product::findByPath($path);
    if (!$pid) {
        return false;
    }
    $product = new \cf\Product($pid);
    $product->fullDescr();
    return $product->toArray();
}
Exemplo n.º 3
0
<?php

require_once dirname(__FILE__) . '/cf/config.php';
require_once cf\Config::path . 'image.php';
require_once cf\Config::path . 'shop.php';
$product = new cf\Product($_REQUEST['p']);
$images = $product->images();
$path = $images[array_key_exists('i', $_REQUEST) ? $_REQUEST['i'] : 0];
$thumb = new cf\Thumbnail(cf\Config::root_path . $path, 391, 358);
$fpath = $thumb->path();
$img = cf\Image::loadFromFile($fpath);
$watermark = cf\Image::loadFromFile(cf\Config::root_path . 'images/logo_white.png');
$watermark->setColorTransparentAsAt(1, 2);
$img->putWatermark($watermark, 60, ($img->width() - $watermark->width()) / 2, $img->height() - $watermark->height());
header('content-type: ' . cf\Image::getImageMime($fpath));
$img->output(cf\Image::getImageType($fpath));
Exemplo n.º 4
0
function getProduct($id)
{
    if (!$id) {
        return array();
    }
    $product = new \cf\Product($id);
    $groups = new \cf\ProductGroups($id, true);
    return array('id' => $product->id(), 'code' => $product->code(), 'name' => $product->name(), 'fullName' => $product->fullName(), 'price' => $product->price(), 'groups' => $groups->IDs(), 'attributes' => $product->attributes()->values(), 'manufacturerName' => $product->manufacturerName(), 'manufacturerId' => $product->manufacturerId(), 'image' => $product->image(), 'rating' => $product->rating(), 'images' => $product->images(), 'imageTexts' => $product->imageTexts(), 'shortDescr' => $product->shortDescr(), 'fullDescr' => $product->fullDescr(), 'sellerId' => $product->sellerId(), 'sellerName' => $product->sellerName(), 'sellerLink' => $product->sellerLink(), 'link' => $product->link(), 'article' => $product->article(), 'state_id' => $product->stateId(), 'state' => $product->state());
}
Exemplo n.º 5
0
     if ($c) {
         $hiddenCategories[$c['id']] = $c;
     }
 }
 $smarty->assign('catalogMenu', array_merge($hiddenCategories, $catalogMenu));
 $smarty->assign('pricelist', cf\Page::get('pricelist'));
 $smarty->assign('searchPage', cf\Page::get('search'));
 $pid = 'home';
 try {
     if (array_key_exists('path', $_REQUEST) && strlen($_REQUEST['path'])) {
         $pathInfo = cf\Page::findByPath($_REQUEST['path']);
         if (strlen($pathInfo['found'])) {
             $pid = $pathInfo['page_id'];
             if (strlen($pathInfo['notfound'])) {
                 $p = cf\Page::get($pid);
                 if (!(cf\Page::isDescendantOf($p, 'catalog') && ($productId = cf\Product::findByPath($pathInfo['notfound']))) && $p['permalink'] != 'articles') {
                     $pid = 'error';
                 }
             }
         } else {
             $pid = 'error';
         }
     }
 } catch (Exception $e) {
     $pid = 'error';
 }
 $page = cf\Page::get($pid);
 $pageText = cf\api\page\getText($page['id']);
 $crumbs = array();
 foreach ($page['branch'] as $p) {
     $crumbs[] = array('name' => $p['menu_name'], 'link' => $p['path']);
Exemplo n.º 6
0
function getList()
{
    $user = \cf\User::getLoggedIn();
    $ids = array();
    if ($user) {
        $cid = create();
        $products = \cf\query2arrays('SELECT product_id, amount FROM cf_products_in_cart WHERE cart_id=:cid', array('cid' => $cid), false, 'product_id');
        $productIDs = array();
        foreach ($products as $id => $p) {
            $productIDs[$id] = $p['amount'];
        }
    } else {
        $c = create();
        $productIDs = $c->getParam('ready');
    }
    $cart = array('contents' => array());
    $total_qty = 0;
    $total_price = 0;
    foreach ($productIDs as $id => $qty) {
        $product = new \cf\Product($id);
        $cart['contents'][$product->id()] = array('product' => $product->toArray(), 'qty' => $qty, 'total' => $product->price() * $qty);
        $total_qty += $qty;
        $total_price += $product->price() * $qty;
    }
    $ruProducts = 'товаров';
    if ($total_qty % 100 < 10 || $total_qty % 100 > 20) {
        if ($total_qty % 10 == 1) {
            $ruProducts = 'товар';
        } else {
            if ($total_qty % 10 > 1 && $total_qty % 10 < 5) {
                $ruProducts = 'товара';
            }
        }
    }
    $cart['ru_products'] = $ruProducts;
    $cart['total'] = array('qty' => $total_qty, 'sum' => $total_price);
    return $cart;
}
Exemplo n.º 7
0
<?php

$p = 1;
if (strlen($pathInfo['notfound'])) {
    $productId = cf\Product::findByPath($pathInfo['notfound']);
    if ($productId) {
        require_once dirname(__FILE__) . '/product.php';
        return true;
    }
    $matches = array();
    if (!preg_match('/page-(\\d+)/', $pathInfo['notfound'], $matches)) {
        return false;
    }
    $p = $matches[1];
}
$productsOnPage = 9;
$params = array('in' => $page['id']);
$filter = array();
if (array_key_exists('price', $_REQUEST) && is_array($_REQUEST['price']) && count($_REQUEST['price']) == 2) {
    $params['price'] = $filter['price'] = $_REQUEST['price'];
}
if (array_key_exists('attribute', $_REQUEST) && is_array($_REQUEST['attribute'])) {
    $params['attribute'] = $filter['attribute'] = $_REQUEST['attribute'];
}
if (array_key_exists('search', $_REQUEST) && strlen(trim($_REQUEST['search']))) {
    $search = trim($_REQUEST['search']);
    $params['name'] = $filter['search'] = $search;
    $page['name'] .= " - поиск: {$search}";
}
$smarty->assign('products', cf\api\shop\products(array_merge($params, array('skip' => ($p - 1) * $productsOnPage, 'limit' => $productsOnPage))));
$smarty->assign('numOfProducts', cf\api\shop\count($params));
Exemplo n.º 8
0
function getList()
{
    $user = \cf\User::getLoggedIn();
    $ids = array();
    if ($user) {
        $cid = create();
        $products = \cf\query2arrays('SELECT product_id, amount FROM cf_products_in_cart WHERE cart_id=:cid', array('cid' => $cid), false, 'product_id');
        $productIDs = array();
        foreach ($products as $id => $p) {
            $productIDs[$id] = $p['amount'];
        }
    } else {
        $c = create();
        $productIDs = $c->getParam('ready');
    }
    $cart = array();
    $total_number = 0;
    $total_price = 0;
    foreach ($productIDs as $id => $amount) {
        $product = new \cf\Product($id);
        $cart[] = array('id' => $product->id(), 'name' => $product->fullName(), 'amount' => $amount, 'price' => $product->price(), 'image' => $product->image(), 'manufacturerName' => $product->manufacturerName(), 'total_price' => $product->price() * $amount, 'attributes' => $product->attributes()->values());
        $total_number += $amount;
        $total_price += $product->price() * $amount;
    }
    $ruProducts = 'товаров';
    if ($total_number % 100 < 10 || $total_number % 100 > 20) {
        if ($total_number % 10 == 1) {
            $ruProducts = 'товар';
        } else {
            if ($total_number % 10 > 1 && $total_number % 10 < 5) {
                $ruProducts = 'товара';
            }
        }
    }
    return array_merge(array(array('total_amount' => $total_number, 'number' => $total_number, 'total_price' => $total_price, 'sum' => $total_price, 'ru_products' => $ruProducts)), $cart);
}