Cron.php
3 years ago
Ecommerce.php
3 years ago
Language.php
3 years ago
Logger.php
3 years ago
MobileDetect.php
3 years ago
Options.php
3 years ago
Plugin.php
3 years ago
Properties.php
3 years ago
Tracking.php
3 years ago
Utils.php
2 years ago
Ecommerce.php
181 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | class TCMP_Ecommerce { |
| 7 | var $order_id; |
| 8 | |
| 9 | function __construct() { |
| 10 | add_action( 'woocommerce_thankyou', array( &$this, 'wooCommerceThankYou' ), -10 ); |
| 11 | //add_action('woocommerce_thankyou_order_id', array(&$this, 'wooCommerceThankYou'), -10); |
| 12 | |
| 13 | add_action( 'edd_payment_receipt_after_table', array( &$this, 'eddThankYou' ) ); |
| 14 | add_action( 'wpsc_transaction_result_cart_item', array( &$this, 'eCommerceThankYou' ) ); |
| 15 | } |
| 16 | |
| 17 | public function getCustomPostType( $pluginId ) { |
| 18 | $result = ''; |
| 19 | switch ( intval( $pluginId ) ) { |
| 20 | case TCMP_PLUGINS_WOOCOMMERCE: |
| 21 | $result = 'product'; |
| 22 | break; |
| 23 | case TCMP_PLUGINS_EDD: |
| 24 | $result = 'download'; |
| 25 | break; |
| 26 | case TCMP_PLUGINS_WP_ECOMMERCE: |
| 27 | $result = 'wpsc-product'; |
| 28 | break; |
| 29 | } |
| 30 | return $result; |
| 31 | } |
| 32 | |
| 33 | //WPSC_Purchase_Log_Customer_HTML_Notification |
| 34 | function eCommerceThankYou( $order ) { |
| 35 | global $tcmp; |
| 36 | $purchase = new TCMP_EcommercePurchase(); |
| 37 | |
| 38 | $order_id = intval( $order['purchase_id'] ); |
| 39 | $purchase->order_id = $order_id; |
| 40 | $tcmp->log->debug( 'Ecommerce: ECOMMERCE THANKYOU' ); |
| 41 | $tcmp->log->debug( 'Ecommerce: NEW ECOMMERCE ORDERID=%s', $order_id ); |
| 42 | |
| 43 | $order = new WPSC_Purchase_Log( $order_id ); |
| 44 | $items = $order->get_cart_contents(); |
| 45 | $productsIds = array(); |
| 46 | foreach ( $items as $v ) { |
| 47 | if ( isset( $v->prodid ) ) { |
| 48 | $k = intval( $v->prodid ); |
| 49 | if ( $k ) { |
| 50 | $v = $v->name; |
| 51 | $purchase->products[] = $v; |
| 52 | $productsIds[] = $k; |
| 53 | $tcmp->log->debug( 'Ecommerce: ITEM %s=%s IN CART', $k, $v ); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | $args = array( |
| 59 | 'pluginId' => TCMP_PLUGINS_WP_ECOMMERCE, |
| 60 | 'productsIds' => $productsIds, |
| 61 | 'categoriesIds' => array(), |
| 62 | 'tagsIds' => array(), |
| 63 | ); |
| 64 | $tcmp->options->pushConversionSnippets( $args, $purchase ); |
| 65 | return ''; |
| 66 | } |
| 67 | |
| 68 | function eddThankYou( $payment, $edd_receipt_args = null ) { |
| 69 | global $tcmp; |
| 70 | if ( ! class_exists( 'EDD_Customer' ) ) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | /* @var $payment WP_Post */ |
| 75 | $purchase = new TCMP_EcommercePurchase(); |
| 76 | $purchase->order_id = $tcmp->utils->get( $payment, 'ID' ); |
| 77 | $purchase->user_id = $tcmp->utils->get( $payment, 'post_author', false ); |
| 78 | |
| 79 | $settings = edd_get_settings(); |
| 80 | if ( isset( $settings['currency'] ) ) { |
| 81 | $purchase->currency = $settings['currency']; |
| 82 | } |
| 83 | |
| 84 | $tcmp->log->debug( 'Ecommerce: EDD THANKYOU' ); |
| 85 | $tcmp->log->debug( 'Ecommerce: NEW EDD ORDERID=%s', $purchase->order_id ); |
| 86 | $cart = edd_get_payment_meta_cart_details( $purchase->order_id, true ); |
| 87 | $productsIds = array(); |
| 88 | $purchase->amount = 0; |
| 89 | $purchase->total = 0; |
| 90 | foreach ( $cart as $key => $item ) { |
| 91 | if ( isset( $item['id'] ) ) { |
| 92 | $k = intval( $item['id'] ); |
| 93 | if ( $k ) { |
| 94 | $v = $item['name']; |
| 95 | $purchase->products[] = $v; |
| 96 | $productsIds[] = $k; |
| 97 | $tcmp->log->debug( 'Ecommerce: ITEM %s=%s IN CART', $k, $v ); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | $args = array( |
| 103 | 'pluginId' => TCMP_PLUGINS_EDD, |
| 104 | 'productsIds' => $productsIds, |
| 105 | 'categoriesIds' => array(), |
| 106 | 'tagsIds' => array(), |
| 107 | ); |
| 108 | $tcmp->options->pushConversionSnippets( $args, $purchase ); |
| 109 | } |
| 110 | function wooCommerceThankYou( $order_id ) { |
| 111 | global $tcmp; |
| 112 | if ( ! $order_id ) { |
| 113 | return; |
| 114 | } |
| 115 | if ( $this->order_id === $order_id ) { |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | $this->order_id = $order_id; |
| 120 | $purchase = new TCMP_EcommercePurchase(); |
| 121 | $purchase->order_id = $order_id; |
| 122 | $tcmp->log->debug( 'Ecommerce: WOOCOMMERCE THANKYOU' ); |
| 123 | |
| 124 | $order = new WC_Order( $order_id ); |
| 125 | $purchase->email = $order->get_billing_email(); |
| 126 | $purchase->fullname = $order->get_billing_first_name(); |
| 127 | if ( $order->get_billing_last_name() != '' ) { |
| 128 | $purchase->fullname .= ' ' . $order->get_billing_last_name(); |
| 129 | } |
| 130 | |
| 131 | $items = $order->get_items(); |
| 132 | $tcmp->log->debug( 'Ecommerce: NEW WOOCOMMERCE ORDERID=%s', $order_id ); |
| 133 | $productsIds = array(); |
| 134 | foreach ( $items as $k => $v ) { |
| 135 | $k = intval( $v['product_id'] ); |
| 136 | if ( $k > 0 ) { |
| 137 | $v = $v['name']; |
| 138 | $purchase->products[] = $v; |
| 139 | $tcmp->log->debug( 'Ecommerce: ITEM %s=%s IN CART', $k, $v ); |
| 140 | $productsIds[] = $k; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | $args = array( |
| 145 | 'pluginId' => TCMP_PLUGINS_WOOCOMMERCE, |
| 146 | 'productsIds' => $productsIds, |
| 147 | 'categoriesIds' => array(), |
| 148 | 'tagsIds' => array(), |
| 149 | ); |
| 150 | $tcmp->options->pushConversionSnippets( $args, $purchase ); |
| 151 | } |
| 152 | |
| 153 | function getActivePlugins() { |
| 154 | return $this->getPlugins( true ); |
| 155 | } |
| 156 | function getPlugins( $onlyActive = true ) { |
| 157 | global $tcmp; |
| 158 | |
| 159 | $array = array(); |
| 160 | $array[] = TCMP_PLUGINS_WOOCOMMERCE; |
| 161 | $array[] = TCMP_PLUGINS_EDD; |
| 162 | $array[] = TCMP_PLUGINS_WP_ECOMMERCE; |
| 163 | /* |
| 164 | $array[]=TCMP_PLUGINS_WP_SPSC; |
| 165 | $array[]=TCMP_PLUGINS_S2MEMBER; |
| 166 | $array[]=TCMP_PLUGINS_MEMBERS; |
| 167 | $array[]=TCMP_PLUGINS_CART66; |
| 168 | $array[]=TCMP_PLUGINS_ESHOP; |
| 169 | $array[]=TCMP_PLUGINS_JIGOSHOP; |
| 170 | $array[]=TCMP_PLUGINS_MARKETPRESS; |
| 171 | $array[]=TCMP_PLUGINS_SHOPP; |
| 172 | $array[]=TCMP_PLUGINS_SIMPLE_WP_ECOMMERCE; |
| 173 | $array[]=TCMP_PLUGINS_CF7; |
| 174 | $array[]=TCMP_PLUGINS_GRAVITY; |
| 175 | */ |
| 176 | |
| 177 | $array = $tcmp->plugin->getPlugins( $array, $onlyActive ); |
| 178 | return $array; |
| 179 | } |
| 180 | } |
| 181 |