関数
CRUD::executeAddToWishlist( int $post_id, string $sku, string $serial, string $advance = '' )
お気に入りリストのテーブルに商品を挿入する
説明 説明
If the user is not logged in or a DB error occurs, false is returned, otherwise true is returned.
- $post_id
- (数値) (必須) 
- $sku
- (文字列) (必須) 
- $serial
- (文字列) (必須) 
- $advance
- (文字列) (任意) 
ファイル: src/API/CRUD.php
    public static function executeAddToWishlist($post_id, $sku, $serial, $advance = '') {
        global $wpdb;
        if (empty(self::getMemberId())) {
            return false;
        }
        $srow = self::getWishlistItemBySerial($serial);
        if (!empty($srow)) {
            // return `true` if the item already exists in wishlist
            return true;
        }
        $unit_price = null;
        $tempcart = new \usces_cart();
        /*
         * `get_realprice` uses `$this->serial` internally so we need to set `serial`
         * before calling it.
         *
         * We can't use `$usces->cart->get_realprice(...)` because spoofing `serial`
         * would directly affect the cart session.
         */
        $tempcart->serial = $serial;
        // `$sku` is automatically urldecoded in `get_realprice`
        $price = (int)$tempcart->get_realprice($post_id, $sku, 1, null, $unit_price);
        $res = $wpdb->insert(
            Master::getWishlistTableName(),
            [
                'mem_id' => self::getMemberId(),
                'quantity' => 1,
                'price' => $price,
                'advance' => $advance,
                'item_serial' => $serial,
            ],
            [
                '%d',
                '%d',
                '%d',
                '%s',
                '%s',
            ]
        );
        if ($res === false) {
            return false;
        }
        return true;
    }