Autor | Zpráva | ||
---|---|---|---|
czmarci Profil * |
#1 · Zasláno: 19. 7. 2012, 23:53:46
Zdravím, snažím se sepsat menší plugin pro WP e-commerce, ale narazil jsem na problém, který se mi nedaří celý den vyřešit. Cílem funkce má být přidání produktů, u nichž je zatrhnutý checkbox. WP e-commerce v základu vkládá do košíku pouze jeden produkt ale na webu na kterém pracuji je potřeba vložit do košíku všechny produkty, u kterých je zatrhnutý checkbox. Přestože jsem vše sepsal podle vzoru, zobrazí se php chyba Call to a member function set_item() on a non-object
function LucToCart($product_id, $parameters) { global $wpsc_cart; $state = $wpsc_cart->set_item($product_id, $parameters); } if(!empty($_GET['lucproducts'])) { foreach($_GET['lucproducts'] as $lucproducts){ $product_id = (int)$lucproducts; $default_parameters = array(); $default_parameters['variation_values'] = null; $default_parameters['quantity'] = 1; $default_parameters['provided_price'] = null; $default_parameters['comment'] = null; $default_parameters['time_requested'] = null; $default_parameters['custom_message'] = null; $default_parameters['file_data'] = null; $default_parameters['is_customisable'] = false; $default_parameters['meta'] = null; $provided_parameters = array(); $parameters = array_merge( $default_parameters, (array)$provided_parameters ); LucToCart($product_id, $parameters); } } Všem děkuji za reakce |
||
Magnus123 Profil |
#2 · Zasláno: 20. 7. 2012, 09:47:52
Ahoj. Píše ti to, že proměnná $wpsc_cart není objekt. Jaká je její deklarace?
|
||
czmarci Profil * |
#3 · Zasláno: 20. 7. 2012, 15:16:53
Ahoj, děkuji za reakci,
$wpsc_cart je objekt puginu wp e-commerce, který umožňuje manipulaci s košíkem. Proměná je popsána např. zde http://ardeearam.wikispaces.com/wp_e-commerce ve čtvrtém bodu, kde se píše: $wpsc_cart - a global object accessible inside themes of WP E-commerce where you can override cart items via $wpsc_cart->cart_items Tuto proměnou úspěšně využívají i jiné pluginy. Zkoušel jsem použít i: do_action('wpsc_set_cart_item' , $product_id , $parameters , $this); Přikládám ještě kompletní funkci set_item z pluginu wp e-commerce: function set_item($product_id, $parameters, $updater = false) { // default action is adding $add_item = false; $edit_item = false; if(($parameters['quantity'] > 0) && ($this->check_remaining_quantity($product_id, $parameters['variation_values'], $parameters['quantity']) == true)) { $new_cart_item = new wpsc_cart_item($product_id,$parameters, $this); do_action('wpsc_set_cart_item' , $product_id , $parameters , $this); $add_item = true; $edit_item = false; if((count($this->cart_items) > 0) && ($new_cart_item->is_donation != 1)) { //loop through each cart item foreach($this->cart_items as $key => $cart_item) { // compare product ids and variations. if(($cart_item->product_id == $new_cart_item->product_id) && ($cart_item->product_variations == $new_cart_item->product_variations) && ($cart_item->custom_message == $new_cart_item->custom_message) && ($cart_item->custom_file == $new_cart_item->custom_file)) { // if they are the same, increment the count, and break out; if(!$updater){ $this->cart_items[$key]->quantity += $new_cart_item->quantity; } else { $this->cart_items[$key]->quantity = $new_cart_item->quantity; } $this->cart_items[$key]->refresh_item(); $add_item = false; $edit_item = true; } } } // if we are still adding the item, add it if($add_item === true) { $this->cart_items[] = $new_cart_item; } } // if some action was performed, return true, otherwise, return false; $status = false; if(($add_item == true) || ($edit_item == true)) { $status = true; } $this->cart_item_count = count($this->cart_items); $this->clear_cache(); return $status; } |
||
Časová prodleva: 12 let
|
0