<?php
defined('COT_CODE') or die('Wrong URL');

$return['success'] = false;
$return['extras'] = array();

$id = cot_import('item_id', 'P', 'INT');
if($id > 0) {
  require_once cot_incfile('market', 'module');
  require_once cot_incfile('catcostplans', 'plug');

  $item = $db->query("SELECT * FROM $db_market WHERE item_id=".$id.' AND item_state=0 LIMIT 1')->fetch();
  if($item['item_id'] > 0) {
    $item_catcostplans = (!empty($item['item_catcostplans']) ? json_decode($item['item_catcostplans'], 1) : array());
    if(!is_array($item_catcostplans)) $item_catcostplans = array('bundle_type' => 'none');
    if($item_catcostplans['bundle_type'] == "single") {
      if(is_array($item_catcostplans['bundles']['custom'])) foreach($item_catcostplans['bundles']['custom'] as $cust) {
        $priceId = 0;
        $cost = $cust['price'];
        if($cost < 100) {
          $priceId = $cost;
          $cost = $costplans_prices[$priceId];
        }
        $return['extras'][] = array(
          'id' => $cust['id'],
          'name' => $cust['name'],
          'price' => ($cost-$cost*($market_crt/100)),
          'payerPrice' => $cost,
          'duration' => $cust['duration'],
          'priceId' => $priceId
        );
      }
      if(count($return['extras']) > 0) {
        $return['success'] = true;
      }
    }
    $return['test'] = $item_catcostplans;
  }
}

?>
