Plugin Directory

Changeset 949997


Ignore:
Timestamp:
07/17/2014 12:25:53 AM (12 years ago)
Author:
segmentio
Message:

merge 1.0.1 into svn

Location:
segmentio/trunk
Files:
3 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • segmentio/trunk/Makefile

    r709542 r949997  
    11
    2 # Open the WordPress site and admin.
     2#
     3# Commands
     4#
     5
     6deploy:
     7    @bin/deploy
     8
    39test:
    4         open http://localhost:8888/analytics-wordpress/test/wp-admin/options-general.php?page=analytics-wordpress
    5         open http://localhost:8888/analytics-wordpress/test/
     10    # TODO
    611
    7 # Turns the testing plugin into a real folder, for more accurate testing.
    8 test-folder:
    9         rm -rf test/wp-content/plugins/analytics-wordpress
    10         cp -r ./ ../analytics-wordpress-temp
    11         rm -rf ../analytics-wordpress-temp/test
    12         rm -rf ../analytics-wordpress-temp/.git
    13         mv ../analytics-wordpress-temp test/wp-content/plugins/analytics-wordpress
     12#
     13# Phonies
     14#
    1415
    15 # Turns the testing plugin into a symlink, for faster testing.
    16 test-symlink:
    17         rm -rf test/wp-content/plugins/analytics-wordpress
    18         ln -s ../../.. test/wp-content/plugins/analytics-wordpress
    19 
     16.PHONY: deploy
    2017.PHONY: test
  • segmentio/trunk/analytics-wordpress.php

    r948394 r949997  
    44Plugin URI: https://segment.io/plugins/wordpress
    55Description: The hassle-free way to integrate any analytics service into your WordPress site.
    6 Version: 1.0.0
     6Version: 1.0.1
    77License: GPLv2
    88Author: Segment.io
     
    179179     * Current plugin version.
    180180     */
    181     const VERSION = '1.0.0';
     181    const VERSION = '1.0.1';
    182182
    183183    /**
  • segmentio/trunk/integrations/ecommerce/woocommerce.php

    r948394 r949997  
    105105    public function add_to_cart( $key, $id, $quantity ) {
    106106
     107        if ( ! is_object( WC()->cart ) ) {
     108            return;
     109        }
     110
    107111        $items     = WC()->cart->get_cart();
    108112        $cart_item = $items[ $key ];
     
    118122            )
    119123        );
     124
    120125    }
    121126
     
    136141        $track = $args[0];
    137142
    138         if ( false !== ( $product = Segment_Cookie::get_cookie( 'added_to_cart' ) ) ) {
     143        if ( false !== ( $cookie = Segment_Cookie::get_cookie( 'added_to_cart' ) ) ) {
     144
     145            if ( ! is_object( WC()->cart ) ) {
     146                return $track;
     147            }
    139148
    140149            $items    = WC()->cart->get_cart();
    141             $product  = json_decode( $product );
    142             $_product = $items[ $product->key ];
    143 
    144             $item = array(
    145                 'id'       => $product->ID,
    146                 'sku'      => $_product['data']->get_sku(),
    147                 'name'     => $product->name,
    148                 'price'    => $product->price,
    149                 'quantity' => $product->quantity,
    150                 'category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->ID, 'product_cat' ), 'name' ) ),
    151             );
    152 
    153             $track = array(
    154                 'event'      => __( 'Added Product', 'segment' ),
    155                 'properties' => $item,
    156                 'http_event' => 'added_to_cart'
    157             );
     150            $_product = json_decode( $cookie );
     151
     152            if ( is_object( $_product ) ) {
     153                $product  = get_product( $_product->ID );
     154
     155                if ( $product ) {
     156                    $item = array(
     157                        'id'       => $product->id,
     158                        'sku'      => $product->get_sku(),
     159                        'name'     => $product->get_title(),
     160                        'price'    => $product->get_price(),
     161                        'quantity' => $_product->quantity,
     162                        'category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->id, 'product_cat' ), 'name' ) ),
     163                    );
     164
     165                    $track = array(
     166                        'event'      => __( 'Added Product', 'segment' ),
     167                        'properties' => $item,
     168                        'http_event' => 'added_to_cart'
     169                    );
     170                }
     171            }
    158172
    159173        }
     
    174188     */
    175189    public function remove_from_cart( $key ) {
     190
     191        if ( ! is_object( WC()->cart ) ) {
     192            return;
     193        }
     194
    176195        $items     = WC()->cart->get_cart();
    177196        $cart_item = $items[ $key ];
     
    205224        $track = $args[0];
    206225
    207         if ( false !== ( $product = Segment_Cookie::get_cookie( 'removed_from_cart' ) ) ) {
    208             $items    = WC()->cart->get_cart();
    209             $product  = json_decode( $product );
    210             $_product = $items[ $product->key ];
    211 
    212             $item = array(
    213                 'id'       => $product->ID,
    214                 'sku'      => $_product['data']->get_sku(),
    215                 'name'     => $product->name,
    216                 'price'    => $product->price,
    217                 'quantity' => 0,
    218                 'category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->ID, 'product_cat' ), 'name' ) ),
    219             );
    220 
    221             $track = array(
    222                 'event'      => __( 'Removed Product', 'segment' ),
    223                 'properties' => $item,
    224                 'http_event' => 'removed_from_cart'
    225             );
    226 
     226        if ( false !== ( $cookie = Segment_Cookie::get_cookie( 'removed_from_cart' ) ) ) {
     227
     228            if ( ! is_object( WC()->cart ) ) {
     229                return $track;
     230            }
     231
     232            $items = WC()->cart->get_cart();
     233
     234            $_product  = json_decode( $cookie );
     235
     236            if ( is_object( $_product ) ) {
     237                $product  = get_product( $_product->ID );
     238
     239                if ( $product ) {
     240                    $item = array(
     241                        'id'       => $product->ID,
     242                        'sku'      => $product->get_sku(),
     243                        'name'     => $product->get_title(),
     244                        'price'    => $product->get_price(),
     245                        'quantity' => 0,
     246                        'category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->ID, 'product_cat' ), 'name' ) ),
     247                    );
     248
     249                    $track = array(
     250                        'event'      => __( 'Removed Product', 'segment' ),
     251                        'properties' => $item,
     252                        'http_event' => 'removed_from_cart'
     253                    );
     254                }
     255            }
    227256        }
    228257
  • segmentio/trunk/readme.txt

    r948394 r949997  
    44Requires at least: 3.6
    55Tested up to: 3.9.2
    6 Stable tag: 0.6
     6Stable tag: 1.0.1
    77License: GPLv2
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6161
    6262== Screenshots ==
    63 s
     63
    6464
    6565== Changelog ==
     66
     67= 1.0.1 =
     68* Fixes fatal error when tracking WooCommerce products.
    6669
    6770= 1.0.0 =
Note: See TracChangeset for help on using the changeset viewer.