Jump to content

How to Make Payment Modules Reinstall Their Order Statuses?


Recommended Posts

I'm migrating from 1.5.4 to 1.7.8 and ran into the following problem:

I've installed and set up the new shop in a separate folder and it's ready to go live now, but when I migrated the most recent user and order data, the migration tool also emptied and recreated the order statuses in the 1.7.8 target installation, thus removing the custom statuses that some 1.7.8 payment modules I had installed created.

In my case, this pertains PayPal and Stripe. I already tried to uninstall and reinstall them, and also removed all mentions of stripe and paypal from the 1.7.8 ps_configuration table as this old thread from 2014 suggests (probably not working anymore in the newer PS versions?): 

 

But I can't get the darn things to reinstall their order statuses. I'm close to moving everything over to yet another fresh installation again and only installing the new payment modules AFTER I transfered all recent data, but I first wanted to check if there isn't an easier and less exhausting way to reinstall the statuses.

Are there any database entries that would need to be deleted in addition to the ones in the configuration tables? Or can I edit a line in the installation files of the payment modules to remove the step where they skip installing the statuses?

Any help with this would be much appreciated. Thank you! :) 

Link to comment
Share on other sites

45 minutes ago, Magicalname said:

Hello,

you can try to copy the Querys from the install function or Module sql file, modify them to your Needs and Fire them Manually in the Database via PHPmyAdmin

Thank you! I'm struggling to find the install information, though. The modules don't seem to have any sql files in their folders and I'm not sure which files include the install information. Would it be in module_name.php? So, for instance, in stripe_official.php and paypal.php?

Ah, I see those do include parts like this:

 /**
     * Create order state
     * @return boolean
     */
    public function installOrderState()
    {
        if (!Configuration::get('PAYPAL_OS_WAITING')
            || !Validate::isLoadedObject(new OrderState(Configuration::get('PAYPAL_OS_WAITING')))) {
            $order_state = new OrderState();
            $order_state->name = array();
            foreach (Language::getLanguages() as $language) {
                if (Tools::strtolower($language['iso_code']) == 'fr') {
                    $order_state->name[$language['id_lang']] = 'En attente de paiement PayPal';
                } else {
                    $order_state->name[$language['id_lang']] = 'Awaiting for PayPal payment';
                }
            }
            $order_state->send_email = false;
            $order_state->color = '#4169E1';
            $order_state->hidden = false;
            $order_state->delivery = false;
            $order_state->logable = false;
            $order_state->invoice = false;
            $order_state->module_name = $this->name;
            if ($order_state->add()) {
                $source = _PS_MODULE_DIR_ . 'paypal/views/img/os_paypal.png';
                $destination = _PS_ROOT_DIR_ . '/img/os/' . (int)$order_state->id . '.gif';
                copy($source, $destination);
            }

            if (Shop::isFeatureActive()) {
                $shops = Shop::getShops();
                foreach ($shops as $shop) {
                    Configuration::updateValue('PAYPAL_OS_WAITING', (int) $order_state->id, false, null, (int)$shop['id_shop']);
                }
            } else {
                Configuration::updateValue('PAYPAL_OS_WAITING', (int) $order_state->id);
            }
        }

        return true;
    }

Could you please point out the line that checks for the order statuses? Is it "if (!Configuration::get('PAYPAL_OS_WAITING')"? Can I change that somehow to just install the order status regardless of any checks?

And I'm really puzzled why it even skips this step. I searched the entire database and "PAYPAL_OS_WAITING" isn't even in there anymore. So I have no clue what is telling the module to skip installing the status. Very strange.

Otherwise, here's another section mentioning order status, from somewhere higher up in the paypal.php file:

        // Registration order status
        if (!$this->installOrderState()) {
            return false;
        }

        $this->registerHooks();
        $this->moduleConfigs['PAYPAL_OS_WAITING_VALIDATION'] = (int)Configuration::get('PAYPAL_OS_WAITING');
        $this->moduleConfigs['PAYPAL_OS_PROCESSING'] = (int)Configuration::get('PAYPAL_OS_WAITING');
        $shops = Shop::getShops();

        foreach ($this->moduleConfigs as $key => $value) {
            if (Shop::isFeatureActive()) {
                foreach ($shops as $shop) {
                    if (!Configuration::updateValue($key, $value, false, null, (int)$shop['id_shop'])) {
                        return false;
                    }
                }
            } else {
                if (!Configuration::updateValue($key, $value)) {
                    return false;
                }
            }
        }

        if (Shop::isFeatureActive()) {
            $shops = Shop::getShops();
            foreach ($shops as $shop) {
                Configuration::updateValue('PAYPAL_CRON_TIME', date('Y-m-d H:m:s'), false, null, (int)$shop['id_shop']);
                Configuration::updateValue('PAYPAL_PREVIOUS_VERSION', $this->version, false, null, (int)$shop['id_shop']);
            }
        } else {
            Configuration::updateValue('PAYPAL_CRON_TIME', date('Y-m-d H:m:s'));
            Configuration::updateValue('PAYPAL_PREVIOUS_VERSION', $this->version);
        }

        $this->hookActionLocalizationPageSave([]);
        return true;
    }

Could the "if (!$this->installOrderState()) {return false;}" line be the problem?

Link to comment
Share on other sites

Hello,

You can use the following queries to create the orderstate manually

INSERT INTO `ps_order_state` (`invoice`, `send_email`, `module_name`, `color`, `unremovable`, `hidden`, `logable`, `delivery`, `shipped`, `paid`, `pdf_invoice`, `pdf_delivery`, `deleted`) VALUES (0, 0, 'paypal', '#4169E1', 0, 0, 0, 0, 0, 0, 0, 0, 0);

INSERT INTO `ps_order_state_lang` (`id_lang`, `name`, `template`) VALUES (1, 'Awaiting for PayPal payment', '');

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...