3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $product = false; $quantity = 1; $postedOptions = false; $downloads = false; $combine = false; //is this an item from a separate cart being combined? extract($data); if(is_int($product)) { $product = \CI::Products()->getProduct($product); if(!$product) { return json_encode(['error'=>lang('error_product_not_found')]); } //Clean up the product for the orderItems database $product = $this->cleanProduct($product); //get downloadable files $downloads = \CI::DigitalProducts()->getAssociationsByProduct($product->product_id); } $update = false; if(empty($product->hash)) { $product->hash = md5(json_encode($product).json_encode($postedOptions)); //set defaults for new items $product->coupon_discount = 0; $product->coupon_discount_quantity = 0; $product->coupon_code = ''; } else { if(!$combine) { //this is an update $update = true; } } $product->order_id = $this->cart->id; //loop through the products in the cart and make sure we don't have this in there already. If we do get those quantities as well $qty_count = $quantity; $this->getCartItems(); // refresh the cart items foreach($this->items as $item) { if(intval($item->product_id) == intval($product->product_id)) { if($item->hash != $product->hash) //if the hashes match, skip this step (this is an update) { $qty_count = $qty_count + $item->quantity; } } if($item->hash == $product->hash && !$update) //if this is an update skip this step { //if the item is already in the cart, send back a message return json_encode(['message'=>lang('item_already_added'), 'product_id'=>$product->product_id]); } } if(!config_item('allow_os_purchase') && (bool)$product->track_stock) { $stock = \CI::Products()->getProduct($product->product_id); if($stock->quantity < $qty_count) { return json_encode(['error'=>sprintf(lang('not_enough_stock'), $stock->name, $stock->quantity)]); } } if (!$quantity || $quantity <= 0 || $product->fixed_quantity==1) { $product->quantity = 1; } else { $product->quantity = $quantity; } //create save options array here for use later. $saveOptions = []; if(!$update && $product->product_id) // if not an update or non-product, try and run the options { //set the base "total_price" if($product->saleprice > 0) { $product->total_price = $product->saleprice; } else { $product->total_price = $product->price; } //set base "total_weight" $product->total_weight = $product->weight; $productOptions = \CI::ProductOptions()->getProductOptions($product->product_id); //option error vars $optionError = false; $optionErrorMessage = lang('option_error').'<br/>'; foreach($productOptions as $productOption) { // are we missing any required values? $optionValue = false; if(!empty($postedOptions[$productOption->id])) { $optionValue = $postedOptions[$productOption->id]; } if((int)$productOption->required && empty($optionValue)) { $optionError = true; $optionErrorMessage .= "- ". $productOption->name .'<br/>'; continue; // don't bother processing this particular option any further } if(empty($optionValue)) { //empty? Move along, nothing to see here. continue; } //create options to save to the database in case we get past the errors if($productOption->type == 'checklist') { if(is_array($optionValue)) { foreach($optionValue as $ov) { foreach($productOption->values as $productOptionValue) { if($productOptionValue->id == $ov) { $saveOptions[] = [ 'option_name'=>$productOption->name, 'value'=>$productOptionValue->value, 'price'=>$productOptionValue->price, 'weight'=>$productOptionValue->weight ]; $product->total_weight += $productOptionValue->weight; $product->total_price += $productOptionValue->price; } } } } } else //every other form type we support { $saveOption = []; if($productOption->type == 'textfield' || $productOption->type == 'textarea') { $productOptionValue = $productOption->values[0]; $productOptionValue->value = $optionValue; } else //radios and checkboxes { foreach($productOption->values as $ov) { if($ov->id == $optionValue) { $productOptionValue = $ov; break; } } $saveOption['value'] = $optionValue; } if(isset($productOptionValue)) { $saveOption['option_name'] = $productOption->name; $saveOption['price'] = $productOptionValue->price; $saveOption['weight'] = $productOptionValue->weight; $saveOption['value'] = $productOptionValue->value; //add it to the array; $saveOptions[] = $saveOption; //update the total weight and price $product->total_weight += $productOptionValue->weight; $product->total_price += $productOptionValue->price; } } } if($optionError) { return json_encode(['error'=>$optionErrorMessage]); }
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.7
Parse error: syntax error, unexpected end of file in /in/LRTNd on line 203
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected $end in /in/LRTNd:203 Stack trace: #0 {main}
Process exited with code 255.