예제 #1
0
    if (isset($_SESSION['alipay_forcard_success_order_id'])) {
        $_order_id = $_SESSION['alipay_forcard_success_order_id'];
        $order->query($_order_id);
        $db->Execute('update ' . TABLE_ORDERS . ' set last_modified=now(), orders_status = ' . MODULE_PAYMENT_ALIPAYFOR_ORDER_STATUS_ID . ' where orders_id = ' . (int) $_order_id);
        $insert_id = $_order_id;
        unset($_SESSION['alipay_forcard_success_order_id']);
        if (isset($_SESSION['alipay_forcard_pending_order_id'])) {
            unset($_SESSION['alipay_forcard_pending_order_id']);
        }
        $order->send_order_email($insert_id, 2);
    } else {
        zen_redirect(zen_href_link(FILENAME_DEFAULT));
    }
} else {
    // create the order record
    $insert_id = $order->create($order_totals, 2);
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE');
    $payment_modules->after_order_create($insert_id);
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE');
    // store the product info to the order
    $order->create_add_products($insert_id);
    $_SESSION['order_number_created'] = $insert_id;
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS');
    //send email notifications
    $order->send_order_email($insert_id, 2);
}
$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL');
// clear slamming protection since payment was accepted
if (isset($_SESSION['payment_attempt'])) {
    unset($_SESSION['payment_attempt']);
}
예제 #2
0
            }
        }
    }
    //下单购买流程
    public function create()
    {
        echo '购买成功';
        $this->obServer('buy');
        // buy动作
    }
}
class orderEmail
{
    public static function update($order)
    {
        echo '发送购买成功一个邮件';
    }
}
class orderStatus
{
    public static function update($order)
    {
        echo '改变订单状态';
        //var_dump($order);
    }
}
$ob = new order();
$ob->addObServer('buy', 'orderEmail');
$ob->addObServer('buy', 'orderStatus');
$ob->create();
예제 #3
0
function orders_create($dishid, $input_data = array())
{
    global $tpl;
    if (!isset($input_data['quantity'])) {
        $input_data['quantity'] = 1;
        echo '<br>quantity not set!';
    }
    $existing = 0;
    if (isset($input_data['priority']) && $input_data['priority']) {
        $existing = order_find_incrementable($dishid, $input_data['priority']);
    }
    if ($existing) {
        // the order already exists, so updates the old one instead of creating a new identical
        $existing = (int) $existing;
        $ord = new order($existing);
        $data_old = $ord->data;
        $data_old['quantity'] = $data_old['quantity'] + $input_data['quantity'];
        if ($err = orders_update($data_old)) {
            return 0;
        }
        return $ord->id;
    }
    $ord = new order();
    $ord->prepare_default_array($dishid);
    if ($err = $ord->create()) {
        return 0;
    }
    // insert all the modules interfaces for order creation here
    toplist_insert($dishid, $input_data['quantity']);
    //don't move stock from here!
    if (class_exists('stock_object') && isset($input_data['quantity'])) {
        $stock = new stock_object();
        $stock->silent = true;
        $stock->remove_from_waiter($ord->id, $input_data['quantity']);
    }
    // end interfaces
    $ord->data['associated_id'] = $ord->id;
    $ord->data['quantity'] = $input_data['quantity'];
    if (isset($input_data['priority']) && $input_data['priority']) {
        $ord->data['priority'] = $input_data['priority'];
    }
    if ($dishid == SERVICE_ID) {
        $ord->data['priority'] = 0;
    }
    if ($err = $ord->set()) {
        return 0;
    }
    return $ord->id;
}
예제 #4
0
 /**
  * Получить заказ, который представляет текущую корзину товаров. Если такого заказа нет, то он будет создан
  * @return order заказ, который представляет корзину товаров
  */
 public function getBasketOrder($useDummyOrder = true)
 {
     static $cache;
     if ($cache instanceof order) {
         //If order has order-status, that means it is not a basket any more, so we have to reset $cache
         if ($cache->getOrderStatus() && $cache->getOrderStatus() != order::getStatusByCode('editing') || $useDummyOrder == false) {
             $cache = null;
         } else {
             return $cache;
         }
     }
     $customer = customer::get();
     $cmsController = cmsController::getInstance();
     $domain = $cmsController->getCurrentDomain();
     $domainId = $domain->getId();
     $orderId = $customer->getLastOrder($domainId);
     if ($orderId) {
         return $cache = order::get($orderId);
     }
     return $cache = order::create($useDummyOrder);
 }
예제 #5
0
    $info = implode(",", $info);
}
require DIR_FS_CLASSES . 'shipping.php';
require BITCOMMERCE_PKG_PATH . 'classes/CommercePaymentManager.php';
$payment_modules = new CommercePaymentManager($_SESSION['payment']);
$shipping_modules = new shipping($_SESSION['shipping']);
require BITCOMMERCE_PKG_PATH . 'classes/CommerceOrder.php';
$order = new order();
if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG == 'Yes') {
    mail(STORE_OWNER_EMAIL_ADDRESS, 'IPN DEBUG MESSAGE', '7.1 Started Order ' . $_SESSION['payment']);
}
require DIR_FS_CLASSES . 'order_total.php';
$order_total_modules = new order_total();
$order_totals = $order_total_modules->process();
if (isset($_SESSION['customer_id'])) {
    $new_order_id = $order->create($order_totals);
}
if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG == 'Yes') {
    mail(STORE_OWNER_EMAIL_ADDRESS, 'IPN DEBUG MESSAGE', '8 Created Order ' . $new_order_id);
}
if (eregi("VERIFIED", $info) && $_POST['txn_type'] == 'web_accept' && $_POST['business'] == MODULE_PAYMENT_PAYPAL_BUSINESS_ID) {
    if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG == 'Yes') {
        mail(STORE_OWNER_EMAIL_ADDRESS, 'IPN DEBUG MESSAGE', 'Order Verified ' . $new_order_id);
    }
    // do success stuff here
    // Things to do
    // create paypal database entry
    $paypal_order = array(zen_order_id => $new_order_id, txn_type => $_POST['txn_type'], reason_code => $_POST['reason_code'], payment_type => $_POST['payment_type'], payment_status => $_POST['payment_status'], pending_reason => $_POST['pending_reason'], invoice => $_POST['invoice'], mc_currency => $_POST['mc_currency'], first_name => $_POST['first_name'], last_name => $_POST['last_name'], payer_business_name => $_POST['payer_business_name'], address_name => $_POST['address_name'], address_street => $_POST['addrss_street'], address_city => $_POST['address_city'], address_state => $_POST['address_state'], address_zip => $_POST['address_zip'], address_country => $_POST['address_country'], address_status => $_POST['address_status'], payer_email => $_POST['payer_email'], payer_id => $_POST['payer_id'], payer_status => $_POST['payer_status'], payment_date => $_POST['payment_date'], business => $_POST['business'], receiver_email => $_POST['receiver_email'], receiver_id => $_POST['receiver_id'], txn_id => $_POST['txn_id'], parent_txn_id => $_POST['parent_txn_id'], num_cart_items => $_POST['num_cart_items'], mc_gross => $_POST['mc_gross'], mc_fee => $_POST['mc_fee'], settle_amount => $_POST['settle_amount'], settle_currency => $_POST['settle_currency'], exchange_rate => $_POST['exchange_rate'], notify_version => $_POST['notify_version'], verify_sign => $_POST['verify_sign'], last_modified => $_POST['last_modified'], date_added => $_POST['date_added'], memo => $_POST['memo']);
    if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG == 'Yes') {
        mail(STORE_OWNER_EMAIL_ADDRESS, 'IPN DEBUG MESSAGE', '10. Created Order Array');
    }
예제 #6
0
function mods_create_ingreds($ord, $ingredid, $operation)
{
    $query = "SELECT * FROM `orders` WHERE `associated_id`='" . $ord->id . "' AND `ingredid` = '" . $ingredid . "'";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return mysql_errno();
    }
    $antiop = $operation * -1;
    // if order is found and is opposite to the wanted one, we simply delete it,
    // otherwise we create the wanted order
    if (mysql_num_rows($res)) {
        $arr = mysql_fetch_array($res);
        if ($arr['operation'] == $antiop) {
            $ord_ingid = (int) $arr['id'];
            $ord_ing = new order($ord_ingid);
            if (class_exists('stock_object')) {
                $stock = new stock_object();
                $stock->silent = true;
                $stock->remove_from_waiter($ord_ing->id, 0);
            }
            if ($err = $ord_ing->delete()) {
                return $err;
            }
        }
    } else {
        $ord_ing = new order();
        $ord_ing->data = $ord->data;
        // now unsets some vars that we don't want to copy
        unset($ord_ing->data['id']);
        unset($ord_ing->data['associated_id']);
        unset($ord_ing->data['price']);
        unset($ord_ing->data['timestamp']);
        // set quantity to 0 to start with empty order (for stock function)
        $ord_ing->data['quantity'] = 0;
        $ord_ing->data['dishid'] = MOD_ID;
        $ord_ing->data['ingredid'] = $ingredid;
        $ord_ing->data['associated_id'] = $ord->id;
        $err = $ord_ing->create();
        $ord_ing->data['operation'] = $operation;
        $ord_ing->data['quantity'] = $ord->data['quantity'];
        if (class_exists('stock_object')) {
            $stock = new stock_object();
            $stock->silent = true;
            $stock->remove_from_waiter($ord_ing->id, $ord->data['quantity']);
        }
        $err += $ord_ing->set();
        if ($err) {
            return 1;
        }
    }
    return 0;
}
 function copy($dest = 0)
 {
     if (!$dest || !$dest->exists()) {
         $dest = new order();
         $create = true;
     }
     $this->get();
     $dest->data = $this->data;
     unset($dest->data['id']);
     unset($dest->data['associated_id']);
     unset($dest->data['price']);
     unset($dest->data['timestamp']);
     if ($create) {
         $id = $dest->create();
     } else {
         $dest->set();
     }
     return $dest->id;
 }
예제 #8
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;
}