function findProductByPath($path) { $pid = \cf\Product::findByPath($path); if (!$pid) { return false; } $product = new \cf\Product($pid); $product->fullDescr(); return $product->toArray(); }
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; }