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