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

目次

  • ソース
  • 関数

フック

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

ファンクション

    クラス

    ComboSet

    API methods for creating/deleting combo-sets

    ソース #ソース

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

    class ComboSet
    {
        /**
         * Returns `true` if the SKU is a combo-set item, `false` otherwise
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \wpdb $wpdb
         * @param int $skuMetaId
         * @return bool
         */
        public static function isComboSet($skuMetaId) {
            global $wpdb;
    
            $cst = Schema::getComboSetsTable();
            $exists = $wpdb->get_var(
                $wpdb->prepare(
                    "SELECT COUNT(ID) FROM {$cst} WHERE sku_meta_id = %d",
                    (int)$skuMetaId
                )
            );
            if ($exists === null) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::INTERNAL_SERVER_ERROR);
            }
            if ((bool)(int)$exists === true) {
                return true;
            }
    
            return false;
        }
    
        /**
         * Marks an SKU as a combo-set item
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \wpdb $wpdb
         * @param int  $skuMetaId
         * @param bool $enableItemOptions
         * @param bool $enableMultiprice
         * @return GenericError|ComboSetType The combo-set type, on success
         */
        public static function createComboSet(
            $skuMetaId,
            $enableItemOptions = Schema::ENABLE_ITEM_OPTIONS_DEFAULT,
            $enableMultiprice = Schema::ENABLE_MULTIPRICE_DEFAULT
        ) {
            global $wpdb;
    
            $skuMetaId = (int)$skuMetaId;
            $postId = Utils::getSkuPostId($skuMetaId);
            if ($postId instanceof GenericError) {
                return $postId;
            }
            $exists = self::isComboSet($skuMetaId);
            if ($exists === true) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::COMBO_SET_ALREADY_EXISTS);
            }
            $isgitem = GroupItem::skuIsGroupItem($skuMetaId);
            if ($isgitem instanceof GenericError) {
                return $isgitem;
            }
            if ($isgitem === true) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::SKU_IS_COMBO_SET_GROUP_ITEM);
            }
    
            $curtime = Utils::getCurrentUTCDateTimeString();
            $res = $wpdb->insert(
                Schema::getComboSetsTable(),
                [
                    'post_id' => (int)$postId,
                    'sku_meta_id' => $skuMetaId,
                    'enable_item_options' => (int)$enableItemOptions,
                    'enable_multiprice' => (int)$enableMultiprice,
                    'created_at' => $curtime,
                    'updated_at' => $curtime,
                ],
                ['%d', '%d', '%d', '%d', '%s', '%s']
            );
            if ($res === false) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::INTERNAL_SERVER_ERROR);
            }
    
            return new ComboSetType(
                $wpdb->insert_id,
                $skuMetaId,
                [],
                $enableItemOptions,
                $enableMultiprice,
                $curtime,
                $curtime
            );
        }
    
        /**
         * Deletes all data associated with a combo-set item and unlinks from the SKU
         *
         * This method will return `0` if no combo-set exists for the `$comboSetId` provided
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \wpdb $wpdb
         * @param int $comboSetId
         * @return GenericError|int Number of rows deleted on success
         */
        public static function deleteComboSet($comboSetId) {
            global $wpdb;
    
            $cst = Schema::getComboSetsTable();
            $res = $wpdb->delete($cst, ['ID' => (int)$comboSetId], ['%d']);
            if ($res === false) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::INTERNAL_SERVER_ERROR);
            }
    
            return (int)$res;
        }
    
        /**
         * Returns a `\Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet` instance given
         * its SKU meta ID
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \wpdb $wpdb
         * @param int $skuMetaId
         * @return GenericError|ComboSetType
         */
        public static function getComboSetBySkuMetaId($skuMetaId) {
            global $wpdb;
    
            $postId = Utils::getSkuPostId($skuMetaId);
            if ($postId instanceof GenericError) {
                return $postId;
            }
    
            $cst = Schema::getComboSetsTable();
            $res = $wpdb->get_var(
                $wpdb->prepare(
                    "SELECT COUNT(ID) FROM {$cst} WHERE sku_meta_id = %d",
                    (int)$skuMetaId
                )
            );
            if ($res === null) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::INTERNAL_SERVER_ERROR);
            }
    
            if ((bool)(int)$res === false) {
                return Master::getErrorStore()->getErrorResponse(
                    ErrorStore::COMBO_SET_NOT_FOUND_BY_SKU_META_ID,
                    [$skuMetaId],
                    [],
                    [$skuMetaId]
                );
            }
    
            $row = $wpdb->get_row(
                $wpdb->prepare(
                    "SELECT * FROM {$cst} WHERE sku_meta_id = %d",
                    (int)$skuMetaId
                ),
                ARRAY_A
            );
            if ($row === null) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::INTERNAL_SERVER_ERROR);
            }
    
            return new ComboSetType(
                (int)$row['ID'],
                $skuMetaId,
                ComboGroup::getAllComboGroupsByComboSetId((int)$row['ID']),
                (bool)$row['enable_item_options'],
                (bool)$row['enable_multiprice'],
                $row['created_at'],
                $row['updated_at']
            );
        }
    
        /**
         * Returns a `\Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet` instance given
         * its ID
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \wpdb $wpdb
         * @param int $comboSetId
         * @return GenericError|ComboSetType
         */
        public static function getComboSetById($comboSetId) {
            global $wpdb;
    
            $comboSetId = (int)$comboSetId;
            $cst = Schema::getComboSetsTable();
            $res = $wpdb->get_var(
                $wpdb->prepare(
                    "SELECT COUNT(ID) FROM {$cst} WHERE ID = %d",
                    $comboSetId
                )
            );
            if ($res === null) {
                return Master::getErrorStore()->getErrorResponse(ErrorStore::INTERNAL_SERVER_ERROR);
            }
    
            if ((bool)(int)$res === false) {
                return Master::getErrorStore()->getErrorResponse(
                    ErrorStore::COMBO_SET_NOT_FOUND_BY_ID,
                    [$comboSetId],
                    [],
                    [$comboSetId]
                );
            }
    
            $row = $wpdb->get_row(
                $wpdb->prepare(
                    "SELECT * FROM {$cst} WHERE ID = %d",
                    $comboSetId
                ),
                ARRAY_A
            );
    
            return new ComboSetType(
                (int)$row['ID'],
                (int)$row['sku_meta_id'],
                ComboGroup::getAllComboGroupsByComboSetId((int)$row['ID']),
                (bool)$row['enable_item_options'],
                (bool)$row['enable_multiprice'],
                $row['created_at'],
                $row['updated_at']
            );
        }
    
        /**
         * Returns instance of \Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet if found,
         * `GenericError` otherwise
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @param int    $post_id Post ID is required because SKU codes are not unique
         * @param string $sku_code **Must be decoded**
         * @return GenericError|ComboSetType
         */
        public static function getComboSetFromSkuCode($post_id, $sku_code) {
            $sets = self::getAllComboSetsForPostId($post_id);
            if (empty($sets)) {
                return Master::getErrorStore()->getErrorResponse(
                    ErrorStore::COMBO_SET_NOT_FOUND_BY_SKU_CODE,
                    [$post_id, $sku_code]
                );
            }
    
            foreach ($sets as $set) {
                if ($set === null) {
                    continue;
                }
                $skudata = $set->getSkuData();
                if ($skudata['code'] === $sku_code) {
                    return $set;
                }
            }
    
            return Master::getErrorStore()->getErrorResponse(
                ErrorStore::COMBO_SET_NOT_FOUND_BY_SKU_CODE,
                [$post_id, $sku_code]
            );
        }
    
        /**
         * Returns a key-value list of all combo-sets associated with a post ID where key is the SKU
         * meta ID and value is an instance of `\Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet`
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \wpdb $wpdb
         * @param int $postId
         * @return ComboSetType[]
         */
        public static function getAllComboSetsForPostId($postId) {
            global $wpdb;
    
            $skust = usces_get_tablename('usces_skus');
            $skuMetaIds = $wpdb->get_results(
                $wpdb->prepare(
                    "SELECT meta_id FROM {$skust} WHERE post_id = %d",
                    (int)$postId
                ),
                ARRAY_N
            );
            $combos = [];
            foreach ($skuMetaIds as $metaId) {
                if (!isset($metaId[0])) {
                    continue;
                }
                $skuMetaId = $metaId[0];
                $combo = self::getComboSetBySkuMetaId($skuMetaId);
                if ($combo instanceof GenericError) {
                    $combo = null;
                }
                $combos[$skuMetaId] = $combo;
            }
    
            return $combos;
        }
    }
    

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


    関数 #関数

    Top ↑

    • createComboSet — Marks an SKU as a combo-set item
    • deleteComboSet — Deletes all data associated with a combo-set item and unlinks from the SKU
    • getAllComboSetsForPostId — Returns a key-value list of all combo-sets associated with a post ID where key is the SKU meta ID and value is an instance of `\Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet`
    • getComboSetById — Returns a `\Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet` instance given its ID
    • getComboSetBySkuMetaId — Returns a `\Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet` instance given its SKU meta ID
    • getComboSetFromSkuCode — Returns instance of \Aivec\Welcart\Extensions\ItemComboSet\Types\ComboSet if found, `GenericError` otherwise
    • isComboSet — Returns `true` if the SKU is a combo-set item, `false` otherwise

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

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

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

    © 2025 Aivec llc All Rights Reserved.