関数
Cart::postToWishlistBySerial( array $args, array $payload )
お気に入りリストに一つまたは複数の商品をカートシリアルで追加する
パラメータ パラメータ
- $args
(配列) (必須) URLパラメーター。 使用されておりません
- $payload
(配列) (必須)
$_POST['payload']に格納されたjson_encodedデータから抽出された配列- 'serials'
(配列)一つまたはそれ以上のシリアル化されたWelcart商品の配列
- 'serials'
successが返されるファイル: src/API/Cart.php
public function postToWishlistBySerial(array $args, array $payload) {
global $wpdb;
if (empty($payload['serials'])) {
$emessage = $this->master->estore->getErrorCodeMap()[Store::UNKNOWN_ERROR]->message;
return $this->master->estore->getErrorResponse(Store::REQUIRED_FIELDS_MISSING, ['serials'], [$emessage]);
}
$serials = !is_array($payload['serials']) ? [] : $payload['serials'];
$cart = isset($_SESSION['usces_cart']) ? $_SESSION['usces_cart'] : [];
$loggedout = false;
$wpdb->query('START TRANSACTION;');
foreach ($serials as $serial) {
$serial = urldecode($serial);
$advance = isset($cart[$serial]['advance']) ? $cart[$serial]['advance'] : '';
$res = $this->addToWishlistBySerial($serial, $advance);
if ($res instanceof GenericError) {
if ($res->errorcode !== Store::NOT_LOGGED_IN) {
$wpdb->query('ROLLBACK;');
return $res;
}
$loggedout = true;
}
/**
* Fires after **one** serialized item from the cart is added to the wishlist.
*
* @important
* @param \Aivec\Welcart\Extensions\Wishlist\API\Cart $this Instance of the `Wishlist` API class
* @param string $serial The serialized Welcart item
* @param string $advance Extra form data
* @param array $payload See \Aivec\Welcart\Extensions\Wishlist\API\Cart::postToWishlistBySerial()
* for details
*/
do_action('wcexwl_cart_api_add_to_wishlist_on_complete', $this, $serial, $advance, $payload);
}
if ($loggedout === true) {
$error = $this->master->estore->getErrorResponse(Store::NOT_LOGGED_IN);
$error->setData($serials);
return $error;
}
$wpdb->query('COMMIT;');
/**
* Fires after **one or more** serialized items from the cart have been added to the wishlist.
*
* @important
* @param \Aivec\Welcart\Extensions\Wishlist\API\Cart $this Instance of the `Wishlist` API class
* @param array $serials Array of one or more serialized Welcart items
* @param array $payload See \Aivec\Welcart\Extensions\Wishlist\API\Cart::postToWishlistBySerial()
* for details
*/
do_action('wcexwl_cart_api_batch_add_to_wishlist_on_complete', $this, $serials, $payload);
return 'success';
}