public static function media_fields($form_fields, $attachment)
 {
     if (!isset($_GET['post_id'])) {
         return $form_fields;
     }
     $product_id = $_GET['post_id'];
     if (!$attachment->post_parent) {
         return $form_fields;
     }
     $parent = get_post($attachment->post_parent);
     if ($parent->post_type !== 'wpsc-product') {
         return $form_fields;
     }
     $product_id = $parent->ID;
     if (isset($_GET['tab']) && $_GET['tab'] == 'gallery' && get_post_type($product_id) == 'wpsc-product' && class_exists('wpsc_variations') && wp_attachment_is_image($attachment->ID)) {
         global $wpsc_variations;
         $wpsc_variations = new wpsc_variations($product_id);
         if (wpsc_have_variation_groups()) {
             $form_fields['start_variation'] = array('label' => __('Variations', 'wpsc_dgallery'), 'input' => 'html', 'html' => '<style>.start_variation {border-width:2px 2px 0} .end_variation {border-width:0 2px 2px} .start_variation, .end_variation {border-style:solid ;border-color:#E6DB55;-webkit-border-radius:10px;-moz-border-radius:10px;-o-border-radius:10px; border-radius: 10px;position:relative;}</style>', 'value' => '', 'helps' => __('Upgrade to the PRO version to use this feature.', 'wpsc_dgallery'));
             while (wpsc_have_variation_groups()) {
                 wpsc_the_variation_group();
                 $html = "<style>.in_variations_" . wpsc_vargrp_id() . " {border-width:0 2px;border-style:solid ;border-color:#E6DB55;}</style>";
                 $html .= "<input disabled='disabled' type='checkbox' id='" . $attachment->ID . "_" . wpsc_vargrp_id() . "' name='" . $attachment->ID . "_" . wpsc_vargrp_id() . "' value=''> <label for='" . $attachment->ID . "_" . wpsc_vargrp_id() . "'><strong>" . __('Apply to All', 'wpsc_dgallery') . "</strong></label><br />";
                 while (wpsc_have_variations()) {
                     wpsc_the_variation();
                     if (wpsc_the_variation_id() > 0) {
                         $html .= "&nbsp;- &nbsp; <input disabled='disabled' type='checkbox' id='" . $attachment->ID . "_" . wpsc_vargrp_id() . "_" . wpsc_the_variation_id() . "'> <label for='" . $attachment->ID . "_" . wpsc_vargrp_id() . "_" . wpsc_the_variation_id() . "'>" . esc_html(wpsc_the_variation_name()) . "</label><br />";
                     }
                 }
                 $form_fields['in_variations_' . wpsc_vargrp_id()] = array('label' => esc_html(wpsc_the_vargrp_name()), 'input' => 'html', 'html' => $html, 'value' => '');
             }
             $form_fields['end_variation'] = array('label' => '', 'input' => 'html', 'html' => '&nbsp;', 'value' => '');
         }
     }
     return $form_fields;
 }
        ?>
<br />
							<input type='file' name='custom_file' value=''  />
						</div>
					<?php 
    }
    ?>
					
					
					<?php 
    /** the variation group HTML and loop */
    ?>
					<div class="wpsc_variation_forms">
						<?php 
    while (wpsc_have_variation_groups()) {
        wpsc_the_variation_group();
        ?>
							<p>
								<label for="<?php 
        echo wpsc_vargrp_form_id();
        ?>
"><?php 
        echo wpsc_the_vargrp_name();
        ?>
:</label>
								<?php 
        /** the variation HTML and loop */
        ?>
								<select class='wpsc_select_variation' name="variation[<?php 
        echo wpsc_vargrp_id();
        ?>
					
					<td width="10%">
						<span id="product_price_<?php echo wpsc_the_product_id(); ?>" class="pricedisplay"><?php echo wpsc_the_product_price(); ?></span>
					</td>
					
					<td width="20%">
						<?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
							<?php	$action =  wpsc_product_external_link(wpsc_the_product_id()); ?>
						<?php else: ?>
							<?php	$action =  wpsc_this_page_url(); ?>						
						<?php endif; ?>
						<form class='product_form'  enctype="multipart/form-data" action="<?php echo $action; ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>">

							<?php /** the variation group HTML and loop */?>
							<div class="wpsc_variation_forms">
								<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
									<p>
										<label for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label>
										<?php /** the variation HTML and loop */?>
										<select class='wpsc_select_variation' name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
										<?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
											<option value="<?php echo wpsc_the_variation_id(); ?>"><?php echo wpsc_the_variation_name(); ?></option>
										<?php endwhile; ?>
										</select>
									</p>
								<?php endwhile; ?>
							</div>
							<?php /** the variation group HTML and loop ends here */?>


Example #4
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();
    }
}
function wpsc_add_to_cart_button($product_id, $return = false)
{
    global $wpdb, $wpsc_variations;
    $output = '';
    if ($product_id > 0) {
        // grab the variation form fields here
        $wpsc_variations = new wpsc_variations($product_id);
        if ($return) {
            ob_start();
        }
        ?>
			<div class='wpsc-add-to-cart-button'>
				<form class='wpsc-add-to-cart-button-form' id='product_<?php 
        echo esc_attr($product_id);
        ?>
' action='' method='post'>
					<?php 
        do_action('wpsc_add_to_cart_button_form_begin');
        ?>
					<div class='wpsc_variation_forms'>
						<?php 
        while (wpsc_have_variation_groups()) {
            wpsc_the_variation_group();
            ?>
							<p>
								<label for='<?php 
            echo wpsc_vargrp_form_id();
            ?>
'><?php 
            echo esc_html(wpsc_the_vargrp_name());
            ?>
:</label>
								<select class='wpsc_select_variation' name='variation[<?php 
            echo wpsc_vargrp_id();
            ?>
]' id='<?php 
            echo wpsc_vargrp_form_id();
            ?>
'>
									<?php 
            while (wpsc_have_variations()) {
                wpsc_the_variation();
                ?>
										<option value='<?php 
                echo wpsc_the_variation_id();
                ?>
' <?php 
                echo wpsc_the_variation_out_of_stock();
                ?>
><?php 
                echo esc_html(wpsc_the_variation_name());
                ?>
</option>
									<?php 
            }
            ?>
								</select>
							</p>
						<?php 
        }
        ?>
					</div>
					<input type='hidden' name='wpsc_ajax_action' value='add_to_cart' />
					<input type='hidden' name='product_id' value='<?php 
        echo $product_id;
        ?>
' />
					<input type='submit' id='product_<?php 
        echo $product_id;
        ?>
_submit_button' class='wpsc_buy_button' name='Buy' value='<?php 
        echo __('Add To Cart', 'wpsc');
        ?>
'  />
					<?php 
        do_action('wpsc_add_to_cart_button_form_end');
        ?>
				</form>
			</div>
		<?php 
        if ($return) {
            return ob_get_clean();
        }
    }
}
Example #6
0
function wpsc_add_to_cart_button($product_id, $replaced_shortcode = false)
{
    global $wpdb, $wpsc_variations;
    if ($product_id > 0) {
        // grab the variation form fields here
        $wpsc_variations = new wpsc_variations($product_id);
        $output .= "<form onsubmit='submitform(this);return false;'  action='' method='post'>";
        /** the variation group HTML and loop */
        $output .= "<div class='wpsc_variation_forms'>";
        while (wpsc_have_variation_groups()) {
            wpsc_the_variation_group();
            $output .= "<p>";
            $output .= "<label for='" . wpsc_vargrp_form_id() . "'>" . wpsc_the_vargrp_name() . ":</label>";
            /** the variation HTML and loop */
            $output .= "<select class='wpsc_select_variation' name='variation[" . wpsc_vargrp_id() . "]' id='" . wpsc_vargrp_form_id() . "'>";
            while (wpsc_have_variations()) {
                wpsc_the_variation();
                $output .= "<option value='" . wpsc_the_variation_id() . "' " . wpsc_the_variation_out_of_stock() . ">" . wpsc_the_variation_name() . "</option>";
            }
            $output .= "</select> ";
            $output .= "</p>";
        }
        $output .= "</div>";
        /** the variation group HTML and loop ends here */
        $output .= "<input type='hidden' name='wpsc_ajax_action' value='add_to_cart' />";
        $output .= "<input type='hidden' name='product_id' value='" . $product_id . "' />";
        $output .= "<input type='hidden' name='item' value='" . $product_id . "' />";
        if (isset($wpsc_theme) && is_array($wpsc_theme) && $wpsc_theme['html'] != '') {
            $output .= $wpsc_theme['html'];
        } else {
            $output .= "<input type='submit' id='product_" . $product['id'] . "_submit_button' class='wpsc_buy_button' name='Buy' value='" . __('Add To Cart', 'wpsc') . "'  />";
        }
        $output .= '</form>';
        if ($replaced_shortcode == true) {
            return $output;
        } else {
            echo $output;
        }
    }
}
Example #7
0
/**
 * Product Specials Widget content function
 *
 * Displays the latest products.
 *
 * @todo Remove marketplace theme specific code and maybe replce with a filter for the image output? (not required if themeable as above)
 *
 * Changes made in 3.8 that may affect users:
 *
 * 1. The product title link text does now not have a bold tag, it should be styled via css.
 * 2. <br /> tags have been ommitted. Padding and margins should be applied via css.
 * 3. Each product is enclosed in a <div> with a 'wpec-special-product' class.
 * 4. The product list is enclosed in a <div> with a 'wpec-special-products' class.
 * 5. Function now expect a single paramter with an array of options (used to be a string which prepended the output).
 */
function wpsc_specials($args = null, $instance)
{
    global $wpdb;
    $args = wp_parse_args((array) $args, array('number' => 5));
    $siteurl = get_option('siteurl');
    if (!($number = (int) $instance['number'])) {
        $number = 5;
    }
    $show_thumbnails = isset($instance['show_thumbnails']) ? (bool) $instance['show_thumbnails'] : FALSE;
    $show_description = isset($instance['show_description']) ? (bool) $instance['show_description'] : FALSE;
    $excludes = wpsc_specials_excludes();
    $args = array('post_type' => 'wpsc-product', 'caller_get_posts' => 1, 'post_status' => 'publish', 'post_parent' => 0, 'post__not_in' => $excludes, 'posts_per_page' => $number);
    $special_products = query_posts($args);
    $output = '';
    $product_ids[] = array();
    if (count($special_products) > 0) {
        list($wp_query, $special_products) = array($special_products, $wp_query);
        // swap the wpsc_query object
        while (wpsc_have_products()) {
            wpsc_the_product();
            if (!in_array(wpsc_the_product_id(), $product_ids)) {
                $product_ids[] = wpsc_the_product_id();
                if ($show_thumbnails) {
                    if (wpsc_the_product_thumbnail()) {
                        ?>
						<a rel="<?php 
                        echo str_replace(array(" ", '"', "'", '&quot;', '&#039;'), array("_", "", "", "", ''), wpsc_the_product_title());
                        ?>
" href="<?php 
                        echo wpsc_the_product_permalink();
                        ?>
">
							<img class="product_image" id="product_image_<?php 
                        echo wpsc_the_product_id();
                        ?>
" alt="<?php 
                        echo wpsc_the_product_title();
                        ?>
" title="<?php 
                        echo wpsc_the_product_title();
                        ?>
" src="<?php 
                        echo wpsc_the_product_thumbnail();
                        ?>
"/>
						</a>
				<?php 
                    } else {
                        ?>
							<a href="<?php 
                        echo wpsc_the_product_permalink();
                        ?>
">
							<img class="no-image" id="product_image_<?php 
                        echo wpsc_the_product_id();
                        ?>
" alt="No Image" title="<?php 
                        echo wpsc_the_product_title();
                        ?>
" src="<?php 
                        echo WPSC_URL;
                        ?>
/wpsc-theme/wpsc-images/noimage.png" width="<?php 
                        esc_attr_e(get_option('product_image_width'));
                        ?>
" height="<?php 
                        esc_attr_e(get_option('product_image_height'));
                        ?>
" />
							</a>
				<?php 
                    }
                    ?>
				<?php 
                }
                // close show thumbnails
                ?>
 
				<br />
				<span id="special_product_price_<?php 
                echo wpsc_the_product_id();
                ?>
">
				<!-- price display -->
				<?php 
                if (wpsc_have_variation_groups()) {
                    while (wpsc_have_variation_groups()) {
                        wpsc_the_variation_group();
                        ?>
								<?php 
                        /** the variation HTML and loop */
                        ?>
								<?php 
                        $variation_outputs = array();
                        ?>
								<?php 
                        while (wpsc_have_variations()) {
                            wpsc_the_variation();
                            ?>
										<?php 
                            $variation_outputs[] = '';
                            $variation_prices[] = wpsc_the_variation_price(true);
                        }
                        // Sort the variations into price order before outputting
                        $data[] = $variation_outputs;
                        $data[] = $variation_prices;
                        array_multisort($data[1], SORT_ASC, SORT_NUMERIC, $data[0], SORT_ASC, SORT_STRING);
                        ?>
						<?php 
                    }
                    echo __('From', 'wpsc') . ' : ' . wpsc_currency_display($data[1][0]);
                    ?>
				<?php 
                } else {
                    ?>
				<?php 
                    echo wpsc_currency_display(wpsc_calculate_price(wpsc_the_product_id(), null, true));
                    ?>
				
				<?php 
                }
                ?>
				</span><br />			
				<strong><a class="wpsc_product_title" href="<?php 
                echo wpsc_product_url(wpsc_the_product_id(), false);
                ?>
"><?php 
                echo wpsc_the_product_title();
                ?>
</a></strong><br /> 
				
				<?php 
                if ($show_description) {
                    ?>
					<div class="wpsc-special-description">
						<?php 
                    echo wpsc_the_product_description();
                    ?>
					</div>									
				<?php 
                }
                // close show description
                ?>
 
			
				<?php 
            }
        }
        list($wp_query, $special_products) = array($special_products, $wp_query);
        // swap the wpsc_query object
        wp_reset_query();
    }
}