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; }
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()); }
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); }