public function warehouseCount($cart_id = 0) { $warehouseIds = []; if (class_exists('Geography\\City\\Data')) { $warehouses = \Geography\City\Data::get([['code', 'warehouses'], ['city_id', \Geography\City::$cur->id]]); if ($warehouses && $warehouses->data) { foreach (explode(',', $warehouses->data) as $id) { $warehouseIds[$id] = $id; } } } if ($warehouseIds) { \App::$cur->db->where(\Ecommerce\Item\Offer\Warehouse::colPrefix() . \Ecommerce\Warehouse::index(), $warehouseIds, 'IN'); } \App::$cur->db->where(\Ecommerce\Item\Offer\Warehouse::colPrefix() . \Ecommerce\Item\Offer::index(), $this->id); \App::$cur->db->cols = 'COALESCE(sum(' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . 'count),0) as `sum` '; $warehouse = \App::$cur->db->select(\Ecommerce\Item\Offer\Warehouse::table())->fetch(); \App::$cur->db->cols = 'COALESCE(sum(' . \Ecommerce\Warehouse\Block::colPrefix() . 'count) ,0) as `sum` '; \App::$cur->db->where(\Ecommerce\Warehouse\Block::colPrefix() . \Ecommerce\Item\Offer::index(), $this->id); if ($cart_id) { \App::$cur->db->where(\Ecommerce\Warehouse\Block::colPrefix() . \Ecommerce\Cart::index(), (int) $cart_id, '!='); } $on = ' ' . \Ecommerce\Cart::index() . ' = ' . \Ecommerce\Warehouse\Block::colPrefix() . \Ecommerce\Cart::index() . ' AND ( (`' . \Ecommerce\Cart::colPrefix() . 'warehouse_block` = 1 and `' . \Ecommerce\Cart::colPrefix() . 'cart_status_id` in(2,3,6)) || (`' . \Ecommerce\Cart::colPrefix() . 'cart_status_id` in(0,1) and `' . \Ecommerce\Cart::colPrefix() . 'date_last_activ` >=subdate(now(),INTERVAL 30 MINUTE)) ) '; \App::$cur->db->join(\Ecommerce\Cart::table(), $on, 'inner'); $blocked = \App::$cur->db->select(\Ecommerce\Warehouse\Block::table())->fetch(); return (double) $warehouse['sum'] - (double) $blocked['sum']; }
public static function getFinalSum($pay, $method) { $sum = parent::getFinalSum($pay, $method); if ($pay->data && ($cart = \Ecommerce\Cart::get($pay->data))) { $extra = '0.' . (strlen((string) $cart->id) > 1 ? substr((string) $cart->id, -2) : $cart->id); } else { $extra = 0; } return $sum + $extra; }
public function parseOrders($orders) { foreach ($orders as $order) { $cart = \Ecommerce\Cart::get((string) $order->Номер); if (!$cart) { continue; } $reqs = []; foreach ($order->ЗначенияРеквизитов->ЗначениеРеквизита as $req) { $reqs[(string) $req->Наименование] = (string) $req->Значение; } $payed = false; $cancel = false; if (!empty($reqs['Дата оплаты по 1С']) && $reqs['Дата оплаты по 1С'] != 'T') { $payed = true; $date = new \DateTime((string) $reqs['Дата оплаты по 1С']); $cart->payed_date = $date->format('Y-m-d H:i:s'); } elseif (!empty($reqs['Отменен']) && $reqs['Отменен'] == 'true' || !empty($reqs['Дата оплаты по 1С']) && $reqs['Дата оплаты по 1С'] == 'T') { $cancel = true; } $this->updateCartItems($cart, $order->Товары->Товар); $cart->payed = $payed; if ($payed && $cart->cart_status_id == 5) { } elseif ($payed && $cart->cart_status_id == 3) { $cart->cart_status_id = 5; $cart->save(); } elseif ($cancel && $cart->cart_status_id == 3) { $cart->cart_status_id = 4; } if ($cart->warehouse_block && !$payed && !$cancel && !empty($reqs['Проведен']) && $reqs['Проведен'] == 'true') { $cart->warehouse_block = 0; foreach ($cart->cartItems as $cci) { if ($cci->price && $cci->price->offer) { $cci->price->offer->changeWarehouse('-' . (double) $cci->count); } } } //$cart->cc_exported = 1; $cart->save(); } }
public function process() { function addToXml($xml, $parent, $nodeName, $text) { $node = $parent->appendChild($xml->createElement($nodeName)); $node->appendChild($xml->createTextNode($text)); return $node; } header("Content-Type: text/xml"); header("Expires: Thu, 19 Feb 1998 13:24:18 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Cache-Control: post-check=0,pre-check=0"); header("Cache-Control: max-age=0"); header("Pragma: no-cache"); $xml = new \DOMDocument('1.0', 'windows-1251'); $xml->formatOutput = true; $root = $xml->createElement('КоммерческаяИнформация'); $root->setAttribute("ВерсияСхемы", "2.03"); $root->setAttribute("ДатаФормирования", date('Y-m-d')); $root = $xml->appendChild($root); $carts = \Ecommerce\Cart::getList(['where' => ['cart_status_id', empty(\App::$cur->Exchange1c->config['uploadStatusId']) ? '3' : \App::$cur->Exchange1c->config['uploadStatusId'], 'IN']]); foreach ($carts as $cart) { $doc = $xml->createElement('Документ'); $statusDateTime = new \DateTime($cart->complete_data); $items = $cart->cartItems; if (!$items) { continue; } $goodss = $xml->createElement('Товары'); $sum = 0; foreach ($items as $cartitem) { $goods = $goodss->appendChild($xml->createElement('Товар')); $id1c = \App::$cur->migrations->findParse($cartitem->price->offer->item_id, 'Ecommerce\\Item'); if ($id1c) { addToXml($xml, $goods, 'Ид', $id1c->parse_id); } addToXml($xml, $goods, 'Наименование', $cartitem->item->name); $one = addToXml($xml, $goods, 'БазоваяЕдиница', 'шт'); $one->setAttribute("Код", "796"); $one->setAttribute("НаименованиеПолное", "Штука"); $one->setAttribute("МеждународноеСокращение", "PCE"); addToXml($xml, $goods, 'ЦенаЗаЕдиницу', $cartitem->final_price); addToXml($xml, $goods, 'Количество', $cartitem->count); addToXml($xml, $goods, 'Сумма', $cartitem->final_price * $cartitem->count); $sum += $cartitem->final_price * $cartitem->count; $reqs = $goods->appendChild($xml->createElement('ЗначенияРеквизитов')); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'ВидНоменклатуры'); addToXml($xml, $req, 'Значение', 'Товар'); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'ТипНоменклатуры'); addToXml($xml, $req, 'Значение', 'Товар'); } foreach ($cart->extras as $extra) { $goods = $goodss->appendChild($xml->createElement('Товар')); addToXml($xml, $goods, 'Наименование', $extra->name); $one = addToXml($xml, $goods, 'БазоваяЕдиница', 'шт'); $one->setAttribute("Код", "796"); $one->setAttribute("НаименованиеПолное", "Штука"); $one->setAttribute("МеждународноеСокращение", "PCE"); addToXml($xml, $goods, 'ЦенаЗаЕдиницу', $extra->price); addToXml($xml, $goods, 'Количество', $extra->count); addToXml($xml, $goods, 'Сумма', $extra->price * $extra->count); $reqs = $goods->appendChild($xml->createElement('ЗначенияРеквизитов')); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'ВидНоменклатуры'); addToXml($xml, $req, 'Значение', 'Товар'); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'ТипНоменклатуры'); addToXml($xml, $req, 'Значение', 'Товар'); } if ($cart->delivery && $cart->delivery->price && $sum < $cart->delivery->max_cart_price) { $sum += $cart->delivery->price; $goods = $goodss->appendChild($xml->createElement('Товар')); addToXml($xml, $goods, 'Наименование', 'Доставка'); $one = addToXml($xml, $goods, 'БазоваяЕдиница', 'шт'); $one->setAttribute("Код", "796"); $one->setAttribute("НаименованиеПолное", "Штука"); $one->setAttribute("МеждународноеСокращение", "PCE"); addToXml($xml, $goods, 'ЦенаЗаЕдиницу', $cart->delivery->price); addToXml($xml, $goods, 'Количество', 1); addToXml($xml, $goods, 'Сумма', $cart->delivery->price); $reqs = $goods->appendChild($xml->createElement('ЗначенияРеквизитов')); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'ВидНоменклатуры'); addToXml($xml, $req, 'Значение', 'Услуга'); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'ТипНоменклатуры'); addToXml($xml, $req, 'Значение', 'Услуга'); } addToXml($xml, $doc, 'Ид', $cart->id); addToXml($xml, $doc, 'Номер', $cart->id); addToXml($xml, $doc, 'Дата', $statusDateTime->format('Y-m-d')); addToXml($xml, $doc, 'ХозОперация', 'Заказ товара'); addToXml($xml, $doc, 'Роль', 'Продавец'); addToXml($xml, $doc, 'Валюта', 'руб'); addToXml($xml, $doc, 'Курс', '1'); addToXml($xml, $doc, 'Сумма', $sum); $agents = $doc->appendChild($xml->createElement('Контрагенты')); $agent = $agents->appendChild($xml->createElement('Контрагент')); $user = $cart->user; addToXml($xml, $agent, 'Ид', $user->id); addToXml($xml, $agent, 'ИдРодителя', $user->parent_id); addToXml($xml, $agent, 'Наименование', $user->name()); addToXml($xml, $agent, 'Роль', $user->role->name); addToXml($xml, $agent, 'ПолноеНаименование', $user->name()); $reg = $agent->appendChild($xml->createElement('АдресРегистрации')); addToXml($xml, $reg, 'Представление', ''); $presents = $agent->appendChild($xml->createElement('Представители')); $present = $presents->appendChild($xml->createElement('Представитель')); $presentAgent = $present->appendChild($xml->createElement('Контрагент')); addToXml($xml, $presentAgent, 'Отношение', 'Контактное лицо'); addToXml($xml, $presentAgent, 'Ид', $user->id); addToXml($xml, $presentAgent, 'Наименование', $user->name()); addToXml($xml, $doc, 'Время', $statusDateTime->format('H:i:s')); addToXml($xml, $doc, 'Комментарий', $cart->comment); $goodss = $doc->appendChild($goodss); $reqs = $doc->appendChild($xml->createElement('ЗначенияРеквизитов')); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'Метод оплаты'); if ($cart->payType) { addToXml($xml, $req, 'Значение', $cart->payType->name); } else { addToXml($xml, $req, 'Значение', 'Наличный расчет'); } $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'Заказ оплачен'); addToXml($xml, $req, 'Значение', $cart->payed ? 'true' : 'false'); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'Доставка разрешена'); addToXml($xml, $req, 'Значение', $cart->delivery ? 'true' : 'false'); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'Отменен'); addToXml($xml, $req, 'Значение', 'false'); if (!empty(\App::$primary->exchange1c->config['queryCartFieldGroups'])) { $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); foreach (\App::$primary->exchange1c->config['queryCartFieldGroups'] as $group) { addToXml($xml, $req, 'Наименование', $group['name']); $string = ''; foreach ($group['parts'] as $part) { switch ($part['type']) { case 'text': $string .= $part['text']; break; case 'field': $value = \Ecommerce\Cart\Info::get([['useradds_field_id', $part['field']], ['cart_id', $cart->id]]); $string .= $value->value; break; } } addToXml($xml, $req, 'Значение', $string); } } foreach ($cart->infos as $value) { $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', $value->name); addToXml($xml, $req, 'Значение', $value->value); } $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'Статус заказа'); addToXml($xml, $req, 'Значение', $cart->status->name); $req = $reqs->appendChild($xml->createElement('ЗначениеРеквизита')); addToXml($xml, $req, 'Наименование', 'Дата изменения статуса'); addToXml($xml, $req, 'Значение', $statusDateTime->format('Y-m-d H:i:s')); $doc = $root->appendChild($doc); } echo $xml->saveXML(); $this->end(); }
public function parseOptions($options = []) { $selectOptions = ['where' => !empty($options['where']) ? $options['where'] : [], 'distinct' => false, 'join' => [], 'order' => [], 'start' => isset($options['start']) ? (int) $options['start'] : 0, 'key' => isset($options['key']) ? $options['key'] : null, 'limit' => !empty($options['count']) ? (int) $options['count'] : 0]; if (!empty($options['sort']) && is_array($options['sort'])) { foreach ($options['sort'] as $col => $direction) { switch ($col) { case 'price': $selectOptions['order'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', strtolower($direction) == 'desc' ? 'desc' : 'asc']; break; case 'name': $selectOptions['order'][] = ['name', strtolower($direction) == 'desc' ? 'desc' : 'asc']; break; case 'sales': $selectOptions['order'][] = ['sales', strtolower($direction) == 'desc' ? 'desc' : 'asc']; break; case 'weight': $selectOptions['order'][] = ['weight', strtolower($direction) == 'desc' ? 'desc' : 'asc']; break; } } } $selectOptions['where'][] = ['deleted', 0]; if (empty($this->config['view_empty_image'])) { $selectOptions['where'][] = ['image_file_id', 0, '!=']; } $selectOptions['join'][] = [Ecommerce\Item\Offer::table(), Ecommerce\Item::index() . ' = ' . Ecommerce\Item\Offer::colPrefix() . Ecommerce\Item::index(), 'inner']; $selectOptions['join'][] = [Ecommerce\Item\Offer\Price::table(), Ecommerce\Item\Offer::index() . ' = ' . Ecommerce\Item\Offer\Price::colPrefix() . Ecommerce\Item\Offer::index() . (empty($this->config['show_zero_price']) ? ' and ' . Ecommerce\Item\Offer\Price::colPrefix() . 'price>0' : ''), empty($this->config['show_without_price']) ? 'inner' : 'left']; $selectOptions['join'][] = [Ecommerce\Item\Offer\Price\Type::table(), Ecommerce\Item\Offer\Price::colPrefix() . Ecommerce\Item\Offer\Price\Type::index() . ' = ' . Ecommerce\Item\Offer\Price\Type::index()]; $selectOptions['where'][] = [[Ecommerce\Item\Offer\Price\Type::index(), NULL, 'is'], [[Ecommerce\Item\Offer\Price\Type::colPrefix() . 'roles', '', '=', 'OR'], [Ecommerce\Item\Offer\Price\Type::colPrefix() . 'roles', '%|' . \Users\User::$cur->role_id . '|%', 'LIKE', 'OR']]]; if (!empty($this->config['view_filter'])) { if (!empty($this->config['view_filter']['options'])) { foreach ($this->config['view_filter']['options'] as $optionId => $optionValue) { $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value = "' . (int) $optionValue . '"', 'inner', 'option' . $optionId]; } } } //filters if (!empty($options['filters'])) { foreach ($options['filters'] as $col => $filter) { switch ($col) { case 'price': if (!empty($filter['min'])) { $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (double) $filter['min'], '>=']; } if (!empty($filter['max'])) { $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (double) $filter['max'], '<=']; } break; case 'options': foreach ($filter as $optionId => $optionValue) { $optionId = (int) $optionId; $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value = ' . \App::$cur->db->connection->pdo->quote($optionValue) . '', 'inner', 'option' . $optionId]; } break; case 'offerOptions': //$selectOptions['join'][] = [Ecommerce\Item\Offer::table(), Ecommerce\Item::index() . ' = offer.' . Ecommerce\Item\Offer::colPrefix() . Ecommerce\Item::index(), 'left', 'offer']; foreach ($filter as $optionId => $optionValue) { $optionId = (int) $optionId; if (is_array($optionValue)) { $optionValueArr = []; foreach ($optionValue as $val) { $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val); } $qstr = 'IN (' . implode(',', $optionValueArr) . ')'; } else { $qstr = '= ' . \App::$cur->db->connection->pdo->quote($optionValue); } $selectOptions['join'][] = [Ecommerce\Item\Offer\Param::table(), Ecommerce\Item\Offer::index() . ' = ' . 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer::index() . ' AND ' . 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer\Option::index() . ' = "' . (int) $optionId . '" AND ' . 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . 'value ' . $qstr, 'inner', 'offerOption' . $optionId]; } break; } } } //parents if (!empty($options['parent']) && strpos($options['parent'], ',') !== false) { $first = true; $where = []; foreach (explode(',', $options['parent']) as $categoryId) { if (!$categoryId) { continue; } $category = \Ecommerce\Category::get($categoryId); $where[] = ['tree_path', $category->tree_path . (int) $categoryId . '/%', 'LIKE', $first ? 'AND' : 'OR']; $first = false; } $selectOptions['where'][] = $where; } elseif (!empty($options['parent'])) { $category = \Ecommerce\Category::get($options['parent']); $selectOptions['where'][] = ['tree_path', $category->tree_path . (int) $options['parent'] . '/%', 'LIKE']; } //search if (!empty($options['search'])) { $searchStr = preg_replace('![^A-zА-я0-9 ]!iSu', ' ', $options['search']); $searchArr = []; foreach (explode(' ', $searchStr) as $part) { $part = trim($part); if ($part && strlen($part) > 2) { $searchArr[] = ['search_index', '%' . $part . '%', 'LIKE']; } } if (!empty($searchArr)) { $selectOptions['where'][] = $searchArr; } } if (empty($this->config['view_empty_warehouse'])) { $warehouseIds = []; if (class_exists('Geography\\City\\Data')) { $warehouses = \Geography\City\Data::get([['code', 'warehouses'], ['city_id', \Geography\City::$cur->id]]); if ($warehouses && $warehouses->data) { foreach (explode(',', $warehouses->data) as $id) { $warehouseIds[$id] = $id; } } } $selectOptions['where'][] = ['( (SELECT COALESCE(sum(`' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . 'count`),0) FROM ' . \App::$cur->db->table_prefix . \Ecommerce\Item\Offer\Warehouse::table() . ' iciw WHERE iciw.' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . \Ecommerce\Item\Offer::index() . ' = ' . \Ecommerce\Item\Offer::index() . ' ' . ($warehouseIds ? ' AND iciw.' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . \Ecommerce\Warehouse::index() . ' IN(' . implode(',', $warehouseIds) . ')' : '') . ' ) - (SELECT COALESCE(sum(' . \Ecommerce\Warehouse\Block::colPrefix() . 'count) ,0) FROM ' . \App::$cur->db->table_prefix . \Ecommerce\Warehouse\Block::table() . ' iewb inner JOIN ' . \App::$cur->db->table_prefix . \Ecommerce\Cart::table() . ' icc ON icc.' . \Ecommerce\Cart::index() . ' = iewb.' . \Ecommerce\Warehouse\Block::colPrefix() . \Ecommerce\Cart::index() . ' AND ( (`' . \Ecommerce\Cart::colPrefix() . 'warehouse_block` = 1 and `' . \Ecommerce\Cart::colPrefix() . 'cart_status_id` in(2,3,6)) || (`' . \Ecommerce\Cart::colPrefix() . \Ecommerce\Cart\Status::index() . '` in(0,1) and `' . \Ecommerce\Cart::colPrefix() . 'date_last_activ` >=subdate(now(),INTERVAL 30 MINUTE)) ) WHERE iewb.' . \Ecommerce\Warehouse\Block::colPrefix() . \Ecommerce\Item\Offer::index() . ' = ' . \Ecommerce\Item\Offer::index() . ') )', 0, '>']; } $selectOptions['group'] = Ecommerce\Item::index(); return $selectOptions; }
public function refillAction($id = 0) { $cart = \Ecommerce\Cart::get((int) $id); if ($cart->user_id != Users\User::$cur->id) { Tools::redirect('/', 'Это не ваша корзина'); } if (!empty($_SESSION['cart']['cart_id'])) { unset($_SESSION['cart']['cart_id']); } $newCart = $this->ecommerce->getCurCart(); foreach ($cart->cartItems as $cartitem) { $newCart->addItem($cartitem->item_offer_price_id, $cartitem->count); } $newCart->save(); Tools::redirect('/ecommerce/cart/'); }