WordPress.org

Ready to get started?Download WordPress

Forums

TheCartPress eCommerce Shopping Cart
[BUG] TheCartPress::refreshShoppingCart(); conflicts with TCP Dynamic Options (1 post)

  1. trusktr
    Member
    Posted 9 months ago #

    The function TheCartPress::refreshShoppingCart(); does not handle situations when the user also has the TCP Dynamic Options plugin installed.

    There needs to be some code added to handle such situations, otherwise when this function is called, the shopping cart will contain the wrong prices for items in the shopping cart. Specifically, the price of the item in the cart will be just the price of the dynamic option, excluding the price of the base product

    (WHOOPS! that's not good! If the option is only $10 but the base product is $2000, they will purchase the item for jst $10 instead of $2010!)

    The function needs to be changed from

    function refresh() {
    		$items = $this->getItems();
    		$this->deleteAll();
    		foreach( $items as $item ) {
    			$price = tcp_get_the_price( $item->getPostId() );
    			if ( $item->getOption1Id() > 0 ) $price += tcp_get_the_price( $item->getOption1Id() );
    			if ( $item->getOption2Id() > 0 ) $price += tcp_get_the_price( $item->getOption2Id() );
    			$this->add( $item->getPostId(), $item->getOption1Id(), $item->getOption2Id(), $item->getCount(), $price, $item->getWeight() );
    		}
    		$this->removeOrderId();
    	}
    }

    to

    function refresh() {
    		$items = $this->getItems();
    		$this->deleteAll();
    		foreach( $items as $item ) {
    			$price = tcp_get_the_price( $item->getPostId() );
    
                            /*
                             *BEGIN FIX {
                             */
                            if (get_post_type($item->getPostId()) == "tcp_dynamic_options") {// if this is a dynamic options item
                                $base_product_id = /*PUT SOMETHING HERE TO DETERMINE THE BASE PRODUCT ID, Does a function exist in the TCP_DO plugin already?*/;
                                $price = $price + tcp_get_the_price( $base_product_id );
                            }
                            /*
                             *END FIX }
                             */
    
    			if ( $item->getOption1Id() > 0 ) $price += tcp_get_the_price( $item->getOption1Id() );
    			if ( $item->getOption2Id() > 0 ) $price += tcp_get_the_price( $item->getOption2Id() );
    			$this->add( $item->getPostId(), $item->getOption1Id(), $item->getOption2Id(), $item->getCount(), $price, $item->getWeight() );
    		}
    		$this->removeOrderId();
    	}
    }

    .

    It's a simple fix, but necessary, because in my case, a third (custom) plugin adds a filter for wp_login to call the refresh() function whenever a user logs in to apply special discounts for certain role types. What happens is the user gets a discount based *only* on the price of the dynamic option, excluding the price of the base product.

    http://wordpress.org/extend/plugins/thecartpress/

Reply

You must log in to post.