関数
Cart::addToWishlistBySerial( string $serial, string $advance = '' )
お気に入りリストにシリアル化された商品を追加する
パラメータ パラメータ
- $serial
(文字列) (必須) シリアル化されたWelcart商品
- $advance
(文字列) (任意) デフォルト: ''
ファイル: src/API/Cart.php
public function addToWishlistBySerial($serial, $advance = '') {
$item = unserialize($serial);
if (!is_array($item) || empty($item)) {
return $this->master->estore->getErrorResponse(Store::UNSERIALIZATION_ERROR, [$serial]);
}
$ids = array_keys($item);
if (empty($ids)) {
return $this->master->estore->getErrorResponse(Store::SERIALIZED_ITEM_IS_MALFORMED);
}
$post_id = (int)$ids[0];
$skus = array_keys($item[$post_id]);
if (empty($skus)) {
return $this->master->estore->getErrorResponse(Store::SERIALIZED_ITEM_IS_MALFORMED);
}
$sku = (string)$skus[0];
$exists = $this->guards->itemExists($post_id, $sku);
if ($exists instanceof GenericError) {
return $exists;
}
// 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;
}