/** * This function deleted product extra images on EDIT OR DELETE product * @param :: $item_id id of product * $image_path :: JSON FORMATTED image paths * * */ function deleteNotReqProdImages($item_id, $image_path) { if (!empty($item_id)) { $db = JFactory::getDBO(); $query = 'SELECT `images` from `#__kart_items` where `item_id`=' . $item_id; $db->setQuery($query); $dbimages = $db->loadResult(); $productHelper = new productHelper(); // IF NOT EMPTY if (!empty($dbimages)) { $dbImg = array(); $dbImg = json_decode($dbimages, true); $image_path = json_decode($image_path); if (empty($image_path)) { // DELETE ALL IMAGES IF IIMAGE_PATH PARAM IS EMPTY $productHelper = new productHelper(); $productHelper->deletImg($dbImg); } else { // FIND OUT EXTRA IMAGE $delImg = array(); foreach ($dbImg as $img) { if (is_array($image_path) && !in_array($img, $image_path)) { $delImg[] = $img; } $productHelper->deletImg($delImg); } } } } }