function add_to_cart($image_id, $product_id, $qty, $price_level, $comments = '', $type = '', $extra = '')
 {
     $current_cart = $this->content;
     $image_id = intval($image_id);
     $product_id = intval($product_id);
     $qty = intval($qty);
     $price_level = intval($price_level);
     if ($image_id > 0) {
         $image = get_post($image_id);
         $gallery_id = $image->post_parent;
     }
     $item = array('image_id' => $image_id, 'gallery_id' => $gallery_id, 'product_id' => $product_id, 'price_level' => $price_level, 'qty' => $qty, 'price' => $this->get_product_price($product_id, $price_level, false), 'shipping' => get_post_meta($product_id, 'sunshine_product_shipping', true), 'comments' => $comments, 'type' => $type ? $type : 'image', 'hash' => md5(time()));
     if (is_array($extra)) {
         $item = array_merge($item, $extra);
     }
     $item = apply_filters('sunshine_add_to_cart_item', $item);
     // Check if item is in cart already. If so, increase quantity instead of adding new line item
     if (is_array($current_cart)) {
         foreach ($current_cart as $key => &$cart_item) {
             if ($image_id == $cart_item['image_id'] && $product_id == $cart_item['product_id']) {
                 if (apply_filters('sunshine_add_to_cart_increment_qty', true, $cart_item, $item)) {
                     $item = $cart_item;
                     // Make current item the existing cart item
                     $item['qty'] = $cart_item['qty'] + $qty;
                     SunshineUser::delete_user_meta('cart', $cart_item);
                     unset($current_cart[$key]);
                 }
             }
         }
     }
     $item['total'] = $item['price'] * $item['qty'];
     // Add item to the current cart
     $current_cart[] = $item;
     // Update to current cart
     $this->content = $current_cart;
     $this->set_item_count();
     $this->set_subtotal();
     // Set user cart values
     if (is_user_logged_in()) {
         $result = SunshineUser::add_user_meta('cart', $item, false);
     } else {
         $this->set_cart_cookies(true, 'add_to_cart');
     }
     do_action('sunshine_add_cart_item', $item);
     return true;
 }
function sunshine_add_favorite($image_id)
{
    $image_id = intval($image_id);
    $favorites = SunshineUser::get_user_meta('favorite', false);
    if (in_array($image_id, $favorites)) {
        return;
    }
    SunshineUser::add_user_meta('favorite', $image_id, false);
    $favorite_count = get_post_meta($image_id, 'sunshine_favorite_count', true);
    $favorite_count++;
    update_post_meta($image_id, 'sunshine_favorite_count', $favorite_count);
    do_action('sunshine_add_favorite', $image_id);
}