Advertisement
KidCache

jigoshop_actions.php

Oct 16th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. //variaton wasn't selected but user managed to submit a form
  2.             if (empty($_POST['variation_id']) || !is_numeric($_POST['variation_id'])) {
  3.                 /* Link on product pages */
  4.                 jigoshop::add_error(__('Please choose product options…', 'jigoshop'));
  5.                 wp_redirect(get_permalink($_GET['product']));
  6.                 exit;
  7.             } else {
  8.                 $product_id = apply_filters('jigoshop_product_id_add_to_cart_filter', (int) $_POST['product_id']);
  9.                 $variation_id = (int) $_POST['variation_id'];
  10.                 $customer_design = $_POST['customer_design'];
  11.                 $quantity = 1;
  12.                 if (isset($_POST['quantity'])) {
  13.                     $quantity = (int) $_POST['quantity'];
  14.                 }
  15.    
  16.                 if ( get_post_meta( $product_id , 'customizable', true ) == 'yes' ) {
  17.                     // session personalization initially set to parent product until variation selected
  18.                     $custom_products = (array) jigoshop_session::instance()->customized_products;
  19.                     // transfer it to the variation
  20.                     $custom_products[$variation_id] = $custom_products[$product_id];
  21.                     unset( $custom_products[$product_id] );
  22.                     jigoshop_session::instance()->customized_products = $custom_products;
  23.                 }
  24.                
  25.                 $attributes = (array) maybe_unserialize(get_post_meta($product_id, 'product_attributes', true));
  26.                 $variations = array();
  27.                 $all_variations_set = true;
  28.    
  29.                 foreach ($attributes as $attribute) {
  30.    
  31.                     if ( ! $attribute['variation']) {
  32.                         continue;
  33.                     }
  34.    
  35.                     $attr_name = 'tax_' . sanitize_title($attribute['name']);
  36.                     if (!empty($_POST[$attr_name])) {
  37.                         $variations[$attr_name] = $_POST[$attr_name];
  38.                     } else {
  39.                         $all_variations_set = false;
  40.                     }
  41.                 }
  42.    
  43.                 if ($all_variations_set && $variation_id > 0) { //all variation options are set
  44.                     jigoshop_cart::add_to_cart($product_id, $quantity, $variation_id, $variations, $customer_design);
  45.    
  46.                     $product_added = true;
  47.                 } else {
  48.                     /* Link on product pages */
  49.                     jigoshop::add_error(__('Please choose product options…', 'jigoshop'));
  50.                     wp_redirect(apply_filters('jigoshop_product_id_add_to_cart_filter', get_permalink($_GET['product'])));
  51.                     exit;
  52.                 }
  53.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement