I am working with PHP array to store the comma separated values of product Ids and then in turn use them to show as recent seen products.
Implementation is as below:
$product_data = array();
$array_ids_a_display = array();
$check_status = array();
$array_check= array();
$_COOKIE['Pr'] = [1,2,3,4,5,6,7,8]
Then i am Taking the last point of the stored string
$array_check = explode(',',substr($_COOKIE['IdProduto'],0,-1));
Now, i check of products are enabled then store them into one other array
foreach($array_check as $id_a_checar){
$check_status = $this->model->getProduct($id_a_checar);
if($check_status['status']){ // If status is 1
$array_ids_a_display[$contprods++] = $id_a_checar;
}
}
if($s['limit']>count($array_ids_a_display)){
//If the number of valid products < number of products of module
$s['limit'] = count($array_ids_a_display);
//will show,then reconfigures the number of products that will show
}
}
where $s['limit'] comes from backend , let us say 6 to limit the number of products.
Now, i will reverse the array to get latest visited product at first place like as
$last_ended = array_reverse($array_ids_a_display);
array_splice($last_ended,0,(int)$s['limit']);
foreach ($last_ended as $result) {
$product_data[$result] = $this->product->getProduct($result);
}
Now here comes the problem, as i am only getting 3 products in $product_data array but is shall get 6 products.
I hope that there is issue with array_splice because if i will comment array_splice then i am getting all stores products in cookies as result.
Mysql query is working very fine.
Please advice how to get latest 6 values from array