greger Posted September 4, 2018 Share Posted September 4, 2018 Hi all, I need some help with using the webservice feature in PS1.7. I've created a bunch of multistore shops with it already, but all the new shops doesn't have any currencies associated with them, causing errors when trying to view the frontend. The /api/currencies doesn't look like it has any parameter for defining which stores uses which currencies. Any idéas on how to proceed? Link to comment Share on other sites More sharing options...
Knowband Plugins Posted September 5, 2018 Share Posted September 5, 2018 Hi, 1. Use getCurrencies function through webservices to get the available currencies. 2. getCurrenciesByIdShop function can be used to get the mapped currencies with any store (Store ID is the parameter which needs to be passed) 3. Now the issue is with add mapping of currencies with store ID. I have created a function for you to achieve the same. Add the below function in the classes/Currency.php file & call the same to map currency id with store id. /** * Map Currency to Shop ID * * @param int $idShop Shop ID * @param int $id_currency Currency ID * * @return array|Currency */ public static function mapCurrencyByIdShop($idShop = 0, $id_currency = 0) { $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'currency` c LEFT JOIN `' . _DB_PREFIX_ . 'currency_shop` cs ON (cs.`id_currency` = c.`id_currency`) WHERE cs.`id_shop` = ' . (int) $idShop . ' AND cs.`id_currency` = ' . (int) $id_currency; if (Db::getInstance()->getRow($sql) > 0) { // Mapping already exist return false; } else { $check_currency = 'SELECT * FROM `' . _DB_PREFIX_ . 'currency` WHERE `id_currency` = ' . (int) $id_currency; $currency = Db::getInstance()->getRow($check_currency); if (empty($currency)) { $insert_query = 'INSERT * INTO ' . _DB_PREFIX_ . 'currency_shop(id_currency, id_shop, conversion_rate) VALUES (' . (int) $id_currency . ','. $idShop .', '.$currency['conversion_rate'].')'; return Db::getInstance()->execute($insert_query); } else { // Currency not exist return false; } } } I hope it will help. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now