Advertisement
KidCache

jigoshop_template_functions.php

Oct 16th, 2012
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.77 KB | None | 0 0
  1. if (!function_exists('jigoshop_variable_add_to_cart')) {
  2.     function jigoshop_variable_add_to_cart() {
  3.  
  4.         global $post, $_product;
  5.         $jigoshop_options = Jigoshop_Base::get_options();
  6.        
  7.         $attributes = $_product->get_available_attributes_variations();
  8.  
  9.         //get all variations available as an array for easy usage by javascript
  10.         $variationsAvailable = array();
  11.         $children = $_product->get_children();
  12.  
  13.         foreach($children as $child) {
  14.             /* @var $variation jigoshop_product_variation */
  15.             $variation = $_product->get_child( $child );
  16.             if($variation instanceof jigoshop_product_variation) {
  17.                 $vattrs = $variation->get_variation_attributes();
  18.                 $availability = $variation->get_availability();
  19.  
  20.                 //@todo needs to be moved to jigoshop_product_variation class
  21.                 if (has_post_thumbnail($variation->get_variation_id())) {
  22.                     $attachment_id = get_post_thumbnail_id( $variation->get_variation_id() );
  23.                     $large_thumbnail_size = apply_filters('single_product_large_thumbnail_size', 'shop_large');
  24.                     $image = wp_get_attachment_image_src( $attachment_id, $large_thumbnail_size);
  25.                     if ( ! empty( $image ) ) $image = $image[0];
  26.                     $image_link = wp_get_attachment_image_src( $attachment_id, 'full');
  27.                     if ( ! empty( $image_link ) ) $image_link = $image_link[0];
  28.                 } else {
  29.                     $image = '';
  30.                     $image_link = '';
  31.                 }
  32.  
  33.                 $a_weight = $a_length = $a_width = $a_height = '';
  34.  
  35.                 if ( $variation->get_weight() ) {
  36.                     $a_weight = '
  37.                         <tr class="weight">
  38.                             <th>Weight</th>
  39.                             <td>'.$variation->get_weight().$jigoshop_options->get_option('jigoshop_weight_unit').'</td>
  40.                         </tr>';
  41.                 }
  42.  
  43.                 if ( $variation->get_length() ) {
  44.                     $a_length = '
  45.                         <tr class="length">
  46.                             <th>Length</th>
  47.                             <td>'.$variation->get_length().$jigoshop_options->get_option('jigoshop_dimension_unit').'</td>
  48.                         </tr>';
  49.                 }
  50.  
  51.                 if ( $variation->get_width() ) {
  52.                     $a_width = '
  53.                         <tr class="width">
  54.                             <th>Width</th>
  55.                             <td>'.$variation->get_width().$jigoshop_options->get_option('jigoshop_dimension_unit').'</td>
  56.                         </tr>';
  57.                 }
  58.  
  59.                 if ( $variation->get_height() ) {
  60.                     $a_height = '
  61.                         <tr class="height">
  62.                             <th>Height</th>
  63.                             <td>'.$variation->get_height().$jigoshop_options->get_option('jigoshop_dimension_unit').'</td>
  64.                         </tr>
  65.                     ';
  66.                 }
  67.  
  68.                 $variationsAvailable[] = array(
  69.                     'variation_id'     => $variation->get_variation_id(),
  70.                     'sku'              => '<div class="sku">'.__('SKU','jigoshop').': ' . $variation->get_sku() . '</div>',
  71.                     'attributes'       => $vattrs,
  72.                     'in_stock'         => $variation->is_in_stock(),
  73.                     'image_src'        => $image,
  74.                     'image_link'       => $image_link,
  75.                     'price_html'       => '<span class="price">'.$variation->get_price_html().'</span>',
  76.                     'availability_html'=> '<p id="bottomStock" class="stock ' . esc_attr( $availability['class'] ) . '"><span class="stockReg">Variation is:</span> '. $availability['availability'].'</p>',
  77.                     'a_weight'         => $a_weight,
  78.                     'a_length'         => $a_length,
  79.                     'a_width'          => $a_width,
  80.                     'a_height'         => $a_height,
  81.                 );
  82.             }
  83.         }
  84.  
  85.         ?>
  86.         <script type="text/javascript">
  87.             var product_variations = <?php echo json_encode($variationsAvailable) ?>;
  88.         </script>
  89.         <form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="variations_form cart" method="post">
  90.             <fieldset class="variations">
  91.                 <?php foreach ( $attributes as $name => $options ): ?>
  92.                     <?php $sanitized_name = sanitize_title( $name ); ?>
  93.                     <div>
  94.                         <span class="select_label"><?php echo jigoshop_product::attribute_label('pa_'.$name); ?></span>
  95.                         <select id="<?php echo esc_attr( $sanitized_name ); ?>" name="tax_<?php echo $sanitized_name; ?>">
  96.                             <option value=""><?php echo __('Choose an option ', 'jigoshop') ?>&hellip;</option>
  97.                             <?php foreach ( $options as $value ) : ?>
  98.                                 <?php if ( taxonomy_exists( 'pa_'.$sanitized_name )) : ?>
  99.                                     <?php $term = get_term_by( 'slug', $value, 'pa_'.$sanitized_name ); ?>
  100.                                     <option value="<?php echo esc_attr( $term->slug ); ?>"><?php echo $term->name; ?></option>
  101.                                 <?php else : ?>
  102.                                     <option value="<?php echo esc_attr( sanitize_title( $value ) ); ?>"><?php echo $value; ?></option>
  103.                                 <?php endif;?>
  104.                             <?php endforeach; ?>
  105.                         </select>
  106.                     </div>
  107.                 <?php endforeach;?>
  108.             </fieldset>
  109.             <div class="single_variation"></div>
  110.             <?php do_action('jigoshop_before_add_to_cart_form_button'); ?>
  111.             <div class="variations_button" style="display:none;">
  112.                 <input type="hidden" name="variation_id" value="" />
  113.                 <input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
  114.                 <input type="hidden" name="customer_design" id="customer_design" value="" />
  115.                 <div class="quantity"><input name="quantity" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
  116.                 <input type="submit" class="button-alt" value="<?php esc_html_e('Order Case', 'jigoshop'); ?>" />
  117.             </div>
  118.             <?php do_action('jigoshop_add_to_cart_form'); ?>
  119.         </form>
  120.         <?php
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement