MZ Remove sell option in a custom plugin

this is the part that handles the shop when it opens. I want the shop to be buy only, but I can figure out how to remove the sell command. Can someone please help?

Spoiler: Code
JavaScript:
    // Overriding the prepare method to accept custom items
    var _Scene_Shop_prepare = Scene_Shop.prototype.prepare;
    Scene_Shop.prototype.prepare = function (goods, purchaseOnly) {
        _Scene_Shop_prepare.call(this, goods, purchaseOnly);
        this._goods = goods;
        this._purchaseOnly = purchaseOnly;
    };

    // Overriding the createCommandWindow method to customize command window
    var _Scene_Shop_createCommandWindow = Scene_Shop.prototype.createCommandWindow;
    Scene_Shop.prototype.createCommandWindow = function () {
        _Scene_Shop_createCommandWindow.call(this);
        if (this._purchaseOnly) {
            this._commandWindow.setHandler('buy', this.commandBuy.bind(this));
            this._commandWindow.setHandler('cancel', this.popScene.bind(this));
            this._commandWindow.deactivate();
            this._commandWindow.select(0);
        }
    };

    // Overriding the commandSell method to disable selling if purchaseOnly is true
    var _Scene_Shop_commandSell = Scene_Shop.prototype.commandSell;
    Scene_Shop.prototype.commandSell = function () {
        if (this._purchaseOnly) {
            this.onSellCancel();
        } else {
            _Scene_Shop_commandSell.call(this);
        }
    };

    // Method to handle cancellation of sell command
    Scene_Shop.prototype.onSellCancel = function () {
        SoundManager.playCancel();
        this.popScene();
    };

    // Overriding makeItemList to use custom shop items
    var _Window_ShopBuy_makeItemList = Window_ShopBuy.prototype.makeItemList;
    Window_ShopBuy.prototype.makeItemList = function () {
        this._data = [];
        this._price = [];

        if (this._shopGoods && this._shopGoods.length > 0) {
            this._shopGoods.forEach(function (good) {
                let item = null;
                switch (good[0]) {
                    case 0: // Item
                        item = $dataItems[good[1]];
                        break;
                    case 1: // Weapon
                        item = $dataWeapons[good[1]];
                        break;
                    case 2: // Armor
                        item = $dataArmors[good[1]];
                        break;
                }
                if (item) {
                    this._data.push(item);
                    this._price.push(good[2] === 0 ? item.price : good[3]);
                }
            }, this);
        }

        _Window_ShopBuy_makeItemList.call(this);
    };
Isn't this a check option in the shop command that lets you select to purchase only?
// Overriding the createCommandWindow method to customize command window
This is not what you're doing. You're not overwriting it, you're aliasing it, which is your problem.

Code:
    var _Scene_Shop_createCommandWindow = Scene_Shop.prototype.createCommandWindow;
...
        _Scene_Shop_createCommandWindow.call(this);
These two lines are storing the original createCommandWindow() method and then calling it. This adds all of the commands that are in that original method - buy, sell, and cancel.

You then add buy and cancel a second time.

You should be actually overwriting this method and using the purchaseOnly conditional to either list just the two commands or all three, as well as the window management that's going on in the default method.
This is not what you're doing. You're not overwriting it, you're aliasing it, which is your problem.


These two lines are storing the original createCommandWindow() method and then calling it. This adds all of the commands that are in that original method - buy, sell, and cancel.

You then add buy and cancel a second time.

You should be actually overwriting this method and using the purchaseOnly conditional to either list just the two commands or all three, as well as the window management that's going on in the default method.
can you give me an example?


JavaScript:
    Scene_Shop.prototype.createCommandWindow = function () {
        this._commandWindow = new Window_ShopCommand(this._goldWindow.x, this._purchaseOnly);
        this._commandWindow.setHandler('buy', this.commandBuy.bind(this));
        this._commandWindow.setHandler('cancel', this.popScene.bind(this));
        this.addWindow(this._commandWindow);

        if (!this._purchaseOnly) {
            this._commandWindow.setHandler('sell', this.commandSell.bind(this));
        }
    };
Sorry, I figured it out! I was working on the wrong file. It was driving me crazy for days! because all I had to do was change false to true on the open shop option. but since I was on the wrong file it never worked no matter what lol.

Original thread: https://forums.rpgmakerweb.com/threads/remove-sell-option-in-a-custom-plugin.170202/