Пример #1
0
 					###r.l. $row = zen_db_fetch_array($result);
                     $row = $result->fields;
 					extract($row, EXTR_PREFIX_ALL, "opt");
 					$AddedOptionsPrice += $opt_options_values_price;
 					$option_value_details[$option_id][$option_value_id] = array ("options_values_price" => $opt_options_values_price);
 					$option_names[$option_id] = $opt_products_options_name;
 					$option_values_names[$option_value_id] = $opt_products_options_values_name;
 				}
 			} */
 // Get Product Info
 $InfoQuery = "select p.products_model,p.products_price,pd.products_name,p.products_tax_class_id from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on pd.products_id=p.products_id where p.products_id='{$add_product_products_id}'";
 $result = $db->Execute($InfoQuery);
 #$row = zen_db_fetch_array($result);
 extract($result->fields, EXTR_PREFIX_ALL, "p");
 // Following functions are defined at the bottom of this file
 $CountryID = zen_get_country_id($order->delivery["country"]);
 $ZoneID = zen_get_zone_id($CountryID, $order->delivery["state"]);
 $ProductsTax = zen_get_tax_rate($p_products_tax_class_id, $CountryID, $ZoneID);
 if ($_POST[applyspecialstoprice] && zen_get_products_special_price((int) $add_product_products_id)) {
     $product_price_woa = zen_get_products_special_price((int) $add_product_products_id);
 } else {
     $product_price_woa = $p_products_price;
 }
 $Query = "insert into " . TABLE_ORDERS_PRODUCTS . " set\n\t\t\t\torders_id = {$oID},\n\t\t\t\tproducts_id = {$add_product_products_id},\n\t\t\t\tproducts_model = '{$p_products_model}',\n\t\t\t\tproducts_name = '" . str_replace("'", "'", $p_products_name) . "',\n\t\t\t\tproducts_price = '{$product_price_woa}',\n\t\t\t\tfinal_price = '" . ($product_price_woa + $AddedOptionsPrice) . "',\n\t\t\t\tproducts_tax = '{$ProductsTax}',\n\t\t\t\tproducts_quantity = {$add_product_quantity},\n                                onetime_charges = {$AddedOptionsPrice_OneTime};";
 $db->Execute($Query);
 $new_product_id = zen_db_insert_id();
 //UPDATE_INVENTORY_QUANTITY_START##############################################################################################################
 if (STOCK_LIMITED == "true") {
     $db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = products_quantity - " . $add_product_quantity . ", products_ordered = products_ordered + " . $add_product_quantity . " where products_id = '" . $add_product_products_id . "'");
 } else {
     $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . $add_product_quantity . " where products_id = '" . $add_product_products_id . "'");
Пример #2
0
function zen_get_country_list($name, $selected = '', $parameters = '')
{
    if ($countries = zen_get_countries()) {
        $countries_array = array(array('id' => '', 'text' => tra('Please Choose Your Country')));
        for ($i = 0, $n = sizeof($countries); $i < $n; $i++) {
            $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
        }
        if (!empty($selected) && !is_numeric($selected)) {
            $selected = zen_get_country_id($selected);
        }
    }
    return zen_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
}
Пример #3
0
            } else {
                $optionValuesList[$optionValues[$_REQUEST['new_option_id']]['products_options_values_id']] = $optionValues[$_REQUEST['new_option_id']]['products_options_values_name'];
            }
            $gBitSmarty->loadPlugin('smarty_function_html_options');
            print smarty_function_html_options(array('options' => $optionValuesList, 'name' => 'newOrderOptionValue', 'class' => 'form-control', 'print_result' => FALSE), $gBitSmarty);
            print '<input class="btn btn-sm btn-primary" type="submit" value="save" name="save_new_option">';
        } else {
            print "<span class='alert alert-danger'>Unkown Option</span>";
        }
    } elseif (!empty($_REQUEST['address_type'])) {
        $addressType = $_REQUEST['address_type'];
        $entry = $order->{$addressType};
        if (isset($entry['country']['countries_id'])) {
            $countryId = $entry['country']['countries_id'];
        } elseif (is_string($entry['country'])) {
            $countryId = zen_get_country_id($entry['country']);
        } else {
            $countryId = NULL;
        }
        if (defined('ACCOUNT_STATE') && ACCOUNT_STATE == 'true') {
            $statePullDown = zen_draw_input_field('state', $entry['state']);
            $gBitSmarty->assign('statePullDown', $statePullDown);
        }
        $gBitSmarty->assign('countryPullDown', zen_get_country_list('country_id', $countryId));
        $gBitSmarty->assign_by_ref('address', $entry);
        $gBitSmarty->display('bitpackage:bitcommerce/order_address_edit.tpl');
    } else {
        print "<span class='alert alert-danger'>Empty Option</span>";
    }
    exit;
}
 function zen_get_tax_locations($store_country = -1, $store_zone = -1)
 {
     global $order;
     if (STORE_PRODUCT_TAX_BASIS != 'Store') {
         $_SESSION['customer_id'] = $order->customer['id'];
         if (STORE_PRODUCT_TAX_BASIS == 'Shipping') {
             $GLOBALS['customer_country_id'] = zen_get_country_id($GLOBALS['order']->delivery['country']);
             $GLOBALS['customer_zone_id'] = zen_get_zone_id($GLOBALS['customer_country_id'], $GLOBALS['order']->delivery['state']);
         } else {
             if (STORE_PRODUCT_TAX_BASIS == 'Billing') {
                 $GLOBALS['customer_country_id'] = zen_get_country_id($GLOBALS['order']->billing['country']);
                 $GLOBALS['customer_zone_id'] = zen_get_zone_id($GLOBALS['customer_country_id'], $GLOBALS['order']->billing['state']);
             }
         }
     }
     return array('zone_id' => $GLOBALS['customer_zone_id'], 'country_id' => $GLOBALS['customer_country_id']);
 }
Пример #5
0
function amazon_process_order($pAmazonOrderId)
{
    global $gAmazonMWS, $gBitUser, $gCommerceSystem, $gBitCustomer, $currencies, $order;
    $ret = NULL;
    $request = new MarketplaceWebServiceOrders_Model_GetOrderRequest();
    $request->setSellerId(MERCHANT_ID);
    // @TODO: set request. Action can be passed as MarketplaceWebServiceOrders_Model_GetOrderRequest
    // object or array of parameters
    // Set the list of AmazonOrderIds
    $orderIds = new MarketplaceWebServiceOrders_Model_OrderIdList();
    $orderIds->setId(array($pAmazonOrderId));
    $request->setAmazonOrderId($orderIds);
    $holdUser = $gBitUser;
    $azUser = new BitPermUser($holdUser->lookupHomepage($gCommerceSystem->getConfig('MODULE_PAYMENT_AMAZONMWS_LOCAL_USERNAME', 'amazonmws')));
    $azUser->load();
    $gBitUser = $azUser;
    $gBitCustomer = new CommerceCustomer($gBitUser->mUserId);
    $gBitCustomer->syncBitUser($gBitUser->mInfo);
    $_SESSION['customer_id'] = $gBitUser->mUserId;
    try {
        $response = $gAmazonMWS->getOrder($request);
        if ($response->isSetGetOrderResult()) {
            $getOrderResult = $response->getGetOrderResult();
            if ($getOrderResult->isSetOrders()) {
                $oldCwd = getcwd();
                chdir(BITCOMMERCE_PKG_PATH);
                $azOrderList = $getOrderResult->getOrders();
                if ($azOrders = $azOrderList->getOrder()) {
                    require_once BITCOMMERCE_PKG_PATH . 'classes/CommerceOrder.php';
                    $order = new order();
                    $order->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'subtotal' => 0, 'tax' => 0, 'total' => 0, 'tax_groups' => array(), 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'ip_address' => $_SERVER['REMOTE_ADDR']);
                    $azOrder = current($azOrders);
                    // Setup delivery address
                    if ($orderTotal = $azOrder->getOrderTotal()) {
                        $order->info['total'] = $orderTotal->getAmount();
                        $order->info['currency'] = $orderTotal->getCurrencyCode();
                        $order->info['currency_value'] = $currencies->currencies[$order->info['currency']]['currency_value'];
                    }
                    if ($shippingAddress = $azOrder->getShippingAddress()) {
                        $country = zen_get_countries(zen_get_country_id($shippingAddress->getCountryCode()), TRUE);
                        $zoneName = zen_get_zone_name_by_code($country['countries_id'], $shippingAddress->getStateOrRegion());
                        $order->delivery = array('firstname' => substr($shippingAddress->getName(), 0, strpos($shippingAddress->getName(), ' ')), 'lastname' => substr($shippingAddress->getName(), strpos($shippingAddress->getName(), ' ') + 1), 'company' => NULL, 'street_address' => $shippingAddress->getAddressLine1(), 'suburb' => trim($shippingAddress->getAddressLine2() . ' ' . $shippingAddress->getAddressLine3()), 'city' => $shippingAddress->getCity(), 'postcode' => $shippingAddress->getPostalCode(), 'state' => $zoneName, 'country' => $country, 'format_id' => $country['address_format_id'], 'telephone' => $shippingAddress->getPhone(), 'email_address' => NULL);
                        $order->customer = $order->delivery;
                        $order->billing = $order->delivery;
                    }
                    // Setup shipping
                    $shipping = array('cost' => 0);
                    switch ($azOrder->getShipServiceLevel()) {
                        case 'Std US Dom':
                            $shipping['id'] = 'usps_MEDIA';
                            $shipping['title'] = 'United States Postal Service (USPS Media Mail (1 - 2 Weeks))';
                            $shipping['code'] = 'USPSREG';
                            break;
                    }
                    $azOrderItems = amazon_mws_get_order_items($azOrder->getAmazonOrderId());
                    $azOrderItem = $azOrderItems->getOrderItem();
                    foreach ($azOrderItem as $azi) {
                        $testSku = $azi->getSellerSKU();
                        list($productsId, $attrString) = explode(':', $testSku, 2);
                        $productsKey = $productsId . ':ASIN-' . $azi->getASIN();
                        $order->contents[$productsKey] = $gBitCustomer->mCart->getProductHash($productsKey);
                        $order->contents[$productsKey]['products_quantity'] = $azi->getQuantityOrdered();
                        $order->contents[$productsKey]['products_name'] = $azi->getTitle();
                        if ($itemPrice = $azi->getItemPrice()) {
                            //							{$itemTax->getCurrencyCode()}
                            $order->contents[$productsKey]['price'] = $itemPrice->getAmount();
                            $order->contents[$productsKey]['final_price'] = $itemPrice->getAmount();
                        }
                        if ($itemTax = $azi->getItemTax()) {
                            //							{$itemTax->getCurrencyCode()}
                            $order->contents[$productsKey]['tax'] = $itemTax->getAmount();
                        }
                        if ($shippingPrice = $azi->getShippingPrice()) {
                            //							{$itemTax->getCurrencyCode()}
                            $order->info['shipping_cost'] = $shippingPrice->getAmount();
                        }
                        if (empty($attrString)) {
                            $attrString = $gCommerceSystem->getConfig('MODULE_PAYMENT_AMAZONMWS_DEFAULT_ATTRIBUTES');
                        }
                        // stock up the attributes
                        if ($attrString && ($attrs = explode(',', $attrString))) {
                            foreach ($attrs as $optionValueId) {
                                $optionId = $order->mDb->getOne("SELECT cpa.`products_options_id` FROM " . TABLE_PRODUCTS_ATTRIBUTES . " cpa WHERE cpa.`products_options_values_id`=?", array($optionValueId));
                                $order->contents[$productsKey]['attributes'][$optionId . '_' . $optionValueId] = $optionValueId;
                            }
                        }
                        if (!empty($order->contents[$productsKey]['attributes'])) {
                            $attributes = $order->contents[$productsKey]['attributes'];
                            $order->contents[$productsKey]['attributes'] = array();
                            $subindex = 0;
                            foreach ($attributes as $option => $value) {
                                $optionValues = zen_get_option_value(zen_get_options_id($option), (int) $value);
                                // Determine if attribute is a text attribute and change products array if it is.
                                if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
                                    $attr_value = $order->contents[$productsKey]['attributes_values'][$option];
                                } else {
                                    $attr_value = $optionValues['products_options_values_name'];
                                }
                                $order->contents[$productsKey]['attributes'][$subindex] = array('option' => $optionValues['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $optionValues['price_prefix'], 'price' => $optionValues['options_values_price']);
                                $subindex++;
                            }
                        }
                        $shown_price = zen_add_tax($order->contents[$productsKey]['final_price'], $order->contents[$productsKey]['tax']) * $order->contents[$productsKey]['products_quantity'] + zen_add_tax($order->contents[$productsKey]['onetime_charges'], $order->contents[$productsKey]['tax']);
                        $order->subtotal += $shown_price;
                        $products_tax = $order->contents[$productsKey]['tax'];
                        $products_tax_description = $order->contents[$productsKey]['tax_description'];
                        if (DISPLAY_PRICE_WITH_TAX == 'true') {
                            $order->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                            if (isset($order->info['tax_groups']["{$products_tax_description}"])) {
                                $order->info['tax_groups']["{$products_tax_description}"] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                            } else {
                                $order->info['tax_groups']["{$products_tax_description}"] = $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                            }
                        } else {
                            $order->info['tax'] += $products_tax / 100 * $shown_price;
                            if (isset($order->info['tax_groups']["{$products_tax_description}"])) {
                                $order->info['tax_groups']["{$products_tax_description}"] += $products_tax / 100 * $shown_price;
                            } else {
                                $order->info['tax_groups']["{$products_tax_description}"] = $products_tax / 100 * $shown_price;
                            }
                        }
                        $order->info['tax'] = zen_round($order->info['tax'], 2);
                        if ($azi->isSetShippingPrice()) {
                            $shippingPrice = $azi->getShippingPrice();
                            $shipping['cost'] += $shippingPrice->getAmount();
                        }
                    }
                    foreach (array('cc_type', 'cc_owner', 'cc_number', 'cc_expires', 'coupon_code') as $key) {
                        $order->info[$key] = NULL;
                    }
                    $order->info['shipping_method'] = $shipping['title'];
                    $order->info['shipping_method_code'] = $shipping['code'];
                    $order->info['shipping_module_code'] = $shipping['id'];
                    $order->info['payment_module_code'] = 'amazonmws';
                    $order->info['payment_method'] = 'Amazon Order';
                    $_SESSION['sendto'] = NULL;
                    $_SESSION['shipping'] = $shipping;
                    unset($_SESSION['cot_gv']);
                    require_once DIR_FS_CLASSES . 'order_total.php';
                    global $order_total_modules;
                    $order_total_modules = new order_total();
                    $order_totals = $order_total_modules->pre_confirmation_check();
                    require_once DIR_WS_MODULES . 'payment/amazonmws.php';
                    $amazon = new amazonmws($azOrder->getAmazonOrderId());
                    $amazonOutput = $amazon->process();
                    $order_totals = $order_total_modules->process();
                    array_splice($order_totals, count($order_totals) - 1, 0, array($amazonOutput));
                    if ($ordersId = $order->create($order_totals, 2)) {
                        $order->create_add_products($ordersId);
                        $ret = $ordersId;
                        $order->updateStatus(array('status' => MODULE_PAYMENT_AMAZONMWS_INITIAL_ORDER_STATUS_ID));
                    }
                }
                chdir($oldCwd);
            }
        }
    } catch (MarketplaceWebServiceOrders_Exception $ex) {
        echo "Caught Exception: " . $ex->getMessage() . "\n";
        echo "Response Status Code: " . $ex->getStatusCode() . "\n";
        echo "Error Code: " . $ex->getErrorCode() . "\n";
        echo "Error Type: " . $ex->getErrorType() . "\n";
        echo "Request ID: " . $ex->getRequestId() . "\n";
        echo "XML: " . $ex->getXML() . "\n";
    }
    $gBitUser = $holdUser;
    $gBitCustomer = new CommerceCustomer($gBitUser->mUserId);
    $_SESSION['customer_id'] = $gBitUser->mUserId;
    return $ret;
}