Ejemplo n.º 1
0
function wpsc_the_product_price_display($args = array())
{
    if (empty($args['id'])) {
        $id = get_the_ID();
    } else {
        $id = (int) $args['id'];
    }
    $defaults = array('id' => $id, 'old_price_text' => __('Old Price: %s', 'wp-e-commerce'), 'price_text' => __('Price: %s', 'wp-e-commerce'), 'you_save_text' => __('You save: %s', 'wp-e-commerce'), 'old_price_class' => 'pricedisplay wpsc-product-old-price ' . $id, 'old_price_before' => '<p %s>', 'old_price_after' => '</p>', 'old_price_amount_id' => 'old_product_price_' . $id, 'old_price_amount_class' => 'oldprice', 'old_price_amount_before' => '<span class="%1$s" id="%2$s">', 'old_price_amount_after' => '</span>', 'price_amount_id' => 'product_price_' . $id, 'price_class' => 'pricedisplay wpsc-product-price ' . $id, 'price_before' => '<p %s>', 'price_after' => '</p>', 'price_amount_class' => 'currentprice pricedisplay ' . $id, 'price_amount_before' => '<span class="%1$s" id="%2$s">', 'price_amount_after' => '</span>', 'you_save_class' => 'pricedisplay wpsc-product-you-save product_' . $id, 'you_save_before' => '<p %s>', 'you_save_after' => '</p>', 'you_save_amount_id' => 'yousave_' . $id, 'you_save_amount_class' => 'yousave', 'you_save_amount_before' => '<span class="%1$s" id="%2$s">', 'you_save_amount_after' => '</span>', 'output_price' => true, 'output_old_price' => true, 'output_you_save' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * wpsc_the_product_price_display_args filter args for product price display
     *
     * Paramters used to format price display can be set globally using this filter
     *
     * @since 4.0
     *
     * @type array $args array of parameters used to format product price
     * @type int $product_id WPeC Product ID for the current product
     */
    $r = apply_filters('wpsc_the_product_price_display_args', $r, $id);
    extract($r);
    // if the product has no variations, these amounts are straight forward...
    $old_price = wpsc_product_normal_price($id);
    $current_price = wpsc_the_product_price(false, false, $id);
    $you_save = wpsc_you_save(array('type' => 'amount', 'product_id' => $id));
    $show_old_price = $show_you_save = wpsc_product_on_special($id);
    // Don't output old price HTML if not on sale.
    if (!wpsc_product_on_special($id)) {
        $output_old_price = $output_you_save = false;
    }
    // but if the product has variations and at least one of the variations is on special, we have
    // a few edge cases...
    if (wpsc_product_has_variations($id) && wpsc_product_on_special($id)) {
        // generally it doesn't make sense to display "you save" amount unless the user has selected
        // a specific variation
        $show_you_save = false;
        $old_price_number = wpsc_product_variation_price_from($id, array('only_normal_price' => true));
        $current_price_number = wpsc_product_variation_price_from($id);
        // if coincidentally, one of the variations are not on special, but its price is equal to
        // or lower than the lowest variation sale price, old price should be hidden, and current
        // price should reflect the "normal" price, not the sales price, to avoid confusion
        if ($old_price_number == $current_price_number) {
            $show_old_price = false;
            $current_price = wpsc_product_normal_price($id);
        }
    }
    // replace placeholders in arguments with correct values
    $old_price_class = apply_filters('wpsc_the_product_price_display_old_price_class', $old_price_class, $id);
    $old_price_amount_class = apply_filters('wpsc_the_product_price_display_old_price_amount_class', $old_price_amount_class, $id);
    $attributes = 'class="' . esc_attr($old_price_class) . '"';
    if (!$show_old_price) {
        $attributes .= ' style="display:none;"';
    }
    $old_price_before = sprintf($old_price_before, $attributes);
    $old_price_amount_before = sprintf($old_price_amount_before, esc_attr($old_price_amount_class), esc_attr($old_price_amount_id));
    $price_class = 'class="' . esc_attr(apply_filters('wpsc_the_product_price_display_price_class', esc_attr($price_class), $id)) . '"';
    $price_amount_class = apply_filters('wpsc_the_product_price_display_price_amount_class', esc_attr($price_amount_class), $id);
    $price_before = sprintf($price_before, $price_class);
    $price_amount_before = sprintf($price_amount_before, esc_attr($price_amount_class), esc_attr($price_amount_id));
    $you_save_class = apply_filters('wpsc_the_product_price_display_you_save_class', $you_save_class, $id);
    $you_save_amount_class = apply_filters('wpsc_the_product_price_display_you_save_amount_class', $you_save_amount_class, $id);
    $attributes = 'class="' . esc_attr($you_save_class) . '"';
    if (!$show_you_save) {
        $attributes .= ' style="display:none;"';
    }
    $you_save_before = sprintf($you_save_before, $attributes);
    $you_save_amount_before = sprintf($you_save_amount_before, esc_attr($you_save_amount_class), esc_attr($you_save_amount_id));
    $you_save = wpsc_currency_display($you_save);
    $old_price = $old_price_amount_before . $old_price . $old_price_amount_after;
    $current_price = $price_amount_before . $current_price . $price_amount_after;
    $you_save = $you_save_amount_before . $you_save . $you_save_amount_after;
    $old_price_text = sprintf($old_price_text, $old_price);
    $price_text = sprintf($price_text, $current_price);
    $you_save_text = sprintf($you_save_text, $you_save);
    if ($output_old_price) {
        echo $old_price_before . $old_price_text . $old_price_after . "\n";
    }
    if ($output_price) {
        echo $price_before . $price_text . $price_after . "\n";
    }
    if ($output_you_save) {
        echo $you_save_before . $you_save_text . $you_save_after . "\n";
    }
}
Ejemplo n.º 2
0
 /**
  * Set Item method, requires a product ID and the parameters for the product
  *
  * @access public
  *
  * @param integer the product ID
  * @param array parameters
  * @return boolean true on sucess, false on failure
  */
 function set_item($product_id, $parameters, $updater = false)
 {
     // default action is adding
     $add_item = false;
     $edit_item = false;
     $variation_check = true;
     if (wpsc_product_has_variations($product_id) && is_null($parameters['variation_values'])) {
         $variation_check = false;
     }
     if ($variation_check && $parameters['quantity'] > 0 && $this->check_remaining_quantity($product_id, $parameters['variation_values'], $parameters['quantity'])) {
         $new_cart_item = new wpsc_cart_item($product_id, $parameters, $this);
         do_action('wpsc_set_cart_item', $product_id, $parameters, $this, $new_cart_item);
         $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 && $cart_item->item_meta_equal($new_cart_item)) {
                     // 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;
                     do_action('wpsc_edit_item', $product_id, $parameters, $this);
                 }
             }
         }
         // if we are still adding the item, add it
         if ($add_item) {
             $this->cart_items[] = $new_cart_item;
             do_action('wpsc_add_item', $product_id, $parameters, $this);
         }
     }
     // if some action was performed, return true, otherwise, return false;
     $status = false;
     if ($add_item || $edit_item) {
         $status = $new_cart_item;
     }
     $this->cart_item_count = count($this->cart_items);
     $this->clear_cache();
     return $status;
 }
Ejemplo n.º 3
0
                        ?>
</label>
										<input type="text" id="wpsc_quantity_update_<?php 
                        echo wpsc_the_product_id();
                        ?>
" name="wpsc_quantity_update" size="2" value="1" />
										<input type="hidden" name="key" value="<?php 
                        echo wpsc_the_cart_item_key();
                        ?>
"/>
										<input type="hidden" name="wpsc_update_quantity" value="true" />
										<input type='hidden' name='wpsc_ajax_action' value='wpsc_update_quantity' />
									</div><!--close quantity_container-->
									<?php 
                    }
                    if (get_option('display_variations') != 1 && wpsc_product_has_variations(wpsc_the_product_id())) {
                        ?>
										<a href="<?php 
                        echo esc_url(wpsc_the_product_permalink());
                        ?>
" class="wpsc_buy_button"><?php 
                        _e('View Product', 'wpsc');
                        ?>
</a>
									<?php 
                    } else {
                        ?>
									<input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
									<input type="submit" value="<?php 
                        _e('Add To Cart', 'wpsc');
                        ?>
Ejemplo n.º 4
0
                    ?>
											<?php 
                    $action = wpsc_product_external_link(wpsc_the_product_id());
                    ?>
											<input class="wpsc_buy_button" type="button" value="<?php 
                    echo wpsc_product_external_link_text(wpsc_the_product_id(), __('Buy Now', 'wpsc'));
                    ?>
" onclick="return gotoexternallink('<?php 
                    echo $action;
                    ?>
', '<?php 
                    echo wpsc_product_external_link_target(wpsc_the_product_id());
                    ?>
')">
											<?php 
                } elseif (wpsc_product_has_variations(wpsc_the_product_id())) {
                    ?>
											<a href="<?php 
                    echo esc_url(wpsc_the_product_permalink());
                    ?>
" class="wpsc_buy_button"><?php 
                    _e('View Product', 'wpsc');
                    ?>
</a>
											<?php 
                } else {
                    ?>
										<input type="submit" value="<?php 
                    _e('Add To Cart', 'wpsc');
                    ?>
" name="Buy" class="wpsc_buy_button" id="product_<?php 
Ejemplo n.º 5
0
function wpsc_product_price_and_stock_forms($product_data = '')
{
    global $closed_postboxes, $wpdb, $variations_processor;
    $table_rate_price = get_product_meta($product_data['id'], 'table_rate_price');
    $custom_tax = get_product_meta($product_data['id'], 'custom_tax');
    if ($product_data == 'empty') {
        $display = "style='visibility:hidden;'";
    }
    echo "<div id='wpsc_product_price_and_stock_forms' class='wpsc_product_price_and_stock_forms postbox " . (array_search('wpsc_product_price_and_stock_forms', $product_data['closed_postboxes']) !== false ? 'closed' : '') . "' " . (array_search('wpsc_product_price_and_stock_forms', $product_data['hidden_postboxes']) !== false ? 'style="display: none;"' : '') . " >";
    echo "<h3 class='hndle'>";
    echo TXT_WPSC_PRICE_AND_STOCK_CONTROL;
    echo "\n\t</h3>\n    <div class='inside'>\n    <table>\n    ";
    echo "\n    <tr>\n       <td>\n          <input id='add_form_tax' type='checkbox' name='notax' value='yes' " . ($product_data['notax'] == 1 ? 'checked="checked"' : '') . "/>&nbsp;<label for='add_form_tax'>" . TXT_WPSC_TAXALREADYINCLUDED . "</label>\n       </td>\n    </tr>";
    echo "\n    <tr>\n\n       <td>\n          <input id='add_form_donation' type='checkbox' name='donation' value='yes' " . ($product_data['donation'] == 1 ? 'checked="checked"' : '') . " />&nbsp;<label for='add_form_donation'>" . TXT_WPSC_IS_DONATION . "</label>\n       </td>\n    </tr>";
    ?>
     <tr>
      <td>
        <input type='checkbox' value='1' name='table_rate_price' id='table_rate_price'  <?php 
    echo count($table_rate_price['quantity']) > 0 ? 'checked=\'checked\'' : '';
    ?>
 <?php 
    echo wpsc_product_has_variations($product_data['id']) ? 'disabled=\'disabled\'' : '';
    ?>
 />
        <label for='table_rate_price'><?php 
    echo TXT_WPSC_TABLE_RATED_PRICE;
    ?>
</label>
        <div style='display:<?php 
    echo $table_rate_price != '' && !wpsc_product_has_variations($product_data['id']) ? 'block' : 'none';
    ?>
;' id='table_rate'>
          <a class='add_level' style='cursor:pointer;'>+ Add level</a><br />
          <table>
						<tr>
							<td><?php 
    echo TXT_WPSC_QUANTITY;
    ?>
</td>
							<td><?php 
    echo TXT_WPSC_PRICE;
    ?>
</td>
						</tr>
						<?php 
    if (count($table_rate_price) > 0) {
        foreach ((array) $table_rate_price['quantity'] as $key => $qty) {
            if ($qty != '') {
                ?>
									<tr>
										<td>
											<input type="text" size="10" value="<?php 
                echo $qty;
                ?>
" name="productmeta_values[table_rate_price][quantity][]"/> and above
										</td>
										<td>
											<input type="text" size="10" value="<?php 
                echo $table_rate_price['table_price'][$key];
                ?>
" name="productmeta_values[table_rate_price][table_price][]" />
										</td>
										<td><img src="<?php 
                echo WPSC_URL;
                ?>
/images/cross.png" class="remove_line" /></td>
									</tr>
									<?php 
            }
        }
    }
    ?>
						
						<tr>
							<td><input type='text' size='10' value='' name='productmeta_values[table_rate_price][quantity][]'/> and above</td>
							<td><input type='text' size='10' value='' name='productmeta_values[table_rate_price][table_price][]'/></td>
						</tr>
          </table>
        </div>
      </td>
    </tr>


    
     <tr>
      <td>
        <input type='checkbox' value='1' name='custom_tax' id='custom_tax_checkbox'  <?php 
    echo is_numeric($custom_tax) > 0 ? 'checked=\'checked\'' : '';
    ?>
  />
        <label for='custom_tax_checkbox'><?php 
    echo _e("Custom Tax Rate", 'wpsc');
    ?>
</label>
        <div style='display:<?php 
    echo is_numeric($custom_tax) ? 'block' : 'none';
    ?>
;' id='custom_tax'>
					<input type='text' size='10' value='<?php 
    echo $custom_tax;
    ?>
' name='productmeta_values[custom_tax]'/>
        </div>
      </td>
    </tr>


    
    <?php 
    echo "\n    <tr>\n      <td style='width:430px;'>\n      <input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' " . ($product_data['quantity_limited'] == 1 ? 'checked="checked"' : '') . " name='quantity_limited'/>";
    //onclick='hideelement(\"add_stock\")'
    echo "&nbsp;<label for='add_form_quantity_limited' class='small'>" . TXT_WPSC_UNTICKBOX . "</label>";
    if ($product_data['id'] > 0) {
        $variations_output = $variations_processor->variations_grid_view($product_data['id']);
        if (wpsc_product_has_variations($product_data['id'])) {
            echo "<div class='edit_stock' style='display: none;'>\n\r";
            echo "<input class='stock_limit_quantity' name='quantity' value='" . $product_data['quantity'] . "' />";
            echo "</div>\n\r";
        } else {
            switch ($product_data['quantity_limited']) {
                case 1:
                    echo "            <div class='edit_stock' style='display: block;'>\n\r";
                    break;
                default:
                    echo "            <div class='edit_stock' style='display: none;'>\n\r";
                    break;
            }
            echo "<input type='text' class='stock_limit_quantity' name='quantity' size='10' value='" . $product_data['quantity'] . "' />";
            echo "              </div>\n\r";
        }
    } else {
        echo "\n\t\t\t\t\t<div style='display: none;' class='edit_stock'>\n\t\t\t\t\t\t<input type='text' name='quantity' value='0' size='10' />\n\t\t\t\t\t</div>";
    }
    echo "\n\t\t\t\t\n\t\t\t\t</td>\n\t\t\t</tr>";
    echo "\n\t\t</table>\n\t</div>\n</div>";
    //return $output;
}
Ejemplo n.º 6
0
/**
 * wpsc buy now button code products function
 * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different
 * @return string - html displaying one or more products
 */
function wpsc_buy_now_button($product_id, $replaced_shortcode = false)
{
    $product_id = absint($product_id);
    $product = get_post($product_id);
    $supported_gateways = array('wpsc_merchant_paypal_standard', 'paypal_multiple');
    $selected_gateways = get_option('custom_gateway_options');
    if ($replaced_shortcode) {
        ob_start();
    }
    if (in_array('wpsc_merchant_paypal_standard', (array) $selected_gateways)) {
        if ($product_id > 0) {
            $post_meta = get_post_meta($product_id, '_wpsc_product_metadata', true);
            $shipping = isset($post_meta['shipping']) ? $post_meta['shipping']['local'] : '';
            $price = get_post_meta($product_id, '_wpsc_price', true);
            $special_price = get_post_meta($product_id, '_wpsc_special_price', true);
            if ($special_price) {
                $price = $special_price;
            }
            if (wpsc_uses_shipping()) {
                $handling = get_option('base_local_shipping');
            } else {
                $handling = $shipping;
            }
            $has_variants = wpsc_product_has_variations($product_id);
            $src = apply_filters('wpsc_buy_now_button_src', _x('https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc'));
            $classes = apply_filters('wpsc_buy_now_button_class', "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}");
            $classes_array = array_map('sanitize_html_class', explode(' ', $classes));
            $classes = implode(' ', $classes_array);
            $button_html = sprintf('<input%1$s class="wpsc-buy-now-button wpsc-buy-now-button-%2$s" type="image" name="submit" border="0" src="%3$s" alt="%4$s" />', disabled($has_variants, true, false), esc_attr($product_id), esc_url($src), esc_attr__('PayPal - The safer, easier way to pay online', 'wpsc'));
            $button_html = apply_filters('wpsc_buy_now_button_html', $button_html, $product_id);
            ?>
			<form class="<?php 
            echo $classes;
            ?>
" id="buy-now-product_<?php 
            echo $product_id;
            ?>
" target="paypal" action="<?php 
            echo esc_url(home_url());
            ?>
" method="post">
				<input type="hidden" name="wpsc_buy_now_callback" value="1" />
				<input type="hidden" name="product_id" value="<?php 
            echo esc_attr($product_id);
            ?>
" />
<?php 
            if ($has_variants) {
                // grab the variation form fields here
                $wpsc_variations = new wpsc_variations($product_id);
                while (wpsc_have_variation_groups()) {
                    wpsc_the_variation_group();
                    printf('<input type="hidden" class="variation-value" name="variation[%1$d]" id="%2$s" value="0"/>', wpsc_vargrp_id(), wpsc_vargrp_form_id());
                }
            }
            /* END wpsc_product_has_variations */
            ?>
				<?php 
            if (get_option('multi_add')) {
                ?>
					<label for="quantity"><?php 
                esc_html_e('Quantity', 'wpsc');
                ?>
</label>
					<input type="text" size="4" id="quantity" name="quantity" value="" /><br />
				<?php 
            } else {
                ?>
					<input type="hidden" name="quantity" value="1" />
				<?php 
            }
            ?>
				<?php 
            echo $button_html;
            ?>
				<img alt='' border='0' width='1' height='1' src='<?php 
            echo esc_url(_x('https://www.paypal.com/en_US/i/scr/pixel.gif', 'PayPal Pixel', 'wpsc'));
            ?>
' />
			</form>
			<?php 
        }
    }
    if ($replaced_shortcode) {
        return ob_get_clean();
    }
}
Ejemplo n.º 7
0
/**
 * add_to_cart function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpsc_add_to_cart()
{
    global $wpsc_cart;
    $default_parameters = $cart_messages = $provided_parameters = array();
    /// default values
    $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;
    $post_type_object = get_post_type_object('wpsc-product');
    $permitted_post_statuses = current_user_can($post_type_object->cap->edit_posts) ? apply_filters('wpsc_product_display_status', array('publish')) : array('publish');
    /// sanitise submitted values
    $product_id = apply_filters('wpsc_add_to_cart_product_id', (int) $_POST['product_id']);
    $product = apply_filters('wpsc_add_to_cart_product_object', get_post($product_id, OBJECT, 'display'));
    if (!in_array($product->post_status, $permitted_post_statuses) || 'wpsc-product' != $product->post_type) {
        return false;
    }
    // compatibility with older themes
    if (isset($_POST['wpsc_quantity_update']) && is_array($_POST['wpsc_quantity_update'])) {
        $_POST['wpsc_quantity_update'] = $_POST['wpsc_quantity_update'][$product_id];
    }
    if (isset($_POST['variation'])) {
        foreach ((array) $_POST['variation'] as $key => $variation) {
            $provided_parameters['variation_values'][(int) $key] = (int) $variation;
        }
        if (count($provided_parameters['variation_values']) > 0) {
            $variation_product_id = wpsc_get_child_object_in_terms($product_id, $provided_parameters['variation_values'], 'wpsc-variation');
            if ($variation_product_id > 0) {
                $product_id = $variation_product_id;
            }
        }
    }
    if (isset($_POST['quantity']) && $_POST['quantity'] > 0 && !isset($_POST['wpsc_quantity_update'])) {
        $provided_parameters['quantity'] = (int) $_POST['quantity'];
    } else {
        if (isset($_POST['wpsc_quantity_update'])) {
            $wpsc_cart->remove_item($_POST['key']);
            $provided_parameters['quantity'] = (int) $_POST['wpsc_quantity_update'];
        }
    }
    if (isset($_POST['is_customisable']) && 'true' == $_POST['is_customisable']) {
        $provided_parameters['is_customisable'] = true;
        if (isset($_POST['custom_text'])) {
            $provided_parameters['custom_message'] = stripslashes($_POST['custom_text']);
        }
        if (isset($_FILES['custom_file'])) {
            $provided_parameters['file_data'] = $_FILES['custom_file'];
        }
    }
    if (isset($_POST['donation_price']) && (double) $_POST['donation_price'] > 0) {
        $provided_parameters['provided_price'] = (double) $_POST['donation_price'];
    }
    $parameters = array_merge($default_parameters, (array) $provided_parameters);
    $cart_item = $wpsc_cart->set_item($product_id, $parameters);
    if (is_object($cart_item)) {
        do_action('wpsc_add_to_cart', $product, $cart_item);
        $cart_messages[] = str_replace("[product_name]", $cart_item->get_title(), __('You just added "[product_name]" to your cart.', 'wpsc'));
    } else {
        if ($parameters['quantity'] <= 0) {
            $cart_messages[] = __('Sorry, but you cannot add zero items to your cart', 'wpsc');
        } else {
            if (wpsc_product_has_variations($product_id) && is_null($parameters['variation_values'])) {
                $cart_messages[] = apply_filters('wpsc_add_to_cart_variation_missing_message', sprintf(__('This product has several options to choose from.<br /><br /><a href="%s" style="display:inline; float:none; margin: 0; padding: 0;">Visit the product page</a> to select options.', 'wpsc'), esc_url(get_permalink($product_id))), $product_id);
            } else {
                if ($wpsc_cart->get_remaining_quantity($product_id, $parameters['variation_values'], $parameters['quantity']) > 0) {
                    $quantity = $wpsc_cart->get_remaining_quantity($product_id, $parameters['variation_values'], $parameters['quantity']);
                    $cart_messages[] = sprintf(_n('Sorry, but there is only %s of this item in stock.', 'Sorry, but there are only %s of this item in stock.', $quantity, 'wpsc'), $quantity);
                } else {
                    $cart_messages[] = apply_filters('wpsc_add_to_cart_out_of_stock_message', __('Sorry, but this item is out of stock.', 'wpsc'), $product_id);
                }
            }
        }
    }
    if (defined('DOING_AJAX') && DOING_AJAX) {
        $json_response = array('cart_messages' => $cart_messages, 'product_id' => $product_id, 'cart_total' => wpsc_cart_total());
        $output = _wpsc_ajax_get_cart(false, $cart_messages);
        $json_response = $json_response + $output;
        if (is_numeric($product_id) && 1 == get_option('fancy_notifications')) {
            $json_response['fancy_notification'] = str_replace(array("\n", "\r"), array('\\n', '\\r'), fancy_notification_content($cart_messages));
        }
        $json_response = apply_filters('wpsc_add_to_cart_json_response', $json_response);
        die(json_encode($json_response));
    }
}
Ejemplo n.º 8
0
function wpsc_product_delivery_forms()
{
    $has_variations = wpsc_product_has_variations(get_post()->ID);
    $show_if_variation = $has_variations ? 'display: block;' : 'display:none;';
    ?>
	<em id="wpsc_product_delivery_metabox_live_title" class="wpsc_metabox_live_title">
		<p></p>
	</em>

	<div id="wpsc_product_delivery_forms" class="categorydiv wpsc-categorydiv">
		<ul id="wpsc_product_delivery_tabs" class="category-tabs">
			<li class="tabs"><a href="#wpsc_product_delivery-shipping"><?php 
    _e('Shipping', 'wp-e-commerce');
    ?>
</a></li>
			<li><a href="#wpsc_product_delivery-download"><?php 
    _e('Download', 'wp-e-commerce');
    ?>
</a></li>
			<li><a href="#wpsc_product_delivery-external_link"><?php 
    _e('External Link', 'wp-e-commerce');
    ?>
</a></li>
		</ul>

		<div id="wpsc_product_delivery-shipping" class="tabs-panel" style="display:block;">
			<?php 
    if (!$has_variations) {
        wpsc_product_shipping_forms();
    } else {
        echo '<p>' . sprintf(__('This product has variations. To edit the shipping, please use the <a href="%s">Variation Controls</a>.', 'wp-e-commerce'), '#wpsc_product_variation_forms') . '</p>';
    }
    ?>
		</div>

		<div id="wpsc_product_delivery-download" class="tabs-panel" style="display:none;">
			<?php 
    wpsc_product_download_forms();
    ?>
		</div>

		<div id="wpsc_product_delivery-external_link" class="tabs-panel" style="display: none;">
			<?php 
    wpsc_product_external_link_forms();
    ?>
		</div>
	</div>
<?php 
}
Ejemplo n.º 9
0
/**
* wpsc_product_has_children function
* Checks whether a product has variations or not
*
* @return boolean true if product does have variations, false otherwise
*/
function wpsc_product_has_children($id, $exclude_unpublished = true)
{
    return wpsc_product_has_variations($id);
}
Ejemplo n.º 10
0
 public function add($product_id)
 {
     global $wpsc_cart;
     if (!wp_verify_nonce($_REQUEST['_wp_nonce'], "wpsc-add-to-cart-{$product_id}")) {
         wp_die(__('Request expired. Please try adding the item to your cart again.', 'wpsc'));
     }
     extract($_REQUEST, EXTR_SKIP);
     $defaults = array('variation_values' => array(), 'quantity' => 1, 'provided_price' => null, 'comment' => null, 'time_requested' => null, 'custom_message' => null, 'file_data' => null, 'is_customisable' => false, 'meta' => null);
     $provided_parameters = array();
     $product_id = apply_filters('wpsc_add_to_cart_product_id', (int) $product_id);
     if (!empty($wpsc_product_variations)) {
         foreach ($wpsc_product_variations as $key => $variation) {
             $provided_parameters['variation_values'][(int) $key] = (int) $variation;
         }
         $variation_product_id = wpsc_get_child_object_in_terms($product_id, $provided_parameters['variation_values'], 'wpsc-variation');
         if ($variation_product_id > 0) {
             $product_id = $variation_product_id;
         }
     }
     if (!empty($quantity)) {
         $provided_parameters['quantity'] = (int) $quantity;
     }
     if (!empty($is_customisable)) {
         $provided_parameters['is_customisable'] = true;
         if (isset($custom_text)) {
             $provided_parameters['custom_message'] = $custom_text;
         }
         if (isset($_FILES['custom_file'])) {
             $provided_parameters['file_data'] = $_FILES['custom_file'];
         }
     }
     if (isset($donation_price) && (double) $donation_price > 0) {
         $provided_parameters['provided_price'] = (double) $donation_price;
     }
     $parameters = array_merge($defaults, $provided_parameters);
     if ($parameters['quantity'] <= 0) {
         $this->message_collection->add(__('Sorry, but the quantity you just entered is not valid. Please try again.', 'wpsc'), 'error', 'main', 'flash');
         return;
     }
     $product = apply_filters('wpsc_add_to_cart_product_object', get_post($product_id, OBJECT, 'display'));
     $stock = get_post_meta($product_id, '_wpsc_stock', true);
     $remaining_quantity = $wpsc_cart->get_remaining_quantity($product_id, $parameters['variation_values']);
     if ($stock !== '' && $remaining_quantity !== true) {
         if ($remaining_quantity <= 0) {
             $message = apply_filters('wpsc_add_to_cart_out_of_stock_message', __('Sorry, the product "%s" is out of stock.', 'wpsc'));
             $this->message_collection->add(sprintf($message, $product->post_title), 'error', 'main', 'flash');
             wp_safe_redirect(wp_get_referer());
             exit;
         } elseif ($remaining_quantity < $parameters['quantity']) {
             $message = __('Sorry, but the quantity you just specified is larger than the available stock. There are only %d of the item in stock.', 'wpsc');
             $this->message_collection->add(sprintf($message, $remaining_quantity), 'error', 'main', 'flash');
             wp_safe_redirect(wp_get_referer());
             exit;
         }
     }
     if (wpsc_product_has_variations($product_id) && is_null($parameters['variation_values'])) {
         $message = apply_filters('wpsc_add_to_cart_variation_missing_message', sprintf(__('This product has several options to choose from.<br /><br /><a href="%s" style="display:inline; float:none; margin: 0; padding: 0;">Visit the product page</a> to select options.', 'wpsc'), esc_url(get_permalink($product_id))), $product_id);
         $this->message_collection->add(sprintf($message, $product->post_title), 'error', 'main', 'flash');
         wp_safe_redirect(wp_get_referer());
         exit;
     }
     if ($wpsc_cart->set_item($product_id, $parameters)) {
         $message = sprintf(__('You just added %s to your cart.', 'wpsc'), $product->post_title);
         $this->message_collection->add($message, 'success', 'main', 'flash');
         wp_safe_redirect(wpsc_get_cart_url());
         exit;
     } else {
         $this->message_collection->add(__('An unknown error just occured. Please contact the shop administrator.', 'wpsc'), 'error', 'main', 'flash');
         wp_safe_redirect(wp_get_referer());
         exit;
     }
 }
function wpsc_product_price_and_stock_forms($product_data = '')
{
    global $closed_postboxes, $wpdb, $variations_processor;
    $table_rate_price = get_product_meta($product_data['id'], 'table_rate_price');
    $custom_tax = get_product_meta($product_data['id'], 'custom_tax');
    if ($product_data == 'empty') {
        $display = "style='visibility:hidden;'";
    }
    echo "<div id='wpsc_product_price_and_stock_forms' class='wpsc_product_price_and_stock_forms postbox " . (array_search('wpsc_product_price_and_stock_forms', $product_data['closed_postboxes']) !== false ? 'closed' : '') . "' " . (array_search('wpsc_product_price_and_stock_forms', $product_data['hidden_postboxes']) !== false ? 'style="display: none;"' : '') . " >";
    echo "<h3 class='hndle'>";
    echo __('Price and Stock Control', 'wpsc');
    echo "\n\t</h3>\n    <div class='inside'>\n    <table>\n    ";
    echo "\n    <tr>\n       <td>\n          <input id='add_form_tax' type='checkbox' name='notax' value='yes' " . ($product_data['notax'] == 1 ? 'checked="checked"' : '') . "/>&nbsp;<label for='add_form_tax'>" . sprintf(__('Do not include tax (tax is set in <a href="%s"/wp-admin/admin.php?page=wpsc-settings">shop config</a>)', 'wpsc'), get_option("siteurl")) . "</label>\n       </td>\n    </tr>";
    echo "\n    <tr>\n\n       <td>\n          <input id='add_form_donation' type='checkbox' name='donation' value='yes' " . ($product_data['donation'] == 1 ? 'checked="checked"' : '') . " />&nbsp;<label for='add_form_donation'>" . __('This is a donation, checking this box populates the donations widget.', 'wpsc') . "</label>\n       </td>\n    </tr>";
    ?>
     <tr>
      <td>
        <input type='checkbox' value='1' name='table_rate_price' id='table_rate_price'  <?php 
    echo count($table_rate_price['quantity']) > 0 ? 'checked=\'checked\'' : '';
    ?>
 <?php 
    echo wpsc_product_has_variations($product_data['id']) ? 'disabled=\'disabled\'' : '';
    ?>
 />
        <label for='table_rate_price'><?php 
    echo __('Table Rate Price', 'wpsc');
    ?>
</label>
        <div style='display:<?php 
    echo $table_rate_price != '' && !wpsc_product_has_variations($product_data['id']) ? 'block' : 'none';
    ?>
;' id='table_rate'>
          <a class='add_level' style='cursor:pointer;'>+ Add level</a><br />
          <table>
						<tr>
							<td><?php 
    echo __('Quantity In Cart', 'wpsc');
    ?>
</td>
							<td><?php 
    echo __('Discounted Price', 'wpsc');
    ?>
</td>
						</tr>
						<?php 
    if (count($table_rate_price) > 0) {
        foreach ((array) $table_rate_price['quantity'] as $key => $qty) {
            if ($qty != '') {
                ?>
									<tr>
										<td>
											<input type="text" size="10" value="<?php 
                echo $qty;
                ?>
" name="productmeta_values[table_rate_price][quantity][]"/> and above
										</td>
										<td>
											<input type="text" size="10" value="<?php 
                echo $table_rate_price['table_price'][$key];
                ?>
" name="productmeta_values[table_rate_price][table_price][]" />
										</td>
										<td><img src="<?php 
                echo WPSC_URL;
                ?>
/images/cross.png" class="remove_line" /></td>
									</tr>
									<?php 
            }
        }
    }
    ?>
						
						<tr>
							<td><input type='text' size='10' value='' name='productmeta_values[table_rate_price][quantity][]'/> and above</td>
							<td><input type='text' size='10' value='' name='productmeta_values[table_rate_price][table_price][]'/></td>
						</tr>
          </table>
        </div>
      </td>
    </tr>


    
     <tr>
      <td>
        <input type='checkbox' value='1' name='custom_tax' id='custom_tax_checkbox'  <?php 
    echo is_numeric($custom_tax) > 0 ? 'checked=\'checked\'' : '';
    ?>
  />
        <label for='custom_tax_checkbox'><?php 
    echo _e("Custom Tax Rate", 'wpsc');
    ?>
</label>
        <div style='display:<?php 
    echo is_numeric($custom_tax) ? 'block' : 'none';
    ?>
;' id='custom_tax'>
					<input type='text' size='10' value='<?php 
    echo $custom_tax;
    ?>
' name='productmeta_values[custom_tax]'/>
        </div>
      </td>
    </tr>


    
    <?php 
    echo "\n    <tr>\n      <td style='width:430px;'>\n      <input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' " . ($product_data['quantity_limited'] == 1 ? 'checked="checked"' : '') . " name='quantity_limited'/>";
    //onclick='hideelement(\"add_stock\")'
    echo "&nbsp;<label for='add_form_quantity_limited' class='small'>" . __('I have a limited number of this item in stock. If the stock runs out, this product will not be available on the shop unless you untick this box or add more stock.', 'wpsc') . "</label>";
    if ($product_data['id'] > 0) {
        $variations_output = $variations_processor->variations_grid_view($product_data['id']);
        if (wpsc_product_has_variations($product_data['id'])) {
            switch ($product_data['quantity_limited']) {
                case 1:
                    echo "            <div class='edit_stock' style='display: block;'>\n\r";
                    break;
                default:
                    echo "            <div class='edit_stock' style='display: none;'>\n\r";
                    break;
            }
            echo "<input class='stock_limit_quantity' name='quantity' style='display:none;' value='" . $product_data['quantity'] . "' />";
            echo "<div style='font-size:9px; padding:5px;'><input type='checkbox' " . $unpublish_oos . " class='inform_when_oos' name='inform_when_oos' /> " . __('If this product runs out of stock set status to Unpublished & email site owner', 'wpsc') . "</div>";
            echo "</div>\n\r";
        } else {
            switch ($product_data['quantity_limited']) {
                case 1:
                    echo "            <div class='edit_stock' style='display: block;'>\n\r";
                    break;
                default:
                    echo "            <div class='edit_stock' style='display: none;'>\n\r";
                    break;
            }
            echo "<p><strong class='wpsc_error'>" . __('Note: If you are using variations please ensure you populate the stock under "Variation Control"', 'wpsc') . "</strong></p>";
            echo __('Stock Qty', 'wpsc') . " <input type='text' class='stock_limit_quantity' name='quantity' size='10' value='" . $product_data['quantity'] . "' />";
            echo "<div style='font-size:9px; padding:5px;'><input type='checkbox' " . $unpublish_oos . " class='inform_when_oos' name='inform_when_oos' /> " . __('If this product runs out of stock set status to Unpublished & email site owner', 'wpsc') . "</div>";
            echo "              </div>\n\r";
        }
    } else {
        echo "\n\t\t\t\t\t<div style='display: none;' class='edit_stock'>\n\t\t\t\t\t\t";
        echo "<p><strong class='wpsc_error'>" . __('Note: If you are using variations please ensure you populate the stock under "Variation Control"', 'wpsc') . "</strong></p>";
        echo __('Stock Qty', 'wpsc') . " <input type='text' name='quantity' value='0' size='10' />";
        echo "<div style='font-size:9px; padding:5px;'><input type='checkbox' class='inform_when_oos' name='inform_when_oos' /> " . __('If this product runs out of stock set status to Unpublished & email site owner', 'wpsc') . "</div>";
        echo "</div>";
    }
    echo "\n\t\t\t\t\n\t\t\t\t</td>\n\t\t\t</tr>";
    echo "\n\t\t</table>\n\t</div>\n</div>";
    //return $output;
}
Ejemplo n.º 12
0
 public function send_product()
 {
     if (wpsc_is_single_product()) {
         $product = array();
         while (wpsc_have_products()) {
             wpsc_the_product();
             $product_id = (int) wpsc_the_product_id();
             $product['url'] = (string) wpsc_the_product_permalink();
             $product['product_id'] = $product_id;
             $product['name'] = (string) wpsc_the_product_title();
             $product['image_url'] = (string) wpsc_the_product_image('', '', $product_id);
             if (wpsc_product_has_variations($product_id)) {
                 $price = $this->get_lowest_product_variation_price($product_id);
             } else {
                 $price = wpsc_calculate_price($product_id, false, true);
             }
             $product['price'] = $this->format_price($price);
             if (wpsc_product_has_stock($product_id)) {
                 $product['stock'] = 1;
             } else {
                 $product['stock'] = 0;
             }
             $product['categories'] = array();
             $category_terms = wp_get_product_categories($product_id);
             foreach ($category_terms as $category_term) {
                 $category_path = $category_term;
                 if (!empty($category_path)) {
                     $product['category_name'] = $category_term->name;
                     $product['category_id'] = $category_term->term_id;
                 }
             }
             if (wpsc_product_has_variations($product_id)) {
                 $list_price = $this->get_lowest_product_variation_price($product_id);
             } else {
                 $list_price = wpsc_calculate_price($product_id, false, false);
             }
             $product['list_price'] = $this->format_price($list_price);
         }
         if (!empty($product)) {
             $this->render('sendProduct', array('product' => $product));
         }
     }
 }
Ejemplo n.º 13
0
function wpsc_meta_boxes()
{
    global $post;
    $pagename = 'wpsc-product';
    remove_meta_box('wpsc-variationdiv', 'wpsc-product', 'side');
    //if a variation page do not show these metaboxes
    if (is_object($post) && $post->post_parent == 0) {
        add_meta_box('wpsc_product_variation_forms', __('Variations', 'wpsc'), 'wpsc_product_variation_forms', $pagename, 'normal', 'high');
        add_meta_box('wpsc_product_external_link_forms', __('Off Site Product link', 'wpsc'), 'wpsc_product_external_link_forms', $pagename, 'normal', 'high');
    } else {
        if (is_object($post) && $post->post_status == "inherit") {
            remove_meta_box('tagsdiv-product_tag', 'wpsc-product', 'core');
            remove_meta_box('wpsc_product_external_link_forms', 'wpsc-product', 'core');
            remove_meta_box('wpsc_product_categorydiv', 'wpsc-product', 'core');
        }
    }
    add_meta_box('wpsc_price_control_forms', __('Price Control', 'wpsc'), 'wpsc_price_control_forms', $pagename, 'side', 'low');
    add_meta_box('wpsc_stock_control_forms', __('Stock Control', 'wpsc'), 'wpsc_stock_control_forms', $pagename, 'side', 'low');
    add_meta_box('wpsc_product_taxes_forms', __('Taxes', 'wpsc'), 'wpsc_product_taxes_forms', $pagename, 'side', 'low');
    add_meta_box('wpsc_additional_desc', __('Additional Description', 'wpsc'), 'wpsc_additional_desc', $pagename, 'normal', 'high');
    add_meta_box('wpsc_product_download_forms', __('Product Download', 'wpsc'), 'wpsc_product_download_forms', $pagename, 'normal', 'high');
    add_meta_box('wpsc_product_image_forms', __('Product Images', 'wpsc'), 'wpsc_product_image_forms', $pagename, 'normal', 'high');
    if (!empty($post->ID) && !wpsc_product_has_variations($post->ID)) {
        add_meta_box('wpsc_product_shipping_forms', __('Shipping', 'wpsc'), 'wpsc_product_shipping_forms_metabox', $pagename, 'normal', 'high');
    }
    add_meta_box('wpsc_product_advanced_forms', __('Advanced Settings', 'wpsc'), 'wpsc_product_advanced_forms', $pagename, 'normal', 'high');
}