本文整理汇总了PHP中WPSC_Purchase_Log::get_cart_contents方法的典型用法代码示例。如果您正苦于以下问题:PHP WPSC_Purchase_Log::get_cart_contents方法的具体用法?PHP WPSC_Purchase_Log::get_cart_contents怎么用?PHP WPSC_Purchase_Log::get_cart_contents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPSC_Purchase_Log
的用法示例。
在下文中一共展示了WPSC_Purchase_Log::get_cart_contents方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _wpsc_action_update_product_stats
/**
* Update product stats when a purchase log containing it changes status
*
* @since 3.8.13
*
* @param int $log_id Purchase Log ID
* @param int $new_status New status
* @param int $old_status Old status
* @param WPSC_Purchase_Log $log Purchase Log
*/
function _wpsc_action_update_product_stats($log_id, $new_status, $old_status, $log)
{
$cart_contents = $log->get_cart_contents();
$new_status_completed = $log->is_transaction_completed();
$old_status_completed = WPSC_Purchase_Log::is_order_status_completed($old_status);
if ($new_status_completed && !$old_status_completed) {
// if the order went through without any trouble, then it's a positive thing!
$yay_or_boo = 1;
} elseif (!$new_status_completed && $old_status_completed) {
// if the order is declined or invalid, sad face :(
$yay_or_boo = -1;
} else {
// Not one of the above options then we will be indifferent
$yay_or_boo = 0;
}
// this dramatic mood swing affects the stats of each products in the cart
foreach ($cart_contents as $cart_item) {
$product = new WPSC_Product($cart_item->prodid);
if ($product->exists()) {
$diff_sales = $yay_or_boo * (int) $cart_item->quantity;
$diff_earnings = $yay_or_boo * (int) $cart_item->price * (int) $cart_item->quantity;
$product->sales += $diff_sales;
$product->earnings += $diff_earnings;
// if this product has parent, make the same changes to the parent
if ($product->post->post_parent) {
$parent = WPSC_Product::get_instance($product->post->post_parent);
$parent->sales += $diff_sales;
$parent->earnings += $diff_earnings;
}
}
}
}
示例2: save_attendee_meta_to_order
/**
* Sets attendee data on order posts
*
* @since 4.1
*
* @param ShoppPurchase $purchase ShoppPurchase object
*/
public function save_attendee_meta_to_order($data)
{
$purchase_log = new WPSC_Purchase_Log($data['purchase_log_id']);
$order_items = $purchase_log->get_cart_contents();
// Bail if the order is empty
if (empty($order_items)) {
return;
}
$product_ids = array();
// gather product ids
foreach ((array) $order_items as $item) {
if (empty($item->prodid)) {
continue;
}
$product_ids[] = $item->prodid;
}
$meta_object = Tribe__Tickets_Plus__Main::instance()->meta();
// build the custom meta data that will be stored in the order meta
if (!($order_meta = $meta_object->build_order_meta($product_ids))) {
return;
}
// store the custom meta on the order
$result = wpsc_add_purchase_meta($purchase_log->get('id'), Tribe__Tickets_Plus__Meta::META_KEY, $order_meta, true);
// clear out product custom meta data cookies
foreach ($product_ids as $product_id) {
$meta_object->clear_meta_cookie_data($product_id);
}
}
示例3: eCommerceThankYou
function eCommerceThankYou($order)
{
global $tcm;
$orderId = intval($order['purchase_id']);
$tcm->Log->debug('Ecommerce: ECOMMERCE THANKYOU');
$tcm->Log->debug('Ecommerce: NEW ECOMMERCE ORDERID=%s', $orderId);
$order = new WPSC_Purchase_Log($orderId);
$items = $order->get_cart_contents();
$productsIds = array();
foreach ($items as $v) {
if (isset($v->prodid)) {
$k = intval($v->prodid);
if ($k) {
$v = $v->name;
$productsIds[] = $k;
$tcm->Log->debug('Ecommerce: ITEM %s=%s IN CART', $k, $v);
}
}
}
$args = array('pluginId' => TCM_PLUGINS_WP_ECOMMERCE, 'productsIds' => $productsIds, 'categoriesIds' => array(), 'tagsIds' => array());
$tcm->Options->pushConversionSnippets($args);
return '';
}
示例4: push_sales_data
/**
* Pushes sales data back to Baikonur
*
* Only pushes once. Accounts for annoying potential edge case of status-switching admins
*
* @param WPSC_Purchase_Log object $purchase_log Purchase Log object
* @return void
*/
public static function push_sales_data($purchase_log_id, $current_status, $old_status, $purchase_log)
{
$purchase_log = new WPSC_Purchase_Log($purchase_log_id);
$id = absint($purchase_log->get('id'));
//Also checking is_order_received, as that's what Manual Payments do.
if ($purchase_log->is_transaction_completed() || $purchase_log->is_order_received()) {
$pushed_to_sass = wpsc_get_meta($id, '_pushed_to_wpeconomy', 'purchase_log');
if (empty($pushed_to_saas)) {
$data = $purchase_log->get_data();
$cart_contents = $purchase_log->get_cart_contents();
//We want to push sales data - but naturally, IDs will differ, even names could potentially.
//So we add the slug to the object we POST
foreach ($cart_contents as $key => $cart_item) {
$slug = get_post_field('post_name', $cart_item->prodid);
$cart_contents[$key]->slug = $slug;
}
$args = array('body' => array('data' => json_encode($data), 'cart_contents' => json_encode($cart_contents)));
$request = wp_remote_post('http://www.wpeconomy.org/?sales_data=true', $args);
$response = wp_remote_retrieve_response_code($request);
//For some reason, if the site is down, we want the ability to ensure we can grab the sale later.
$success = 200 === $response;
wpsc_update_meta($id, '_pushed_to_wpeconomy', $success, 'purchase_log');
}
}
}
示例5: add_pushes
public function add_pushes($session_id)
{
$purchase = new WPSC_Purchase_Log($session_id, 'sessionid');
$purchase_id = $purchase->get('id');
$data = new WPSC_Checkout_Form_Data($purchase_id);
$output = '';
$city = $data->get('billingcity');
$state = $data->get('billingstate');
$country = $data->get('billingcountry');
$state = !empty($state) ? wpsc_get_state_by_id($state, 'name') : '';
$cart_items = $purchase->get_cart_contents();
$total_shipping = wpsc_get_total_shipping($purchase_id);
$total_tax = $total_price = 0;
foreach ($cart_items as $item) {
/* For backwards compatibility, convert objects to arrays */
$item = (array) $item;
$total_tax += $item['tax_charged'];
$total_price += absint($item['quantity']) * $item['price'];
}
if ($this->is_theme_tracking || $this->advanced_code) {
$output .= "<script type='text/javascript'>\n\r";
}
add_filter('wpsc_toggle_display_currency_code', array($this, 'remove_currency_and_html'));
if ($this->use_universal_analytics()) {
// Yoast GA Plugin switched to it's own object name __gaTracker - assign it to our ga object if it exists
$output .= "var ga = typeof ga === 'undefined' && typeof __gaTracker !== 'undefined' ? __gaTracker : ga;";
$output .= "ga('require', 'ecommerce');\n\r";
$output .= "ga('ecommerce:addTransaction', {\n\t\t\t\t'id': '" . $purchase_id . "', // Transaction ID. Required.\n\t\t\t\t'affiliation': '" . wp_specialchars_decode($this->get_site_name()) . "', // Affiliation or store name.\n\t\t\t\t'revenue': '" . number_format($total_price, 2, '.', '') . "', // Grand Total.\n\t\t\t\t'shipping': '" . wpsc_currency_display($total_shipping) . "', // Shipping.\n\t\t\t\t'tax': '" . wpsc_currency_display($total_tax) . "' // Tax.\n\t\t\t});\n\r";
} else {
$output .= "\n\t\t\t\t_gaq.push(['_addTrans',\n\t\t\t\t'" . $purchase_id . "', // order ID - required\n\t\t\t\t'" . wp_specialchars_decode($this->get_site_name()) . "', // affiliation or store name\n\t\t\t\t'" . number_format($total_price, 2, '.', '') . "', // total - required\n\t\t\t\t'" . wpsc_currency_display($total_tax) . "', // tax\n\t\t\t\t'" . wpsc_currency_display($total_shipping) . "', // shipping\n\t\t\t\t'" . wp_specialchars_decode($city) . "', // city\n\t\t\t\t'" . wp_specialchars_decode($state) . "', // state or province\n\t\t\t\t'" . wp_specialchars_decode($country) . "' // country\n\t\t\t]);\n\r";
}
remove_filter('wpsc_toggle_display_currency_code', array($this, 'remove_currency_and_html'));
foreach ($cart_items as $item) {
/* For backwards compatibility, convert objects to arrays */
$item = (array) $item;
$category = wp_get_object_terms($item['prodid'], 'wpsc_product_category', array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'all_with_object_id'));
$item['sku'] = get_post_meta($item['prodid'], '_wpsc_sku', true);
if (empty($item['sku'])) {
$item['sku'] = $item['prodid'];
}
if ($category) {
$item['category'] = $category[0]->name;
} else {
$item['category'] = '';
}
$item = apply_filters('wpsc_google_analytics_pushed_product', array_map('wp_specialchars_decode', $item), $item, $this);
if ($this->use_universal_analytics()) {
$output .= "ga('ecommerce:addItem', {" . "'id': '" . $purchase_id . "'," . "'name': '" . $item['name'] . "'," . "'sku': '" . $item['sku'] . "'," . "'category': '" . $item['category'] . "'," . "'price': '" . $item['price'] . "'," . "'quantity': '" . $item['quantity'] . "'" . "});\n\r";
} else {
$output .= "_gaq.push(['_addItem'," . "'" . $purchase_id . "'," . "'" . $item['sku'] . "'," . "'" . $item['name'] . "'," . "'" . $item['category'] . "'," . "'" . $item['price'] . "'," . "'" . $item['quantity'] . "']);\n\r";
// Item Quantity
}
}
if ($this->use_universal_analytics()) {
$output .= "ga('ecommerce:send');\n\r";
} else {
$output .= "_gaq.push(['_trackTrans']);\n\r";
}
if ($this->is_theme_tracking || $this->advanced_code) {
$output .= "</script>\n\r";
}
return $output;
}
示例6: completed_order
/**
* Adds product properties to analytics.track() when the order is completed successfully.
*
* @since 1.0.0
* @access public
*
* @uses func_get_args() Because our abstract class doesn't know how many parameters are passed to each hook
* for each different platform, we use func_get_args().
*
* @return array Filtered array of name and properties for analytics.track().
*/
public function completed_order()
{
$args = func_get_args();
$track = $args[0];
if (did_action('wpsc_transaction_results_shutdown') && isset($_GET['sessionid'])) {
$log = new WPSC_Purchase_Log($_GET['sessionid'], 'sessionid');
/* We like checking is_order_received(), as that's what the manual payment gateway uses. */
if ($log->is_transaction_completed() || $log->is_order_received()) {
$gateway_data = $log->get_gateway_data();
$items = $log->get_cart_contents();
$products = array();
foreach ($items as $item) {
$product = array('id' => $item->prodid, 'sku' => wpsc_product_sku($item->prodid), 'name' => $item->name, 'price' => $item->price, 'quantity' => $item->quantity, 'category' => implode(', ', wp_list_pluck(wpsc_get_product_terms($item->prodid, 'wpsc_product_category'), 'name')));
$products[] = $product;
}
$track = array('event' => __('Completed Order', 'segment'), 'properties' => array('id' => $log->get('id'), 'total' => $log->get('totalprice'), 'revenue' => $gateway_data['subtotal'], 'shipping' => $gateway_data['shipping'], 'tax' => $gateway_data['tax'], 'products' => $products));
}
}
return $track;
}
示例7: type_of_goods
public function type_of_goods($log_id)
{
$digital = 0;
$log = new WPSC_Purchase_Log($log_id);
$cart = $log->get_cart_contents();
foreach ($cart as $cartitem) {
$product_meta = get_post_meta($cartitem->prodid, '_wpsc_product_metadata');
if (isset($product_meta[0]['no_shipping']) && $product_meta[0]['no_shipping'] == 1) {
$digital++;
}
}
return $digital == count($cart) ? 'DIGITAL' : 'PHYSICAL';
}
示例8: array
//.........这里部分代码省略.........
case 'BADDR3':
$cust[$key] = $checkout['billingcity'] . ', ' . $checkout['billingstate'] . ' ' . $checkout['billingpostcode'];
break;
case 'BADDR4':
$cust[$key] = $checkout['billingcountry'];
break;
case 'SADDR1':
$cust[$key] = $checkout['shippingfirstname'] . ' ' . $checkout['shippinglastname'];
break;
case 'SADDR2':
$cust[$key] = $checkout['shippingaddress'];
break;
case 'SADDR3':
$cust[$key] = $checkout['shippingcity'] . ', ' . $checkout['shippingstate'] . ' ' . $checkout['shippingpostcode'];
break;
case 'SADDR4':
$cust[$key] = $checkout['billingcountry'];
break;
}
}
foreach ($trans as $key => $value) {
$trans[$key] = trim(preg_replace('/\\s+/', ' ', $value));
}
foreach ($cust as $key => $value) {
$cust[$key] = trim(preg_replace('/\\s+/', ' ', $value));
}
$splid = 1;
// TRNS line
$content .= 'TRNS';
foreach ($trans as $key => $value) {
$content .= "\t" . $value;
}
$content .= "\n";
$cart_contents = $purchase_log->get_cart_contents();
foreach ($cart_contents as $cart_item) {
$product_id = $cart_item->prodid;
if ($parent_product = get_post_field('post_parent', $product_id)) {
$product_id = $parent_product;
}
$terms = wp_get_post_terms($product_id, 'wpsc_product_category');
if (!empty($terms)) {
foreach ($terms as $term) {
$invitem = $term->name;
if ($term->parent != 0) {
break;
}
}
} else {
$invitem = '';
}
/*
$item_name = '';
$article = new Bling_Article( $cart_item->prodid );
if ( $article->check() ) {
$item_name = $article->name();
}
*/
$spl_product = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['sales_revenue'], 'AMOUNT' => -($cart_item->price * $cart_item->quantity), 'QNTY' => -$cart_item->quantity, 'PRICE' => $cart_item->price, 'NAME' => '', 'DOCNUM' => $purchase_log_id, 'MEMO' => $cart_item->name);
// SPL line
$content .= 'SPL';
foreach ($spl as $key => $value) {
$content .= "\t";
if (!empty($spl_product[$key])) {
$content .= $spl_product[$key];
}