public function list_import_product_to_json_data($data) { //new a new receipt //basically, a Reiceipt is a list of product... $receipt = new Receipt(); foreach ($data as $value) { //new Product $product = new ImportProduct($value['Import_Price']); // add attribute to it $product->add_attribute($value['Name'], new Unit($value['UnitName'], $value['Price']), $value['Id'], $value['ProductId']); //add the product to the receipt $receipt->add($product); } // return the receipt in json format return $receipt->json_encode(); }
function push_new_product_data_to_server($array) { if (sizeof($array) == 0) { return; } $receipt = new Receipt(); foreach ($array as $key => $product) { if (isset($product['name'])) { $import_product = new ImportProduct($product['bought']); $import_product->add_attribute($product['name'], new Unit($product['unit_name'], $product['sale'])); $receipt->add($import_product); } } echo $receipt->json_encode(true); $manage = new Management(); $manage->push_new_product_data_to_server($receipt); }