/** */ function attribute_add() { if (main()->is_post()) { if (empty($_POST['title'])) { _re('Title is required'); } if (empty($_POST['value_list'])) { _re('Values list is required'); } if (!common()->_error_exists()) { $value_list = []; foreach ((array) explode("\n", $_POST['value_list']) as $val) { $v = trim($val); if ($v != '') { $value_list[$v] = $v; } } db()->INSERT('shop_productparams', db()->es(['title' => $_POST['title']])); $insert_id = db()->insert_id(); foreach ($value_list as $val) { // insert new db()->INSERT('shop_productparams_options', ['productparams_id' => $insert_id, 'title' => $val]); } common()->admin_wall_add(['shop product attribute added: ' . $_POST['title'], $insert_id]); return js_redirect('./?object=' . main()->_get('object') . '&action=attributes'); } } $form_fields = ['name', 'type', 'value_list', 'default_value', 'order', 'comment']; $replace = array_fill_keys($form_fields, ''); $replace = my_array_merge($replace, ['form_action' => './?object=' . main()->_get('object') . '&action=' . $_GET['action'] . '&id=' . $_GET['id'], 'error' => _e(), 'back_url' => './?object=' . main()->_get('object') . '&action=attributes', 'active' => 1]); return form($replace)->text('title')->textarea('value_list')->save_and_back(); }
/** * Order step */ function _order_step_delivery($FORCE_DISPLAY_FORM = false) { // Validate previous form if (main()->is_post() && !$FORCE_DISPLAY_FORM) { module('shop')->_order_validate_delivery(); // Display next form if we have no errors if (!common()->_error_exists()) { return module('shop')->_order_step_select_payment(true); } } if (main()->USER_ID) { $order_info = module('shop')->_user_info; } // Fill fields foreach ((array) module('shop')->_b_fields as $_field) { $replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[substr($_field, 2)]); } // Fill shipping from billing foreach ((array) module('shop')->_s_fields as $_field) { if (module('shop')->_user_info["shipping_same"] && !isset($_POST[$_field])) { $s_field = "b_" . substr($_field, 2); $replace[$_field] = _prepare_html(isset($_POST[$s_field]) ? $_POST[$s_field] : module('shop')->_user_info[$s_field]); } else { $replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[$_field]); } } $force_ship_type = module('shop')->FORCE_GROUP_SHIP[module('shop')->USER_GROUP]; $SELF_METHOD_ID = substr(__FUNCTION__, strlen("_order_step_")); $replace = my_array_merge((array) $replace, ["form_action" => "./?object=shop&action=" . $_GET["action"] . "&id=" . $SELF_METHOD_ID, "error_message" => _e(), "ship_type_box" => module('shop')->_box("ship_type", $force_ship_type ? $force_ship_type : $_POST["ship_type"]), "back_link" => "./?object=shop&action=order", "cats_block" => module('shop')->_categories_show()]); return tpl()->parse("shop/order_delivery", $replace); }
public function test_complex() { $to_merge_1 = ['auth_user' => ['EXEC_AFTER_LOGIN' => [['_add_login_activity']]], 'send_mail' => ['USE_MAILER' => 'phpmailer'], 'tpl' => ['ALLOW_LANG_BASED_STPLS' => 1, 'CUSTOM_META_INFO' => 1], 'graphics' => ['META_KEYWORDS' => 'keyword2', 'META_DESCRIPTION' => 'description2', 'EMBED_CSS' => 0], 'i18n' => ['REPLACE_UNDERSCORE' => 1]]; $to_merge_2 = ['main' => ['USE_CUSTOM_ERRORS' => 1, 'STATIC_PAGES_ROUTE_TOP' => 1], 'auth_user' => ['URL_SUCCESS_LOGIN' => './?object=account', 'EXEC_AFTER_LOGIN' => [['_add_login_activity']]], 'graphics' => ['CSS_ADD_RESET' => 1], 'debug_info' => ['_SHOW_NOT_TRANSLATED' => 1, '_SHOW_I18N_VARS' => 1], 'rewrite' => ['_rewrite_add_extension' => '/'], 'comments' => ['USE_TREE_MODE' => 1], 'register' => ['NICK_ALLOWED_SYMBOLS' => ['а-я', 'a-z', '0-9', '_', '\\-', '@', '#', ' ']], 'validate' => ['NICK_ALLOWED_SYMBOLS' => ['а-я', 'a-z', '0-9', '_', '\\-', '@', '#', ' ']], 'bb_codes' => ['SMILIES_DIR' => 'uploads/forum/smilies/']]; $merged = ['send_mail' => ['USE_MAILER' => 'phpmailer'], 'tpl' => ['ALLOW_LANG_BASED_STPLS' => 1, 'CUSTOM_META_INFO' => 1], 'i18n' => ['REPLACE_UNDERSCORE' => 1], 'main' => ['USE_CUSTOM_ERRORS' => 1, 'STATIC_PAGES_ROUTE_TOP' => 1], 'debug_info' => ['_SHOW_NOT_TRANSLATED' => 1, '_SHOW_I18N_VARS' => 1], 'rewrite' => ['_rewrite_add_extension' => '/'], 'comments' => ['USE_TREE_MODE' => 1], 'register' => ['NICK_ALLOWED_SYMBOLS' => [0 => 'а-я', 1 => 'a-z', 2 => '0-9', 3 => '_', 4 => '\\-', 5 => '@', 6 => '#', 7 => ' ']], 'validate' => ['NICK_ALLOWED_SYMBOLS' => [0 => 'а-я', 1 => 'a-z', 2 => '0-9', 3 => '_', 4 => '\\-', 5 => '@', 6 => '#', 7 => ' ']], 'bb_codes' => ['SMILIES_DIR' => 'uploads/forum/smilies/'], 'auth_user' => ['URL_SUCCESS_LOGIN' => './?object=account', 'EXEC_AFTER_LOGIN' => [0 => [0 => '_add_login_activity']]], 'graphics' => ['META_KEYWORDS' => 'keyword2', 'META_DESCRIPTION' => 'description2', 'EMBED_CSS' => 0, 'CSS_ADD_RESET' => 1]]; $this->assertEquals(my_array_merge((array) $to_merge_1, $to_merge_2), $merged); }
/** * Order step */ function _order_step_finish($FORCE_DISPLAY_FORM = false) { module('shop')->_basket_api()->clean(); if (isset($_GET["page"])) { $_GET["id"] = intval($_GET["page"]); unset($_GET["page"]); } $_GET["id"] = intval($_GET["id"]); if ($_GET["id"]) { $order_info = db()->query_fetch("SELECT * FROM " . db('shop_orders') . " WHERE id=" . intval($_GET["id"]) . " AND user_id=" . intval(main()->USER_ID)); } if (empty($order_info)) { return _e("No such order"); } $products_ids = []; $Q = db()->query("SELECT * FROM " . db('shop_order_items') . " WHERE `order_id`=" . intval($order_info["id"])); while ($_info = db()->fetch_assoc($Q)) { if ($_info["product_id"]) { $products_ids[$_info["product_id"]] = $_info["product_id"]; } $order_items[$_info["product_id"]] = $_info; } if (!empty($products_ids)) { $products_infos = db()->query_fetch_all("SELECT * FROM " . db('shop_products') . " WHERE id IN(" . implode(",", $products_ids) . ") AND active='1'"); $products_atts = module('shop')->_products_get_attributes($products_ids); } foreach ((array) $order_items as $_info) { $_product_id = $_info["product_id"]; $_product = $products_infos[$_product_id]; $price = $_info["sum"]; $dynamic_atts = []; if (strlen($_info["attributes"]) > 3) { foreach ((array) unserialize($_info["attributes"]) as $_attr_id) { $_attr_info = $products_atts[$_info["product_id"]][$_attr_id]; $dynamic_atts[$_attr_id] = "- " . $_attr_info["name"] . " " . $_attr_info["value"]; $price += $_attr_info["price"]; } } $URL_PRODUCT_ID = module('shop')->_product_id_url($_product); $products[$_info["product_id"]] = ["name" => _prepare_html($_product["name"]), "price" => module('shop')->_format_price($price), "sum" => module('shop')->_format_price($_info["sum"]), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => intval($_info["quantity"]), "details_link" => process_url("./?object=shop&action=product_details&id=" . $URL_PRODUCT_ID), "dynamic_atts" => !empty($dynamic_atts) ? implode("\n<br />", $dynamic_atts) : "", "cat_name" => _prepare_html(module('shop')->_shop_cats[$_product["cat_id"]]), "cat_url" => process_url("./?object=shop&action=products_show&id=" . module('shop')->_shop_cats_all[$_product["cat_id"]]['url'])]; $total_price += $price * $quantity; } $total_price = $order_info["total_sum"]; if (main()->USER_ID) { $order_info = my_array_merge(module('shop')->_user_info, $order_info); } else { $order_info["email"] = $order_info["email"]; $order_info["phone"] = $order_info["phone"]; } $order_info = my_array_merge(module('shop')->COMPANY_INFO, $order_info); $replace2 = my_array_merge($order_info, ["id" => $_GET["id"], "products" => $products, "ship_cost" => module('shop')->_format_price(0), "total_cost" => module('shop')->_format_price($total_price), "password" => ""]); // Prepare email template $message = tpl()->parse("shop/invoice_email", $replace2); common()->quick_send_mail($order_info["email"], "invoice #" . $_GET["id"], $message); $replace = my_array_merge($replace2, ["error_message" => _e(), "products" => $products, "ship_price" => module('shop')->_format_price(module('shop')->_ship_types_names[$order_info["ship_type"]]), "total_price" => module('shop')->_format_price($total_price), "order_no" => str_pad($order_info["id"], 8, "0", STR_PAD_LEFT), "hash" => _prepare_html($order_info["hash"]), "back_link" => "./?object=shop&action=show", "cats_block" => module('shop')->_categories_show()]); return tpl()->parse("shop/order_finish", $replace); }
/** * Edit user var */ function user_var_edit() { $_GET['id'] = intval($_GET['id']); $A = db()->query_fetch('SELECT * FROM ' . db('locale_user_tr') . ' WHERE id=' . intval($_GET['id'])); if (!$A) { return _e('No id'); } if (main()->is_post()) { db()->UPDATE('locale_user_tr', ['name' => _es($_POST['name']), 'translation' => _es($_POST['translation']), 'last_update' => time()], 'id=' . intval($_GET['id'])); return js_redirect('./?object=' . $_GET['object'] . '&action=user_vars'); } $DATA = my_array_merge($A, $_POST); $replace = ['form_action' => './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . ($_GET['id'] ? '&id=' . $_GET['id'] : ''), 'back_url' => process_url('./?object=' . $_GET['object'] . '&action=user_vars'), 'error' => _e(), 'for_edit' => 1, 'id' => _prepare_html($DATA['id']), 'user_id' => _prepare_html($DATA['user_id']), 'name' => _prepare_html($DATA['name']), 'translation' => _prepare_html($DATA['translation']), 'locale' => _prepare_html($DATA['locale']), 'site_id' => _prepare_html($DATA['site_id'])]; return tpl()->parse($_GET['object'] . '/user_vars_edit', $replace); }
/** * view orders */ function _order_view() { if ($_POST["order_id"]) { $_GET["id"] = intval($_POST["order_id"]); } else { $_GET["id"] = intval($_GET["id"]); } if ($_GET["id"]) { $order_info = db()->query_fetch("SELECT * FROM " . db('shop_orders') . " WHERE id=" . intval($_GET["id"])); } if (empty($order_info)) { return _e("No such order"); } if (!empty($_POST["status"])) { db()->UPDATE(db('shop_orders'), ["status" => _es($_POST["status"])], "id=" . intval($_GET["id"])); return js_redirect("./?object=shop&action=orders"); } $products_ids = []; $Q = db()->query("SELECT * FROM " . db('shop_order_items') . " WHERE `order_id`=" . intval($order_info["id"])); while ($_info = db()->fetch_assoc($Q)) { if ($_info["product_id"]) { $products_ids[$_info["product_id"]] = $_info["product_id"]; } $order_items[$_info["product_id"]] = $_info; } if (!empty($products_ids)) { $products_infos = db()->query_fetch_all("SELECT * FROM " . db('shop_products') . " WHERE id IN(" . implode(",", $products_ids) . ") AND active='1'"); $products_atts = module('shop')->_products_get_attributes($products_ids); } foreach ((array) $order_items as $_info) { $_product = $products_infos[$_info["product_id"]]; $dynamic_atts = []; if (strlen($_info["attributes"]) > 3) { foreach ((array) unserialize($_info["attributes"]) as $_attr_id) { $_attr_info = $products_atts[$_info["product_id"]][$_attr_id]; $dynamic_atts[$_attr_id] = "- " . $_attr_info["name"] . " " . $_attr_info["value"]; $price += $_attr_info["price"]; } } $products[$_info["product_id"]] = ["name" => _prepare_html($_product["name"]), "price" => module('shop')->_format_price($_info["sum"]), "currency" => _prepare_html(module('shop')->CURRENCY), "quantity" => intval($_info["quantity"]), "details_link" => process_url("./?object=shop&action=view&id=" . $_product["id"]), "dynamic_atts" => !empty($dynamic_atts) ? implode("\n<br />", $dynamic_atts) : ""]; $total_price += $_info["price"] * $quantity; } $total_price = $order_info["total_sum"]; $replace = my_array_merge($replace, _prepare_html($order_info)); $replace = my_array_merge($replace, ["form_action" => "./?object=shop&action=" . $_GET["action"] . "&id=" . $_GET["id"], "order_id" => $order_info["id"], "total_sum" => module('shop')->_format_price($order_info["total_sum"]), "user_link" => _profile_link($order_info["user_id"]), "user_name" => _display_name(user($order_info["user_id"])), "error_message" => _e(), "products" => (array) $products, "total_price" => module('shop')->_format_price($total_price), "ship_type" => module('shop')->_ship_type[$order_info["ship_type"]], "pay_type" => module('shop')->_pay_types[$order_info["pay_type"]], "date" => _format_date($order_info["date"], "long"), "status_box" => module('shop')->_statuses[$order_info["status"]], "back_url" => "./?object=shop&action=orders"]); return tpl()->parse("shop/order_view", $replace); }
/** */ function view_order() { $_GET['id'] = intval($_GET['id']); if ($_GET['id']) { if ($this->SUPPLIER_ID) { $sql = 'SELECT o.* FROM ' . db('shop_orders') . ' AS o INNER JOIN ' . db('shop_order_items') . ' AS i ON i.order_id = o.id INNER JOIN ' . db('shop_products') . ' AS p ON i.product_id = p.id INNER JOIN ' . db('shop_admin_to_supplier') . ' AS m ON m.supplier_id = p.supplier_id WHERE o.id=' . intval($_GET['id']) . ' AND m.admin_id=' . intval(main()->ADMIN_ID) . ' GROUP BY o.id'; } else { $sql = 'SELECT * FROM ' . db('shop_orders') . ' WHERE id=' . intval($_GET['id']); } $order_info = db()->query_fetch($sql); } if (empty($order_info)) { return _e('No such order'); } $recount_price = false; $_class_price = _class('_shop_price', 'modules/shop/'); $_class_units = _class('_shop_product_units', 'modules/shop/'); $_class_basket = _class('shop_basket', 'modules/shop/'); if (main()->is_post()) { module('manage_shop')->_product_check_first_revision('order', intval($_GET['id'])); $order_id = (int) $_GET['id']; foreach ($_POST as $k => $v) { if ($k == 'status_item') { foreach ($v as $k1 => $status) { list($product_id, $param_id) = explode('_', $k1); db()->UPDATE(db('shop_order_items'), ['status' => $status], ' order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id)); } } elseif ($k == 'delete') { foreach ($v as $k1 => $is_del) { list($product_id, $param_id) = explode('_', $k1); if ($is_del == 1) { db()->query('DELETE FROM ' . db('shop_order_items') . ' WHERE order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id)); } } $recount_price = true; } elseif ($k == 'qty') { foreach ($v as $k1 => $qty) { list($product_id, $param_id) = explode('_', $k1); if (intval($qty) == 0) { db()->query('DELETE FROM ' . db('shop_order_items') . ' WHERE order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id)); } else { db()->UPDATE(db('shop_order_items'), ['quantity' => intval($qty)], ' order_id=' . $_GET['id'] . ' AND product_id=' . intval($product_id) . ' AND param_id=' . intval($param_id)); } $recount_price = true; } } elseif ($k == 'unit') { foreach ($v as $k1 => $unit) { $unit = (int) $unit; list($product_id, $param_id) = explode('_', $k1); $product_id = (int) $product_id; $param_id = (int) $param_id; if ($unit > 0) { $units = $_class_units->get_by_product_ids($product_id); if (isset($units[$product_id][$unit])) { db()->UPDATE(db('shop_order_items'), ['unit' => $unit], ' order_id=' . $order_id . ' AND product_id=' . $product_id . ' AND param_id=' . $param_id); $products = db_get_all('SELECT * FROM ' . db('shop_products') . ' WHERE id = ' . $product_id); $product = $products[$product_id]; list($price) = $_class_price->markup_down($product['price'], $product_id); $item = ['price' => $price, 'unit' => $unit, 'units' => $units[$product_id]]; $price_one = $_class_basket->_get_price_one($item); $item = ['order_id' => $order_id, 'product_id' => $product_id, 'param_id' => $param_id]; $item_price = $item + ['price' => $price_one]; $this->_item_update_price_unit($item_price); $recount_price = true; } } } } elseif ($k == 'price_unit') { foreach ($v as $k1 => $price) { list($product_id, $param_id) = explode('_', $k1); $this->_item_update_price_unit(['price' => $price, 'order_id' => $order_id, 'product_id' => (int) $product_id, 'param_id' => (int) $param_id]); $recount_price = true; } } } $sql = []; foreach (['address', 'phone', 'address', 'house', 'apartment', 'floor', 'porch', 'intercom', 'delivery_price', 'status', 'region', 'discount', 'discount_add', 'delivery_type', 'delivery_id', 'delivery_location'] as $f) { if (isset($_POST[$f])) { $sql[$f] = $_POST[$f]; if ($f == 'delivery_price' && $_POST['delivery_price'] != $order_info['delivery_price']) { $sql['is_manual_delivery_price'] = 1; $order_info['is_manual_delivery_price'] = 1; $order_info['delivery_price'] = $sql['delivery_price']; $recount_price = true; } if ($f == 'discount') { $discount = $_class_price->_number_mysql($sql['discount']); $order_info['discount'] = $discount; $sql['discount'] = $discount; $recount_price = true; } if ($f == 'discount_add') { $discount = $_class_price->_number_mysql($sql['discount_add']); $order_info['discount_add'] = $discount; $sql['discount_add'] = $discount; } if ($f == 'delivery_id') { $value = (int) $sql[$f]; $value = $value > 0 ? $value : $order_info[$f]; $sql[$f] = $value; } if ($f == 'delivery_type') { $value = (int) $sql[$f]; $order_info['payment'] = $value; $sql['payment'] = $value; } } } if (count($sql) > 0) { db()->update_safe(db('shop_orders'), $sql, 'id=' . intval($_GET['id'])); } if ($recount_price) { list($order_info['total_sum'], $order_info['delivery_price']) = $this->_order_recount_price($order_info['id'], $order_info); } module('manage_shop')->_order_add_revision('edit', intval($_GET['id'])); return js_redirect('./?object=' . main()->_get('object') . '&action=view_order&id=' . $order_info['id']); } $products_ids = []; $Q = db()->query('SELECT * FROM ' . db('shop_order_items') . ' WHERE `order_id`=' . intval($order_info['id'])); while ($_info = db()->fetch_assoc($Q)) { if ($_info['product_id']) { $products_ids[$_info['product_id']] = $_info['product_id']; } $order_items[$_info['product_id'] . "_" . $_info['param_id']] = $_info; } if (!empty($products_ids)) { $products_infos = db()->query_fetch_all('SELECT * FROM ' . db('shop_products') . ' WHERE id IN(' . implode(',', $products_ids) . ')'); $products_atts = module('manage_shop')->_get_products_attributes($products_ids); } $price_total = 0; foreach ((array) $order_items as $_info) { $_product = $products_infos[$_info['product_id']]; $_units = []; if (intval($_info['type']) == 1) { $images[0]['thumb'] = _class('_shop_products', 'modules/shop/')->_product_set_image($_info["product_id"], $_product['cat_id'], 'thumb', false); $link = './?object=' . main()->_get('object') . '&action=product_set_edit&id=' . $_info['product_id']; } else { $images = _class('_shop_products', 'modules/shop/')->_product_image($_info["product_id"], false, false); $link = './?object=' . main()->_get('object') . '&action=product_edit&id=' . $_info['product_id']; $_units = $_class_units->get_by_product_ids($_info['product_id']); } $image = $images[0]['thumb'] ?: _class('_shop_categories', 'modules/shop/')->get_icon_url($_product['cat_id'], 'item'); $dynamic_atts = []; if (strlen($_info['attributes']) > 3) { foreach ((array) unserialize($_info['attributes']) as $_attr_id) { $_attr_info = $products_atts[$_info['product_id']][$_attr_id]; $dynamic_atts[$_attr_id] = '- ' . $_attr_info['name'] . ' ' . $_attr_info['value']; $price += $_attr_info['price']; } } $product_id = (int) $_info['product_id']; $param_id = (int) $_info['param_id']; $price_one = tofloat($_info['price']); $quantity = (int) $_info['quantity']; $price_item = $price_one * $quantity; // product unit $unit = (int) $_info['unit']; $units = null; $unit_name = 'шт.'; if ($_units[$product_id]) { $units = $_units[$product_id]; $units[$unit] && ($unit_name = $units[$unit]['title']); } $products[$_info['product_id'] . '_' . $_info['param_id']] = ['product_id' => intval($_info['product_id']), 'param_id' => intval($_info['param_id']), 'param_name' => _class('_shop_product_params', 'modules/shop/')->_get_name_by_option_id($_info['param_id']), 'name' => _prepare_html($_product['name']), 'image' => $image, 'link' => $link, 'unit' => $unit, 'unit_name' => $unit_name, 'units' => $units, 'price_unit' => $price_one, 'price' => $price_item, 'currency' => _prepare_html(module('manage_shop')->CURRENCY), 'quantity' => intval($_info['quantity']), 'details_link' => process_url('./?object=' . main()->_get('object') . '&action=view&id=' . $_product['id']), 'dynamic_atts' => !empty($dynamic_atts) ? implode('<br />' . PHP_EOL, $dynamic_atts) : '', 'status' => module('manage_shop')->_box('status_item', $_info['status']), 'delete' => '']; $price_total += $price_item; } // discount $discount = $order_info['discount']; $discount_add = $order_info['discount_add']; $_discount = $discount; $discount_price = $_class_price->apply_price($price_total, $_discount); $discount_price -= $price_total; $discount_price = $_class_price->_number_round($discount_price); $_discount = $discount_add; $discount_add_price = $_class_price->apply_price($price_total, $_discount); $discount_add_price -= $price_total; $total_price = tofloat($order_info['total_sum']); $replace = my_array_merge($replace, _prepare_html($order_info)); $replace = my_array_merge($replace, ['form_action' => './?object=' . main()->_get('object') . '&action=' . $_GET['action'] . '&id=' . $_GET['id'], 'order_id' => $order_info['id'], 'price_total_info' => module('manage_shop')->_format_price($price_total), 'discount' => $_class_price->_number_format($discount), 'discount_add' => $_class_price->_number_format($discount_add), 'discount_price_info' => $_class_price->_price_format($discount_price), 'discount_add_price_info' => $_class_price->_price_format($discount_add_price), 'delivery_info' => module('manage_shop')->_format_price($order_info['delivery_price']), 'total_sum' => module('manage_shop')->_format_price($total_price), 'user_link' => _profile_link($order_info['user_id']), 'user_name' => _display_name(user($order_info['user_id'])), 'error_message' => _e(), 'products' => (array) $products, 'total_price' => module('manage_shop')->_format_price($total_price), 'ship_type' => module('manage_shop')->_ship_types[$order_info['ship_type']], 'pay_type' => module('manage_shop')->_pay_types[$order_info['pay_type']], 'date' => $order_info['date'], 'status_box' => module('manage_shop')->_box('status', $order_info['status']), 'back_url' => './?object=' . main()->_get('object') . '&action=show_orders', 'print_url' => './?object=' . main()->_get('object') . '&action=show_print&id=' . $order_info['id'], 'payment' => common()->get_static_conf('payment_methods', $order_info['payment'])]); $link_invoice = './?object=manage_shop&action=invoice&id=' . $replace['id']; $link_invoice_add = $link_invoice . '&with_discount_add=y'; $link_pdf_invoice = $link_invoice . '&pdf=y'; $link_pdf_invoice_add = $link_invoice_add . '&pdf=y'; $region = _class('_shop_region', 'modules/shop/')->_get_list(); array_unshift($region, '- регион не выбран -'); $out = form2($replace, ['dd_mode' => 1, 'big_labels' => true])->info('id')->info('price_total_info', ['desc' => 'Сумма'])->row_start(['desc' => 'Скидка, %'])->number('discount', ['desc' => 'Скидка, %'])->info('discount_price_info')->link('Invoice', $link_invoice, ['title' => 'Накладная без учета добавочной скидки', 'icon' => 'fa fa-file-o', 'target' => '_blank'])->link('PDF', $link_pdf_invoice, ['title' => 'Накладная PDF без учета добавочной скидки', 'icon' => 'fa fa-file-text-o', 'target' => '_blank'])->row_end()->row_start(['desc' => 'Скидка добавочная, %'])->number('discount_add', ['desc' => 'Скидка добавочная, %'])->info('discount_add_price_info', ['desc' => ' '])->link(t('Invoice') . '+', $link_invoice_add, ['title' => 'Накладная с учетом добавочной скидки', 'icon' => 'fa fa-file-o', 'target' => '_blank'])->link(t('PDF') . '+', $link_pdf_invoice_add, ['title' => 'Накладная PDF с учетом добавочной скидки', 'icon' => 'fa fa-file-text-o', 'target' => '_blank'])->row_end()->info('delivery_info', ['desc' => 'Доставка'])->info('total_sum', '', ['desc' => 'Итоговая сумма', 'tip' => 'Итоговая сумма без учета добавочной скидки', 'no_escape' => 1])->info_date('date', ['format' => 'full'])->info('name')->email('email')->info('phone')->container('<a href="./?object=' . main()->_get('object') . '&action=send_sms&phone=' . urlencode($replace["phone"]) . '" class="btn">Send SMS</a><br /><br />')->select_box('region', $region, ['desc' => 'Регион доставки', 'class_add_wrapper' => 'region_type_wrap'])->select_box('delivery_type', _class('_shop_delivery', 'modules/shop/')->_get_types(), ['desc' => 'Тип доставки', 'class_add_wrapper' => 'delivery_type_wrap'])->select_box('delivery_id', _class('_shop_delivery', 'modules/shop/')->_get_locations_by_type($replace['delivery_type']), ['class' => 'delivery_id', 'class_add_wrapper' => 'delivery_id_wrap', 'desc' => 'Отделение'])->text('delivery_location', 'Отделение доставки', ['class' => 'delivery_location', 'class_add_wrapper' => 'delivery_location_wrap'])->text('address')->text('house')->text('apartment')->text('floor')->text('porch')->text('intercom')->info('comment')->text('delivery_time')->price('delivery_price')->user_info('user_id')->info('payment', 'Payment method')->info('transaction_id', 'Transaction id')->container(table2($products)->image('product_id', ['width' => '50px', 'no_link' => true, 'web_path' => '', 'img_path_check' => false, 'img_path_callback' => function ($_p1, $_p2, $row) { return $row['image']; }])->func('link', function ($f, $p, $row) { $result = "<a class='btn' href='{$row[link]}'>{$row[product_id]}</a>"; return $result; })->func('name', function ($f, $p, $row) { $row['name'] = $row['name'] . ($row['param_name'] != '' ? "<br /><small>" . $row['param_name'] . "</small>" : ''); return $row['name']; })->func('unit', function ($f, $p, $row) { $values = []; if (!empty($row['units'])) { $values[0] = ' - '; foreach ($row['units'] as $id => $item) { $values[$id] = $item['title']; } } $desc = 'Ед. измерения'; $width = '7em'; $result = sprintf(' <style> .unit_current { width: %s; } </style> <div class="unit_current"> %s <span class="btn btn-mini unit_change"> <i class="icon-edit fa fa-edit"></i> </span> </div> ', $width, $row['unit_name']) . _class('html')->select2_box(['desc' => $desc, 'name' => 'unit[' . $row['product_id'] . '_' . $row['param_id'] . ']', 'values' => $values, 'js_options' => ['width' => $width, 'containerCssClass' => 'select2_box']]); return $result; })->func('quantity', function ($f, $p, $row) { $row['quantity'] = "<input type='text' name='qty[" . $row['product_id'] . "_" . $row['param_id'] . "]' value='" . intval($row['quantity']) . "' style='width:50px;'>"; return $row['quantity']; })->func('price_unit', function ($f, $p, $row) { $row['price_unit'] = "<input type='text' name='price_unit[" . $row['product_id'] . "_" . $row['param_id'] . "]' value='" . $row['price_unit'] . "' style='width:100px;'>"; return $row['price_unit']; })->text('price')->func('status', function ($f, $p, $row) { $row['status'] = str_replace("status_item", "status_item[" . $row['product_id'] . "_" . $row['param_id'] . "]", $row['status']); return $row['status']; })->func('delete', function ($f, $p, $row) { $row['delete'] = "<input type='checkbox' name='delete[" . $row['product_id'] . "_" . $row['param_id'] . "]' value='1'>"; return $row['delete']; }), ['wide' => 1])->container(tpl()->parse('manage_shop/product_search_order', ['order_id' => $_GET['id']]), 'Add product')->box('status_box', 'Status order', ['selected' => $order_info['status']])->save_and_back(); // misc handlers css(' .select2_box { display: none; } .unit_current { position : relative; } .btn.unit_change { display : none; position : absolute; right : 0; } '); jquery(' $(".delivery_id").on( "change", function( event ) { var location = $(this).find( "option:selected" ).text(); $(".delivery_location").val( location ); }); var delivery_type__on_change = function( target ) { var value = +$(target).find( "option:selected" ).val(); if( value == 1 ) { $(".delivery_id_wrap").hide(); $(".delivery_location_wrap").hide(); } else if( value == 2 ) { var count = +$(".delivery_id_wrap").find( "option" ).length; if( count > 1 ) { $(".delivery_id_wrap").show(); $(".delivery_location_wrap").show(); } } } delivery_type__on_change( $(".delivery_type_wrap") ); $(".delivery_type_wrap").on( "change", function( event ) { delivery_type__on_change( event.target ); }); $( ".unit_change" ).on( "click", function( event ) { var $this = $( this ); var $select2 = $this.parent().next(); $select2.toggle() }).each( function( i ) { var $this = $( this ); if( $this.parent().next().length ) { $this.show(); } }); '); // get similar orders $sql = "SELECT o.*, COUNT(*) AS num_items FROM `" . db('shop_orders') . "` AS `o`\n\t\t\t\tINNER JOIN " . db('shop_order_items') . " AS i ON i.order_id = o.id\n\t\t\t\tWHERE `o`.`id`!='" . $order_info['id'] . "'\n\t\t\t\t\tAND `o`.`phone`='" . $order_info['phone'] . "'\n\t\t\t\t\tAND `o`.`status`='" . $order_info['status'] . "'\n\t\t\t\tGROUP BY o.id ORDER BY o.id DESC"; $out .= "<br /><br /><h3>" . t('Similar orders') . "</h3>" . table($sql)->text('id')->date('date', ['format' => 'full', 'nowrap' => 1])->user('user_id')->text('name')->text('phone')->text('total_sum', ['nowrap' => 1])->text('num_items')->btn_edit('', './?object=' . main()->_get('object') . '&action=view_order&id=%d', ['no_ajax' => 1])->btn('Merge', './?object=' . main()->_get('object') . '&action=merge_order&id=' . $order_info['id'] . '&merge_id=%d', ['no_ajax' => 1]); // $out .= tpl()->parse('manage_shop/product_search',array()); return $out; }
{ foreach ((array) $a2 as $k => $v) { if (isset($a1[$k]) && is_array($a1[$k])) { if (is_array($a2[$k])) { foreach ((array) $a2[$k] as $k2 => $v2) { if (isset($a1[$k][$k1]) && is_array($a1[$k][$k1])) { $a1[$k][$k2] += $v2; } else { $a1[$k][$k2] = $v2; } } } else { $a1[$k] += $v; } } else { $a1[$k] = $v; } } return $a1; } } $PROJECT_CONF = my_array_merge((array) $PROJECT_CONF, ['main' => ['USE_CUSTOM_ERRORS' => 1, 'STATIC_PAGES_ROUTE_TOP' => 1], 'auth_user' => ['URL_SUCCESS_LOGIN' => './?object=account', 'EXEC_AFTER_LOGIN' => [['_add_login_activity']]], 'send_mail' => ['USE_MAILER' => 'phpmailer'], 'tpl' => ['ALLOW_LANG_BASED_STPLS' => 1], 'graphics' => [], 'i18n' => ['TRACK_TRANSLATED' => 1], 'rewrite' => ['_rewrite_add_extension' => '/'], 'comments' => ['USE_TREE_MODE' => 1], 'logs' => ['_LOGGING' => 1, 'STORE_USER_AUTH' => 1, 'UPDATE_LAST_LOGIN' => 1]]); $OVERRIDE_CONF_FILE = dirname(__DIR__) . '/.dev/override_conf_after.php'; if (file_exists($OVERRIDE_CONF_FILE)) { include_once $OVERRIDE_CONF_FILE; } // Load auto-configured file $AUTO_CONF_FILE = __DIR__ . '/_auto_conf.php'; if (file_exists($AUTO_CONF_FILE)) { @eval('?>' . file_get_contents($AUTO_CONF_FILE)); }
/** * Order payment method by authorize.net */ function _order_pay_authorize_net($params = []) { $order_info = $params["order_info"]; $params = $params["params"]; $PAY_METHOD_ID = 2; $PAY_METHOD_PARAMS = module('shop')->_pay_method_params[$PAY_METHOD_ID]; $amount = $order_info["total_sum"]; $description = $params["DESCRIPTION"] ? $params["DESCRIPTION"] : $PAY_METHOD_PARAMS["DESCRIPTION"]; $login_id = $PAY_METHOD_PARAMS["LOGIN_ID"]; $transaction_key = $PAY_METHOD_PARAMS["TRANSACTION_KEY"]; $TEST_MODE = $PAY_METHOD_PARAMS["TEST_MODE"] ? "true" : "false"; $IN_PRODUCTION = $PAY_METHOD_PARAMS["IN_PRODUCTION"]; // By default, this sample code is designed to post to our test server for // developer accounts: https://test.authorize.net/gateway/transact.dll // for real accounts (even in test mode), please make sure that you are // posting to: https://secure.authorize.net/gateway/transact.dll // Useful for debugging: // $url = "https://developer.authorize.net/param_dump.asp"; if ($IN_PRODUCTION) { $url = "https://secure.authorize.net/gateway/transact.dll"; } else { $url = "https://test.authorize.net/gateway/transact.dll"; } // an invoice is generated using the date and time $invoice = date("YmdHis"); // a sequence number is randomly generated $sequence = rand(1, 1000); // a timestamp is generated $time_stamp = time(); // The following lines generate the SIM fingerprint. PHP versions 5.1.2 and // newer have the necessary hmac function built in. For older versions, it // will try to use the mhash library. if (phpversion() >= '5.1.2') { $fingerprint = hash_hmac("md5", $login_id . "^" . $sequence . "^" . $time_stamp . "^" . $amount . "^", $transaction_key); } else { $fingerprint = bin2hex(mhash(MHASH_MD5, $login_id . "^" . $sequence . "^" . $time_stamp . "^" . $amount . "^", $transaction_key)); } // Required authorise.net fields $_fields_and_values = ["x_login" => substr($login_id, 0, 20), "x_amount" => substr($amount, 0, 15), "x_description" => substr($description, 0, 255), "x_invoice_num" => substr($invoice, 0, 128), "x_fp_sequence" => $sequence, "x_fp_timestamp" => $time_stamp, "x_fp_hash" => $fingerprint, "x_test_request" => $TEST_MODE, "x_delim_char" => '|', "x_delim_data" => 'TRUE', "x_version" => '3.1', "x_relay_response" => "FALSE"]; // Test mode only if ($TEST_MODE) { $_fields_and_values = my_array_merge($_fields_and_values, ["x_card_num" => "370000000000002", "x_exp_date" => "1220"]); } $_order_fields_values = ["x_cust_id" => substr($order_info["user_id"], 0, 20), "x_customer_ip" => substr($_SERVER["REMOTE_ADDR"], 0, 20), "x_card_num" => substr($order_info["card_num"], 0, 50), "x_exp_date" => substr($order_info["exp_date"], 0, 4), "x_first_name" => substr($order_info["b_first_name"], 0, 50), "x_last_name" => substr($order_info["b_last_name"], 0, 50), "x_address" => substr($order_info["b_address"], 0, 60), "x_city" => substr($order_info["b_city"], 0, 40), "x_state" => substr($order_info["b_state"], 0, 40), "x_zip" => substr($order_info["b_zip_code"], 0, 20), "x_country" => substr($order_info["b_country"], 0, 60), "x_phone" => substr($order_info["b_phone"], 0, 25), "x_company" => substr($order_info["b_company"], 0, 50), "x_email" => substr($order_info["b_email"], 0, 255), "x_ship_to_first_name" => substr($order_info["s_first_name"], 0, 50), "x_ship_to_last_name" => substr($order_info["s_last_name"], 0, 50), "x_ship_to_address" => substr($order_info["s_address"], 0, 60), "x_ship_to_city" => substr($order_info["s_city"], 0, 40), "x_ship_to_state" => substr($order_info["s_state"], 0, 40), "x_ship_to_zip" => substr($order_info["s_zip_code"], 0, 20), "x_ship_to_country" => substr($order_info["s_country"], 0, 60), "x_ship_to_company" => substr($order_info["s_company"], 0, 50)]; $_fields_and_values = my_array_merge($_fields_and_values, $_order_fields_values); $_data_to_post = []; foreach ((array) $_fields_and_values as $k => $v) { $_data_to_post[$k] = $k . '=' . urlencode(str_replace('|', '', $v)); } $_data_to_post = implode("&", $_data_to_post); db()->UPDATE(db('shop_orders'), ["status" => "pending payment"], "id=" . intval($order_info['id'])); // Try to post data $ch = curl_init(); if ($ch) { curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, process_url("./?object=shop&action=" . $_GET["action"] . "&id=" . $_GET["id"])); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $_data_to_post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($error) { trigger_error("SHOP: authorize.net response error: " . $error, E_USER_WARNING); return _e("SHOP: Payment gateway error #1. Please <a href='" . process_url("./?object=support") . "'>contact</a> site admin"); } } else { return _e("SHOP: Payment gateway error #2. Please <a href='" . process_url("./?object=support") . "'>contact</a> site admin"); } // Sample good response: // 1,1,1,This transaction has been approved.,Ms6s3z,P,2148412154,20090317055427,Shop Description Here,32.95,CC,auth_capture,14,fixit,fixit,,fixit 78,fixit,fixit,12345,,,,,fixit,fixit,,fixit 78,fixit,fixit,12345,,,,,,,2E9E8E7E6236B4344F9985FDE9E6522E,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,, $gateway_response = explode('|', $response); // Even though authorize.net is told to return the data delimited with the pipe character, // many times it will return data comma-delimited. if (count($gateway_response) < 5) { $gateway_response = explode(',', $response); } // If the response code is not 1 (approved) then redirect back to the payment page // with the appropriate error message if ($gateway_response[0] != '1') { trigger_error("SHOP: authorize.net not approved: " . $response, E_USER_WARNING); return _e("SHOP: Payment gateway error #3. Please <a href='" . process_url("./?object=support") . "'>contact</a> site admin"); } else { db()->UPDATE(db('shop_orders'), ["status" => "processed"], "id=" . intval($order_info['id'])); } // Display order result $_GET["id"] = $order_info['id']; return module('shop')->_order_step_finish(); }
$zip->add_file(file_get_contents(ROOT_PATH . $row['goods_img']), $row['goods_img']); } } if (EC_CHARSET == 'utf-8') { $zip->add_file(ecs_iconv('UTF8', 'GB2312', $content), 'goods_list.csv'); } else { $zip->add_file($content, 'goods_list.csv'); } header("Content-Disposition: attachment; filename=goods_list.zip"); header("Content-Type: application/unknown"); die($zip->file()); } elseif ($_REQUEST['act'] == 'import_paipai') { $smarty->display('import_paipai.htm'); } elseif ($_REQUEST['act'] == 'get_goods_fields') { $cat_id = isset($_REQUEST['cat_id']) ? intval($_REQUEST['cat_id']) : 0; $goods_fields = my_array_merge($_LANG['custom'], get_attributes($cat_id)); make_json_result($goods_fields); } elseif ($_REQUEST['act'] == 'act_export_custom') { /* 检查输出列 */ if (empty($_POST['custom_goods_export'])) { sys_msg($_LANG['custom_goods_field_not_null'], 1, array(), false); } /* 检查权限 */ admin_priv('goods_export'); include_once 'includes/cls_phpzip.php'; $zip = new PHPZip(); $where = get_export_where_sql($_POST); $sql = "SELECT g.*, b.brand_name as brandname " . " FROM " . $ecs->table('goods') . " AS g LEFT JOIN " . $ecs->table('brand') . " AS b " . "ON g.brand_id = b.brand_id" . $where; $res = $db->query($sql); $goods_fields = explode(',', $_POST['custom_goods_export']); $goods_field_name = set_goods_field_name($goods_fields, $_LANG['custom']);
<?php $PROJECT_CONF = my_array_merge($PROJECT_CONF, ['site_map' => [], 'send_mail' => ['USE_MAILER' => 'phpmailer', 'DEFAULT_CHARSET' => 'UTF-8', 'MAIL_DEBUG' => true, 'DEBUG_TEST_SEND_BULK' => true, 'DEBUG_TEST_ADDRESS' => '*****@*****.**']]); #$CONF['DEBUG_CONSOLE_POPUP' ] = 1; #$PROJECT_CONF['_shop_region']['ENABLE'] = true;
/** * 获取id levaeName对 * * 可适用于列表以及下拉列表 * * @return array */ public function getValueOptions($tree = NULL) { $tree = $tree ? $tree : $this->tree; $returnList = array(); foreach ($tree as $item) { $tmp = array(); $item[$this->fields[2]] = $this->getLevelName($item[$this->fields[0]]); $tmp[$item[$this->fields[0]]] = array_unset_key($item, 'child'); $returnList = my_array_merge($returnList, $tmp); if (isset($item['child']) && $item['child']) { $childList = $this->getValueOptions($item['child']); $returnList = my_array_merge($returnList, $childList); } } return $returnList; }
/** */ public function load_data() { // Preload db installer SQL CREATE TABLE DDL statements $ext = '.sql.php'; $dir = 'share/db/sql/*' . $ext; $globs_sql = ['yf_main' => YF_PATH . $dir, 'yf_plugins' => YF_PATH . 'plugins/*/' . $dir, 'project_app' => APP_PATH . $dir, 'project_main' => PROJECT_PATH . $dir, 'project_plugins' => PROJECT_PATH . 'plugins/*/' . $dir, 'project_plugins_app' => APP_PATH . 'plugins/*/' . $dir]; $t_names = []; foreach ($globs_sql as $glob) { foreach (glob($glob) as $path) { $t_name = substr(basename($path), 0, -strlen($ext)); $t_names[$t_name] = $path; } } // Allow override in project foreach ($t_names as $t_name => $path) { $this->TABLES_SQL[$t_name] = (include $path); } // Preload db installer PHP array of CREATE TABLE DDL statements $ext = '.sql_php.php'; $dir = 'share/db/sql_php/*' . $ext; $globs_sql_php = ['yf_main' => YF_PATH . $dir, 'yf_plugins' => YF_PATH . 'plugins/*/' . $dir, 'project_app' => APP_PATH . $dir, 'project_main' => PROJECT_PATH . $dir, 'project_plugins' => PROJECT_PATH . 'plugins/*/' . $dir, 'project_plugins_app' => APP_PATH . 'plugins/*/' . $dir]; $t_names = []; foreach ($globs_sql_php as $glob) { foreach (glob($glob) as $path) { $t_name = substr(basename($path), 0, -strlen($ext)); $t_names[$t_name] = $path; } } // Allow override in project foreach ($t_names as $t_name => $path) { $this->TABLES_SQL_PHP[$t_name] = (include $path); } // Preload db installer data PHP arrays needed to be inserted after CREATE TABLE == initial data $ext = '.data.php'; $dir = 'share/db/data/*' . $ext; $globs_data = ['yf_main' => YF_PATH . $dir, 'yf_plugins' => YF_PATH . 'plugins/*/' . $dir, 'project_app' => APP_PATH . $dir, 'project_main' => PROJECT_PATH . $dir, 'project_plugins' => PROJECT_PATH . 'plugins/*/' . $dir, 'project_plugins_app' => APP_PATH . 'plugins/*/' . $dir]; $t_names = []; foreach ($globs_data as $glob) { foreach (glob($glob) as $path) { $t_name = substr(basename($path), 0, -strlen($ext)); $t_names[$t_name] = $path; } } // Allow override in project foreach ($t_names as $t_name => $path) { $this->TABLES_DATA[$t_name] = (include $path); } // Project has higher priority than framework (allow to change anything in project) // Try to load db structure from project file // Sample contents part: $project_data['OTHER_TABLES_STRUCTS'] = my_array_merge((array)$project_data['OTHER_TABLES_STRUCTS'], array( $structure_file = PROJECT_PATH . 'project_db_structure.php'; if (file_exists($structure_file)) { include_once $structure_file; } foreach ((array) $project_data as $cur_array_name => $_cur_data) { $this->{$cur_array_name} = my_array_merge((array) $this->{$cur_array_name}, (array) $_cur_data); } // Compatibility with old codebase foreach ((array) $this->SYS_TABLES_STRUCTS as $k => $v) { $this->TABLES_SQL[$k] = $v; } foreach ((array) $this->OTHER_TABLES_STRUCTS as $k => $v) { $this->TABLES_SQL[$k] = $v; } foreach ((array) $this->SYS_TABLES_DATAS as $k => $v) { $this->TABLES_DATA[$k] = $v; } foreach ((array) $this->OTHER_TABLES_DATAS as $k => $v) { $this->TABLES_DATA[$k] = $v; } }
function parse_rules() { if ($this->p_arr['rules_type'] > 1) { return; } //判断内置规则是列表采集还是直接文章详细页采集 $page_url = $this->r_arr['page_url']; $page_url_arr = explode('(*)', $page_url); $url_last_str = array_pop($page_url_arr); if (trim($this->p_arr['page_link_rules'])) { //填了列表规则就是从列表采集 $this->p_arr['url_range_type'] = 1; $this->max_level = 2; } else { $this->p_arr['url_range_type'] = 2; $this->max_level = 1; } foreach ((array) $this->p_arr['rules_var'] as $k => $v) { $value_arr = $this->get_var_set_value($v); $set_arr[$k] = $value_arr['set']; $type_arr[$k] = $value_arr['type']; } $i = 0; //重新构造数组的索引 foreach ((array) $page_url_arr as $k => $v) { $k = $k + 1; if (is_array($set_arr[$k])) { if ($type_arr[$k] == 'range') { //范围 $args['start'] = $set_arr[$k][0]; $args['end'] = $set_arr[$k][1]; $args['step'] = 1; $args['url'] = $v . '(*)'; //函数需要,临时给他安上 $url_arr[$i] = convert_url_range($args); } else { foreach ($set_arr[$k] as $k1 => $v1) { $url_arr[$i][$k1] = $v . $v1; } } } else { $url_arr[$i] = $v . $set_arr[$k]; } $i++; } array_push($url_arr, array($url_last_str)); //利用数组拼接成可以使用的url $new_url_arr = my_array_merge($url_arr); $this->temp_arr['page_num'] = count($new_url_arr); $this->now_url_arr = $new_url_arr; }