• プラグイン一覧
    - WCEX Item Combo Set
    - WCEX Amazon Pay
    - WCEX Wishlist お気に入りリスト
  • リリース情報
  • お役立ちコラム
  • お問い合わせ
  • サポート
    • よくある質問
      • WCEX Amazon Pay
      • WCEX Wishlist お気に入りリスト
      • wcex-item-combo-set
    • リファレンス
      • WCEX Amazon Pay
      • WCEX Wishlist お気に入りリスト
      • wcex-item-combo-set
新規会員登録
ログイン
新規会員登録
ログイン
カート
  • プラグイン一覧
    • - WCEX Item Combo Set
    • - WCEX Amazon Pay
    • - WCEX Wishlist お気に入りリスト
  • リリース情報
  • お役立ちコラム
  • サポート
    • - よくある質問
      • - WCEX Amazon Pay
      • - WCEX Wishlist お気に入りリスト
      • - wcex-item-combo-set
    • - リファレンス
      • - WCEX Amazon Pay
      • - WCEX Wishlist お気に入りリスト
      • - wcex-item-combo-set
  • お問い合わせ
Aivec APPs > WCEX Wishlist お気に入りリスト > クラス > Cart
レファレンス
バージョン
3.1.6
絞り込み:
目的から探す
お気に入りデータを取得 お気に入りページのHTMLを取得 スナックバーアラート

目次

  • ソース
  • 関数

フック

  • アクション
  • フィルター

ファンクション

  • データ取得
  • ユーティリティー
  • 条件判断
  • 表示系

クラス

Cart

Cart API

ソース #ソース

ファイル: src/API/Cart.php

class Cart
{
    /**
     * Master object
     *
     * @var Master
     */
    public $master;

    /**
     * Contains methods for checking stock, etc.
     *
     * @var Validation
     */
    public $guards;

    /**
     * Sets up `Cart`
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param Master $master
     * @return void
     */
    public function __construct(Master $master) {
        $this->master = $master;
        $this->guards = new Validation($master);
    }

    /**
     * Adds a serialized item to wishlist
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param string $serial The Welcart item serialized
     * @param string $advance Default: ''
     * @return GenericError|true
     */
    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;
    }

    /**
     * Adds an item or multiple items to wishlist by cart serial
     *
     * @todo Consider requiring `advance` in `$payload` since currently this method
     *       implicitly relies on `$_SESSION['usces_cart']` for the `advance` value
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @global \wpdb $wpdb
     * @param array $args URI parameters. **Unused**
     * @param array $payload {
     *     The array parsed from `json_encoded` data stored in `$_POST['payload']`.
     *
     *     @type array $serials Array of one or more serialized Welcart items
     * }
     * @return GenericError|string If no error occurs, `success` is returned
     */
    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';
    }

    /**
     * Batch deletes items from cart
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param array $args URI parameters. **Unused**
     * @param array $payload {
     *     The array parsed from `json_encoded` data stored in `$_POST['payload']`.
     *
     *     @type array $serials Array of one or more serialized Welcart items
     * }
     * @return GenericError|string If no error occurs, `success` is returned
     */
    public function batchDelete(array $args, array $payload) {
        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 = $payload['serials'];
        foreach ($serials as $serial) {
            $serial = urldecode($serial);
            unset($_SESSION['usces_cart'][$serial]);

            /**
             * Fires after **one** serialized item is deleted from the cart.
             *
             * @important
             * @param \Aivec\Welcart\Extensions\Wishlist\API\Cart $this Instance of the `Wishlist` API class
             * @param string                                      $serial The serialized Welcart item
             * @param array                                       $payload See \Aivec\Welcart\Extensions\Wishlist\API\Cart::batchDelete()
             *                                                             for details
             */
            do_action('wcexwl_cart_api_delete_on_complete', $this, $serial, $payload);
        }

        /**
         * Fires after **one or more** serialized items have been deleted from the cart.
         *
         * @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_delete_on_complete', $this, $serials, $payload);

        return 'success';
    }
}

ソースを伸ばす ソースを縮める


関数 #関数

Top ↑

  • __construct — Sets up `Cart`
  • addToWishlistBySerial — Adds a serialized item to wishlist
  • batchDelete — Batch deletes items from cart
  • postToWishlistBySerial — Adds an item or multiple items to wishlist by cart serial

  • 新規会員登録
  • ログイン
    • プラグイン一覧
    • 会社概要
    • リリース情報
    • よくある質問
    • お役立ちコラム
    • お問い合わせ
    • 個人情報保護方針
    • 特定商取引法に基づく表記
    • 情報セキュリティ基本方針
    • 利用規約

アイベック合同会社は「Welcart」「Amazon Pay」の公式パートナーです。

※Amazon、Amazon.co.jp、Amazon Payおよびそれらのロゴは、Amazon.com,inc.またはその関連会社の商標です。

© 2025 Aivec llc All Rights Reserved.