public static function cc_product_via_api($args, $content) { $form = ''; if ($error_message = CC_Flash_Data::get('api_error')) { $form .= "<p class=\"cc_error\">{$error_message}</p>"; } $product_id = isset($args['id']) ? $args['id'] : false; $product_sku = isset($args['sku']) ? $args['sku'] : false; $display_quantity = isset($args['quantity']) ? $args['quantity'] : 'true'; $display_price = isset($args['price']) ? $args['price'] : 'true'; $display_mode = isset($args['display']) ? $args['display'] : null; if ($form_with_errors = CC_Flash_Data::get($product_sku)) { $form .= $form_with_errors; } else { $product = new CC_Product(); if ($product_sku) { $product->sku = $product_sku; } elseif ($product_id) { $product->id = $product_id; } else { throw new CC_Exception_Product('Unable to add product to cart without know the product sku or id'); } try { $form .= $product->get_order_form($display_quantity, $display_price, $display_mode); } catch (CC_Exception_Product $e) { $form = "Product order form unavailable"; CC_Log::write('Failed to get product order form: ' . $e->getMessage()); } } return $form; }
function cc_auth_product_create() { if ('POST' == $_SERVER['REQUEST_METHOD']) { $post_body = file_get_contents('php://input'); if ($product_data = json_decode($post_body)) { $product = new CC_Product(); // Check for demo product if ('cc-cellerciser' == $product_data->sku) { $content = $product->cellerciser_content(); $excerpt = $product->cellerciser_excerpt(); $post_id = $product->create_post($product_data->sku, $content, $excerpt); $product->attach_cellerciser_images($post_id); } else { // Create a normal product pressed from the cloud $product->create_post($product_data->sku); } } exit; } }