• プラグイン一覧
    - 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-item-combo-set > クラス > Wishlist
レファレンス
バージョン
1.0.6
絞り込み:

目次

  • ソース
  • 関数

フック

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

ファンクション

    クラス

    Wishlist

    Adds compatibility with WCEX Wishlist

    ソース #ソース

    ファイル: src/Wishlist.php

    class Wishlist
    {
        /**
         * Registers hooks
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @return void
         */
        public static function init() {
            add_action('wcexwl_wishlist_api_add_to_cart_on_complete', [get_class(), 'addLabelsOnAddToCart'], 10, 2);
            add_filter(
                'wcexwl_filter_item_add_to_wishlist_custom_validation',
                [get_class(), 'validateComboSetOnAddToWishlist'],
                10,
                2
            );
            add_filter(
                'wcexwl_filter_item_add_to_wishlist_serial',
                [get_class(), 'filterItemAddToWishlistSerial'],
                10,
                2
            );
            add_filter('wcexwl_filter_wlpage_cart_item_name', [get_class(), 'filterWishlistCartItemName'], 10, 2);
            add_action('wcexwl_wishlist_page_on_load_assets', function () {
                Components\Cart\Cart::loadCss();
            });
        }
    
        /**
         * Adds group and group item labels to the combo-set cart item when added from the wishlist page
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @param \Aivec\Welcart\Extensions\Wishlist\API\Wishlist $instance
         * @param array                                           $args
         * @return void
         */
        public static function addLabelsOnAddToCart($instance, $args) {
            $id = (int)$args['itemId'];
            $item = \Aivec\Welcart\Extensions\Wishlist\API\CRUD::getWishlistItemById($id);
            $serial = $item['serial'];
            $maps = API\Cart::getGroupAndItemLabelsFromSerial($serial);
            if (empty($maps)) {
                return;
            }
            $_SESSION['usces_cart'][$serial]['grouplabelmap'] = $maps['grouplabelmap'];
            $_SESSION['usces_cart'][$serial]['itemlabelmap'] = $maps['itemlabelmap'];
        }
    
        /**
         * Performs validation for a combo-set being added to the wishlist from the item page
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @param null  $null
         * @param array $args
         * @return null|GenericError
         */
        public static function validateComboSetOnAddToWishlist($null, $args) {
            // we need to make sure the item is a combo-set item
            $comboset = API\ComboSet::getComboSetFromSkuCode($args['post_id'], urldecode($args['sku']));
            if ($comboset instanceof GenericError) {
                // error fetching automatically sets the response code (bad design...)
                http_response_code(200);
                return $null;
            }
    
            $pvals = API\Cart::getAddToCartPostValues($comboset->getId());
            $groupids = $pvals['groupids'];
    
            // check that all group IDs and item IDs exist. Check that required groups have selections
            $error = API\PurchaseSanityChecks::comboSetSelectionsAreValid($comboset->getId(), $groupids);
            if ($error instanceof GenericError) {
                return $error;
            }
    
            return $null;
        }
    
        /**
         * Filters serialization of a combo-set when adding to wishlist from the item page
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @param string $serial
         * @param array  $args
         * @return string
         */
        public static function filterItemAddToWishlistSerial($serial, $args) {
            // we need to make sure the item is a combo-set item
            $comboset = API\ComboSet::getComboSetFromSkuCode($args['post_id'], urldecode($args['sku']));
            if ($comboset instanceof GenericError) {
                // error fetching automatically sets the response code (bad design...)
                http_response_code(200);
                return $serial;
            }
    
            $pvals = API\Cart::getAddToCartPostValues($comboset->getId());
            $groupids = $pvals['groupids'];
            $itemoptmap = $pvals['itemoptmap'];
    
            // get post data for constructing a cart out of the selected group items
            $postdata = API\Cart::getInCartPostData($comboset, $groupids, $itemoptmap);
    
            // Now we need to construct a cart out of all the group items
            $cartapi = new API\Cart();
            $groupitemscart = $cartapi->getGroupItemsCart($postdata)['rawCart'];
    
            // set $this->payload for use in processing the combo-set item
            $cartapi->payload = [];
            $cartapi->payload['comboSetId'] = $comboset->getId();
            $cartapi->payload['groupItemsCart'] = $groupitemscart;
    
            $tempcart = new \usces_cart();
            if (!empty($args['item_option'])) {
                // we are forced to set $_POST at runtime here since `in_serialize` uses $_POST internally
                $_POST['itemOption'] = $args['item_option'];
            }
            add_filter('usces_filter_in_serialize', [$cartapi, 'filterComboSetInSerialize'], 10);
            $tempcart->in_serialize($args['post_id'], $args['sku']);
            unset($_POST['itemOption']);
            remove_filter('usces_filter_in_serialize', [$cartapi, 'filterComboSetInSerialize']);
    
            return $tempcart->serial;
        }
    
        /**
         * Adds combo-set details below the cart item name on the wishlist page
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \usc_e_shop $usces
         * @param string $html
         * @param array  $row
         * @return string
         */
        public static function filterWishlistCartItemName($html, $row) {
            global $usces;
    
            $sels = unserialize($row['serial']);
            if (empty($sels['comboSetId']) || !isset($sels['comboSetItems'])) {
                return $html;
            }
    
            $rows = [];
            foreach ($sels['comboSetItems'] as $serial => $gitem) {
                $gisels = unserialize($serial);
                $gicsels = (new \usces_cart())->key_unserialize($serial);
                $glabel = '';
                $group = API\ComboGroup::getComboGroupById($gisels['groupId']);
                if ($group instanceof Types\ComboGroup) {
                    $glabel = $group->getLabel();
                }
    
                $itemLabel = '';
                $itemtype = API\GroupItem::getGroupItemById($gisels['itemId']);
                if ($itemtype instanceof Types\GroupItem) {
                    $itemLabel = $itemtype->getItemLabel();
                }
                if (empty($itemLabel)) {
                    $itemLabel = wcexics_get_group_item_default_label(
                        $usces->getItemName($gicsels['post_id']),
                        $usces->getItemSkuDisp($gicsels['post_id'], urldecode($gicsels['sku'])),
                        $gitem['quant'],
                        $gitem['price']
                    );
                }
                $rows[$gisels['groupId']]['groupLabel'] = $glabel;
                $rows[$gisels['groupId']]['groupItems'][] = [
                    'name' => $itemLabel,
                    'options' => !empty($gicsels['options']) ? $gicsels['options'] : [],
                ];
            }
    
            return $html . Components\Cart\Cart::getComboSetCartDetailsHtml($rows);
        }
    }
    

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


    関数 #関数

    Top ↑

    • addLabelsOnAddToCart — Adds group and group item labels to the combo-set cart item when added from the wishlist page
    • filterItemAddToWishlistSerial — Filters serialization of a combo-set when adding to wishlist from the item page
    • filterWishlistCartItemName — Adds combo-set details below the cart item name on the wishlist page
    • init — Registers hooks
    • validateComboSetOnAddToWishlist — Performs validation for a combo-set being added to the wishlist from the item page

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

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

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

    © 2025 Aivec llc All Rights Reserved.