PHP code example of reinvanoyen / oak-wishlist

1. Go to this page and download the library: Download reinvanoyen/oak-wishlist library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reinvanoyen / oak-wishlist example snippets




use Tnt\Wishlist\Contracts\WishlistItemInterface;

class Product implements WishlistItemInterface
{
    public static function getByWishlistId(int $id): ?WishlistItemInterface
    {
        // get the product by id
    }
    
    public function getWishlistId(): int
    {
        return 1;
    }
    
    public function serialize(): array
    {
        return [
            'id' => $this->getWishListId(),
            'title' => 'Your wishlistable product #1',
        ];
    }
}




use Tnt\Wishlist\Facade\Wishlist;

$product = new Product();

// Add an item
Wishlist::add($product);

// Remove an item
Wishlist::remove($product);

// Check if an item is wishlisted
if (Wishlist::has($product)) {
    echo 'Yes, it is a wishlisted item!';
}

// Retrieve all wishlisted items
Wishlist::getItems();

// Clear all items from the wishlist
Wishlist::clear();