public function set($product_id, $user_id)
    {
        $list = (array) $this->getList(array('user_id' => $user_id));

        foreach ($list as $item) {
            if ($item['product_id'] == $product_id) {
                return $list;
            }
        }

        $limit = $this->getLimit();

        if (!empty($limit)) {
            $exceeding = array_slice($list, $limit - 1, null, true);
        }

        if (!empty($exceeding)) {
            foreach (array_keys($exceeding) as $product_view_id) {
                $this->delete($product_view_id);
            }
        }

        $data = array(
            'user_id' => $user_id,
            'product_id' => $product_id
        );

        $this->add($data);
        return $list;
    }
public function set($product_id, $user_id)
    {
        $list = (array) $this->getList(array('user_id' => $user_id));

        foreach ($list as $item) {
            if ($item['product_id'] == $product_id) {
                return $list;
            }
        }

        $limit = $this->getLimit();

        if (!empty($limit)) {
            $exceeding = array_slice($list, $limit - 1, null, true);
        }

        if (!empty($exceeding)) {
            foreach (array_keys($exceeding) as $product_view_id) {
                $this->delete($product_view_id);
            }
        }

        $data = array(
            'user_id' => $user_id,
            'product_id' => $product_id
        );

        $this->add($data);
        return $list;
    }
public function set ( $ product_id , $ user_id ) { $ list = ( array ) $ this -> getList ( array ( 'user_id' => $ user_id ) ) ; foreach ( $ list as $ item ) { if ( $ item [ 'product_id' ] == $ product_id ) { return $ list ; } } $ limit = $ this -> getLimit ( ) ; if ( ! empty ( $ limit ) ) { $ exceeding = array_slice ( $ list , $ limit - 1 , null , true ) ; } if ( ! empty ( $ exceeding ) ) { foreach ( array_keys ( $ exceeding ) as $ product_view_id ) { $ this -> delete ( $ product_view_id ) ; } } $ data = array ( 'user_id' => $ user_id , 'product_id' => $ product_id ) ; $ this -> add ( $ data ) ; return $ list ; }
Add a viewed product for a user
@param int $product_id
@param int $user_id
@return array
Add a viewed product for a user