コード例 #1
0
ファイル: order.php プロジェクト: forthrobot/inuvik
/**
 * shopp_add_order_line - add a line item to an order.
 *
 * @api
 * @since 1.2
 *
 * @param int $order (required) the order id to add the line item to
 * @param array|Item $data data to create the free-form item from (see $item_fields for allowed data), or alternately an Item object
 * @return bool|Purchased item object - false on failure, new order line item on success.
 **/
function shopp_add_order_line($order = false, $data = array())
{
    $item_fields = array('product', 'price', 'download', 'dkey', 'name', 'description', 'optionlabel', 'sku', 'quantity', 'unitprice', 'unittax', 'shipping', 'total', 'type', 'addons', 'variation', 'data');
    if (!($Purchase = shopp_order_exists($order))) {
        shopp_debug(__FUNCTION__ . " failed: Invalid order id.");
        return false;
    }
    // Create and save a new ShoppPurchased item object
    $Purchased = new ShoppPurchased();
    if (is_object($data) && is_a($data, 'Item')) {
        $Purchased->copydata($data);
        if ($data->inventory) {
            $data->unstock();
        }
    } else {
        // build purchased line item
        $Purchased->unitprice = $Purchased->unittax = $Purchased->shipping = $Purchased->total = 0;
        foreach ($data as $key => $value) {
            if (!in_array($key, $item_fields)) {
                continue;
            }
            $Purchased->{$key} = $value;
        }
        if (!isset($Purchased->type)) {
            $Purchase->type = 'Shipped';
        }
    }
    $Purchased->purchase = $order;
    if (!empty($Purchased->download)) {
        $Purchased->keygen();
    }
    $Purchased->save();
    // Update the Purchase
    $Purchase->subtotal += $Purchased->unitprice * $Purchased->quantity;
    $Purchase->tax += $Purchased->unittax * $Purchased->quantity;
    $Purchase->freight += $Purchased->shipping;
    $total_added = $Purchased->total + $Purchased->unittax * $Purchased->quantity + $Purchased->shipping;
    $Purchase->total += $total_added;
    $Purchase->save();
    // invoice new amount
    shopp_add_order_event($Purchase->id, 'invoiced', array('gateway' => $Purchase->gateway, 'amount' => $total_added));
    return !empty($Purchased->id) ? $Purchased : false;
}
コード例 #2
0
ファイル: Order.php プロジェクト: forthrobot/inuvik
 /**
  * Builds purchased records from cart items attached to the given Purchase ID
  *
  * @author Jonathan Davis
  * @since 1.2.2
  *
  * @param int $purchaseid The Purchase id to attach the purchased records to
  * @return void
  **/
 public function items($purchaseid)
 {
     foreach ($this->Cart as $Item) {
         // Build purchased records from cart items
         $Purchased = new ShoppPurchased();
         $Purchased->purchase = $purchaseid;
         $Purchased->copydata($Item);
         $Purchased->save();
     }
     $this->checksum = $this->Cart->checksum;
     // Track the cart contents checksum to detect changes.
 }