関数
Item::addToWishlist( int $post_id, string $sku, array $item_option = array(), string $advance = '' )
パラメータにある商品情報でお気に入りリストに商品を追加する
パラメータ パラメータ
- $post_id
(数値) (必須)
- $sku
(文字列) (必須) 必須 URLデコードされています
- $item_option
(配列) (任意)
- $advance
(文字列) (任意)
ファイル: src/API/Item.php
public function addToWishlist($post_id, $sku, $item_option = [], $advance = '') { $exists = $this->guards->itemExists($post_id, $sku); if ($exists instanceof GenericError) { return $exists; } if (!defined('WCEX_WIDGET_CART')) { if (!empty($item_option)) { // by default we use `wcex_widget_cart`'s way of serializing option data but multi-select // option values are serialized differently when not using `wcex_widget_cart`. Because of this, // we have to transform multi-select option values when `wcex_widget_cart` is not being used. $item_option = self::convertWidgetCartItemOptionPayloadToWelcartDefault($item_option, $post_id, $sku); } // By default, Welcart serializes with the encoded SKU. `wcex_widget_cart` serializes with the decoded SKU. $sku = urlencode($sku); } $opterror = $this->guards->requiredOptionsProvided($post_id, $sku, $item_option); if ($opterror instanceof GenericError) { return $opterror; } $tempcart = new \usces_cart(); if (!empty($item_option)) { // we are forced to set $_POST at runtime here since `in_serialize` uses $_POST internally $_POST['itemOption'] = $item_option; } $tempcart->in_serialize($post_id, $sku); unset($_POST['itemOption']); if (!empty($advance)) { $advance = $tempcart->wc_serialize($advance); } $hookargs = [ 'post_id' => $post_id, 'sku' => $sku, 'item_option' => $item_option, 'advance' => $advance, ]; $customerror = apply_filters('wcexwl_filter_item_add_to_wishlist_custom_validation', null, $hookargs); if ($customerror !== null) { return $customerror; } $serial = apply_filters('wcexwl_filter_item_add_to_wishlist_serial', $tempcart->serial, $hookargs); // check if logged in after all other checks pass so that we can add the item // to the wishlist automatically after a successful login $isloggedin = $this->guards->isLoggedIn(); if ($isloggedin instanceof GenericError) { $isloggedin->setData($serial); return $isloggedin; } $res = CRUD::executeAddToWishlist($post_id, $sku, $serial, $advance); if ($res === false) { return $this->master->estore->getErrorResponse(Store::INTERNAL_SERVER_ERROR); } return true; }