redirect deleted products from database asigning them a new ID

37 Views Asked by At

I need to make some redirects for some products which has been deleted from database.

I get the product from database this way:


    public function show( $prod_id=null){
      $produs=Product::find(array('conditions' => array('product_id = ?', $prod_id)));
    }

and I want to create some kind of array with the ID's that are deleted and set them a new ID for an existing product. I have made something like this (1726 is the deleted ID and the other one, 369 is the new ID):


    $products = array(  '1726' => 369,
                        '1716' => 1650,
             );

1

There are 1 best solutions below

1
Blue On BEST ANSWER
public function show( $prod_id=null ) {
    $products = array(  '1726' => 369,
                    '1716' => 1650,
     );

    if ( isset($products[ $prod_id ]) ) {
        $prod_id = $products[ $prod_id ];
    }

    $produs=Product::find(array('conditions' => array('product_id = ?', $prod_id)));
}