private function cartSync($contact = null) { if (!$this->getSettings('enabled')) { return null; } if (!$contact) { $id = wa()->getUser()->getId(); } else { $id = $contact->getId; } $cart = waRequest::cookie('shop_cart'); $model = new shopCartItemsModel(); $carts = $model->query('SELECT code FROM shop_cart_items WHERE contact_id=' . $id)->fetchAssoc(); if (count($carts) == 0) { return null; } $values = array('contact_id' => $id); if (count($carts) == 1) { if ($cart != $carts['code']) { $data = array('code' => $cart); $model->updateByField($data, $values); $data = array('code' => $carts['code']); $model->updateByField($values, $data); $model->updateByField($data, $values); wa()->getResponse()->setCookie('shop_cart', $carts['code'], time() + 30 * 86400, null, '', false, true); return true; } } }
private function getData() { /** * @todo */ $on_page = 10; $data = array(); $m = new shopCartItemsModel(); $sql = "SELECT SUM(quantity) as qty, product_id FROM shop_cart_items WHERE " . $this->getTimeQuery() . ' GROUP BY product_id ORDER BY qty DESC'; $items = $m->query($sql)->fetchAll('product_id', true); if ($items) { $other = 0; if (count($items) > $on_page) { $items1 = array(); $i = 0; foreach ($items as $product_id => $quantity) { if ($i++ < $on_page) { $items1[$product_id] = $quantity; } else { $other += $quantity; } } $items = $items1; unset($items1); } $pm = new shopProductModel(); $products = $pm->select('id, name')->where('id IN(?)', array(array_keys($items)))->fetchAll('id', true); foreach ($items as $product_id => $quantity) { $data[] = array('label' => ifset($products[$product_id], _wp('(no name)')), 'value' => $quantity, 'id' => $product_id); } if ($other) { $data[] = array('label' => _wp('Other...'), 'value' => $other, 'id' => 'other'); } } return $data; }