function fn_get_ebay_orders() { $success_orders = $failed_orders = array(); setlocale(LC_TIME, 'en_US'); $params = array('OrderStatus' => 'Completed'); $last_transaction = db_get_field('SELECT timestamp FROM ?:ebay_cached_transactions WHERE type = ?s AND status = ?s ORDER BY timestamp DESC', 'orders', 'C'); // Need user_id if (!empty($last_transaction)) { $params['CreateTimeFrom'] = gmstrftime("%Y-%m-%dT%H:%M:%S", $last_transaction); $params['CreateTimeTo'] = gmstrftime("%Y-%m-%dT%H:%M:%S", TIME); } $data = array('timestamp' => TIME, 'user_id' => $_SESSION['auth']['user_id'], 'session_id' => Session::getId(), 'status' => 'A', 'type' => 'orders', 'result' => '', 'site_id' => 0); $transaction_id = db_query('INSERT INTO ?:ebay_cached_transactions ?e', $data); list(, $ebay_orders) = Ebay::instance()->GetOrders($params); $data = array('status' => 'C', 'result' => count($ebay_orders)); db_query('UPDATE ?:ebay_cached_transactions SET ?u WHERE transaction_id = ?i', $data, $transaction_id); if (!empty($ebay_orders)) { foreach ($ebay_orders as $k => $v) { $item_transactions = $v['TransactionArray']; $cart = $products = array(); if (!is_array($item_transactions)) { $item_transactions = array($item_transactions->Transaction); } $i = 1; foreach ($item_transactions as $item) { $email = (string) $item->Buyer->Email; break; } $shipping_address = $v['ShippingAddress']; $customer_name = explode(' ', (string) $shipping_address->Name); $firstname = array_shift($customer_name); $lastname = implode(' ', $customer_name); $cart = array('user_id' => 0, 'company_id' => Registry::get('runtime.company_id'), 'email' => $email, 'ebay_order_id' => $v['OrderID'], 'status' => 'P', 'timestamp' => strtotime($v['CreatedTime']), 'payment_id' => 0, 'user_data' => array('firstname' => $firstname, 'lastname' => $lastname, 'phone' => (string) $shipping_address->Phone, 's_firstname' => $firstname, 's_lastname' => $lastname, 's_address' => (string) $shipping_address->Street1, 's_city' => (string) $shipping_address->CityName, 's_state' => (string) $shipping_address->StateOrProvince, 's_country' => (string) $shipping_address->Country, 's_phone' => (string) $shipping_address->Phone, 's_zipcode' => (string) $shipping_address->PostalCode, 'b_firstname' => $firstname, 'b_lastname' => $lastname, 'b_address' => (string) $shipping_address->Street1, 'b_city' => (string) $shipping_address->CityName, 'b_state' => (string) $shipping_address->StateOrProvince, 'b_country' => (string) $shipping_address->Country, 'b_phone' => (string) $shipping_address->Phone, 'b_zipcode' => (string) $shipping_address->PostalCode), 'total' => $v['Total'], 'subtotal' => $v['Subtotal'], 'shipping_cost' => (double) $v['ShippingServiceSelected']->ShippingServiceCost); foreach ($item_transactions as $item) { $_item = (array) $item->Item; $product_id = db_get_field('SELECT product_id FROM ?:ebay_template_products WHERE ebay_item_id = ?i', $_item['ItemID']); // Need check company_id if (!$product_id) { continue; } $product = fn_get_product_data($product_id, $cart['user_data']); $extra = array("product_options" => array()); $options = db_get_array('SELECT ?:product_options.option_id, ?:product_options_descriptions.option_name, ?:product_option_variants_descriptions.variant_id, ?:product_option_variants_descriptions.variant_name FROM ?:product_options JOIN ?:product_option_variants ON ?:product_option_variants.option_id = ?:product_options.option_id JOIN ?:product_options_descriptions ON ?:product_options_descriptions.option_id = ?:product_options.option_id JOIN ?:product_option_variants_descriptions ON ?:product_option_variants_descriptions.variant_id = ?:product_option_variants.variant_id WHERE product_id =?i', $product_id); if (isset($item->Variation)) { $variations_xml = (array) $item->Variation->VariationSpecifics; if (isset($variations_xml['NameValueList']->Name)) { $variations = (array) $variations_xml['NameValueList']; } else { foreach ($variations_xml['NameValueList'] as $variation) { $variations[] = (array) $variation; } } if (isset($variations)) { if (isset($variations['Name'])) { foreach ($options as $option) { if ($variations['Name'] == $option['option_name'] && $variations['Value'] == $option['variant_name']) { $extra['product_options'][$option['option_id']] = $option['variant_id']; } } } else { foreach ($variations as $variation) { foreach ($options as $option) { if ($variation['Name'] == $option['option_name'] && $variation['Value'] == $option['variant_name']) { $extra['product_options'][$option['option_id']] = $option['variant_id']; } } } } $variations = array(); } } $products[$i] = array('product_id' => $product_id, 'amount' => (int) $item->QuantityPurchased, 'price' => (double) $item->TransactionPrice, 'base_price' => (double) $item->TransactionPrice, 'is_edp' => $product['is_edp'], 'edp_shipping' => $product['edp_shipping'], 'free_shipping' => $product['free_shipping'], 'stored_price' => 'Y', 'company_id' => Registry::get('runtime.company_id'), 'extra' => $extra); unset($product); $i += 1; } if (empty($products)) { continue; } $cart['products'] = $products; unset($products); $location = fn_get_customer_location($cart['user_data'], $cart); $cart['product_groups'] = Shippings::groupProductsList($cart['products'], $location); list($order_id, $status) = fn_update_order($cart); if (!empty($order_id)) { fn_change_order_status($order_id, 'P', $status, fn_get_notification_rules(array(), false)); $success_orders[] = $order_id; } else { $failed_orders[] = $cart['ebay_order_id']; } } } return array($success_orders, $failed_orders); }
if (isset($template_data['site_id'])) { Ebay::instance()->site_id = $template_data['site_id']; } // [Page sections] Registry::set('navigation.tabs', array('detailed' => array('title' => __('general'), 'js' => true), 'shippings' => array('title' => __('shippings'), 'js' => true), 'payments' => array('title' => __('payments'), 'js' => true), 'returnPolicy' => array('title' => __('return_policy'), 'js' => true))); // [/Page sections] $ebay_root_categories = fn_get_ebay_categories(0); Tygh::$app['view']->assign('ebay_root_categories', $ebay_root_categories); Tygh::$app['view']->assign('template_data', $template_data); } elseif ($mode == 'update') { $template_data = fn_get_ebay_template($_REQUEST['template_id']); if (isset($_REQUEST['site_id'])) { $template_data['site_id'] = $_REQUEST['site_id']; } if (isset($template_data['site_id'])) { Ebay::instance()->site_id = $template_data['site_id']; } // [Page sections] Registry::set('navigation.tabs', array('detailed' => array('title' => __('general'), 'js' => true), 'shippings' => array('title' => __('shippings'), 'js' => true), 'payments' => array('title' => __('payments'), 'js' => true), 'returnPolicy' => array('title' => __('return_policy'), 'js' => true))); // [/Page sections] $ebay_root_categories = fn_get_ebay_categories(0); Tygh::$app['view']->assign('ebay_root_categories', $ebay_root_categories); Tygh::$app['view']->assign('template_data', $template_data); } elseif ($mode == 'get_subcategories') { $subcategories = array(); if (!empty($_REQUEST['parent_id'])) { $subcategories = fn_get_ebay_categories($_REQUEST['parent_id'], true); } Tygh::$app['view']->assign('ebay_categories', $subcategories); Tygh::$app['view']->assign('data_id', $_REQUEST['data_id']); Tygh::$app['view']->assign('required_field', $_REQUEST['required_field']);
function fn_register_ebay_shippings($site_id = 0) { $data = array('timestamp' => TIME, 'user_id' => $_SESSION['auth']['user_id'], 'session_id' => Session::getId(), 'status' => 'A', 'type' => 'shippings', 'result' => '', 'site_id' => $site_id); $transaction_id = db_query('INSERT INTO ?:ebay_cached_transactions ?e', $data); list(, $shippings) = Ebay::instance()->GetEbayDetails('ShippingServiceDetails'); if (!empty($shippings)) { db_query('DELETE FROM ?:ebay_shippings WHERE site_id = ?i', $site_id); $data = array(); foreach ($shippings as $shipping) { if (isset($shipping['ValidForSellingFlow']) && $shipping['ValidForSellingFlow'] == 'true') { $data[] = array('service_id' => isset($shipping['ShippingServiceID']) ? $shipping['ShippingServiceID'] : '', 'name' => isset($shipping['ShippingService']) ? $shipping['ShippingService'] : '', 'description' => isset($shipping['Description']) ? $shipping['Description'] : '', 'service_type' => isset($shipping['ServiceType']) ? is_array($shipping['ServiceType']) ? implode(',', $shipping['ServiceType']) : $shipping['ServiceType'] : '', 'is_international' => isset($shipping['InternationalService']) && $shipping['InternationalService'] == 'true' ? 'Y' : 'N', 'category' => isset($shipping['ShippingCategory']) ? $shipping['ShippingCategory'] : '', 'ship_days_max' => isset($shipping['ShippingTimeMax']) ? $shipping['ShippingTimeMax'] : '', 'ship_days_min' => isset($shipping['ShippingTimeMin']) ? $shipping['ShippingTimeMin'] : '', 'package' => isset($shipping['ShippingPackage']) ? is_array($shipping['ShippingPackage']) ? implode(',', $shipping['ShippingPackage']) : $shipping['ShippingPackage'] : '', 'carrier' => isset($shipping['ShippingCarrier']) ? $shipping['ShippingCarrier'] : '', 'weight_required' => isset($shipping['WeightRequired']) && $shipping['WeightRequired'] == 'true' ? 'Y' : 'N', 'selling_flow' => 'Y', 'dimensions_required' => isset($shipping['DimensionsRequired']) && $shipping['DimensionsRequired'] == 'true' ? 'Y' : 'N', 'surcharge_applicable' => isset($shipping['SurchargeApplicable']) && $shipping['SurchargeApplicable'] == 'true' ? 'Y' : 'N', 'expedited_service' => isset($shipping['ExpeditedService']) && $shipping['ExpeditedService'] == 'true' ? 'Y' : 'N', 'detail_version' => isset($shipping['DetailVersion']) ? $shipping['DetailVersion'] : '', 'update_timestamp' => isset($shipping['UpdateTime']) ? strtotime($shipping['UpdateTime']) : '', 'site_id' => $site_id); } } if (!empty($data)) { db_query('INSERT INTO ?:ebay_shippings ?m', $data); } $_data = array('status' => 'C', 'result' => count($data)); db_query('UPDATE ?:ebay_cached_transactions SET ?u WHERE transaction_id = ?i', $_data, $transaction_id); } return true; }