function getPricingHistory($upc, $storeID, $type, $dateFrom, $dateTo) { $CI =& get_instance(); $priceHistory = array(); $pd = getProductIdByUPC($upc, $storeID); if (count($pd) < 1) { return $priceHistory; } //we should be getting exact time values - so don't do 24 hour day period /*$dateFrom = $date." 00:00:00"; $dateTo = $date." 23:59:59";*/ //pull original record from products table for camparison $query = 'select ' . $type . ', created_at from products WHERE id = \'' . $pd['id'] . '\''; $prodPricing = $CI->db->query($query)->result(); //use the record if applicable if (count($prodPricing) == 1 && ($prodPricing[0]->created_at > $dateFrom && $prodPricing[0]->created_at < $dateTo)) { $priceHistory[] = array('start' => $prodPricing[0]->created_at, 'stamp' => $prodPricing[0]->created_at != '0000-00-00 00:00:00' ? strtotime($prodPricing[0]->created_at) : 0, 'price' => (double) $prodPricing[0]->{$type}); } $query = "SELECT pricing_value, pricing_start\n\t\t\tFROM products_pricing\n\t\t\tWHERE product_id = '{$pd['id']}'\n\t\t\t\tAND pricing_type='{$type}'\n\t\t\t\tAND pricing_start BETWEEN '{$dateFrom}' AND '{$dateTo}'\n\t\t\tORDER BY pricing_start ASC"; $ph = $CI->db->query($query)->result(); if (count($ph) > 0) { for ($i = 0, $n = sizeof($ph); $i < $n; $i++) { $priceHistory[] = array('start' => $ph[$i]->pricing_start, 'stamp' => $ph[$i]->pricing_start != '0000-00-00 00:00:00' ? strtotime($ph[$i]->pricing_start) : 0, 'price' => (double) $ph[$i]->pricing_value); } } elseif ($prodPricing[0]->created_at < $dateFrom) { //pull original record from products table - should not already be present in $priceHistory $priceHistory[] = array('start' => $prodPricing[0]->created_at, 'stamp' => $prodPricing[0]->created_at != '0000-00-00 00:00:00' ? strtotime($prodPricing[0]->created_at) : 0, 'price' => (double) $prodPricing[0]->{$type}); } return $priceHistory; }
/** * Handle AJAX inline change to product lookup table. * * Reviewed by Christophe on 10/30/2015. * * @author unknown */ public function update_product_lookup() { $this->load->model('products_m'); $this->_response_type('json'); $upc = $this->input->post('upc'); $this->data->status = FALSE; // First check that this product belongs to the user $product = getProductIdByUPC($upc, $this->store_id); if (!$product) { ajax_return($this->data); } // Now we can make the update $column = $this->input->post('column'); $value = trim($this->input->post('value')); switch ($column) { case 'url': // if URL value is blank, check to see if we have an existing row and delete if ($value == '') { $current_url = $this->input->post('old_value'); $existing_lookup_row = $this->products_m->get_lookup_by_url($upc, $current_url); if (!empty($existing_lookup_row)) { $this->products_m->delete_product_lookup($existing_lookup_row['id']); } } else { //$marketplace_id = 0;//$this->input->post('marketplace_id'); // find the marketplace by the domain name used in the URL entered with the lookup $marketplace_id = $this->Marketplace->get_marketplace_id_by_url($value); if ($marketplace_id == FALSE) { log_message('error', 'update_product_lookup() - marketplace ID not found'); $this->data->status = 'false'; } else { //if (empty($value) OR filter_var($value, FILTER_VALIDATE_URL)) if ($value != '' && !empty($value)) { $product_id = $this->Product->get_product_id_from_upc($upc, $this->store_id); // insert new row or update existing row $this->data->status = $this->Marketplace->set_product_lookup($product_id, $marketplace_id, $value, $upc); log_message('debug', 'set_product_lookup() query: ' . $this->db->last_query()); } else { $this->data->status = 'false'; log_message('error', 'update_product_lookup() - invalid product page URL: ' . $value); } } } break; } }