Commit d41f936c authored by Batyr Mackenov's avatar Batyr Mackenov

Currencies are cut out to a separate plugin

parent a5c87a8d
......@@ -89,7 +89,7 @@ SQL;
public function exists($slug, $parentId, $id = null)
{
$wherePattern = self::_cols('`title_alias` = :slug AND `:col_pid` = :parent');
$wherePattern = self::_cols('`slug` = :slug AND `:col_pid` = :parent');
empty($id)
? (bool)$this->iaDb->exists($wherePattern, ['slug' => $slug, 'parent' => $parentId], self::getTable())
......
......@@ -19,12 +19,6 @@ if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
];
}
if ($iaView->blockExists('currencies')) {
$iaCurrency = $iaCore->factoryModule('currency', $iaProduct->getModuleName());
$blocksData['currencies'] = $iaCurrency->fetch();
}
if ($iaView->blockExists('priority_categories')) {
$blocksData['priorityCategories'] = $iaCategory->getBlockPriority();
}
......
<?php
//##copyright##
class iaRatesProviderJsonrates extends abstractCore
{
const ENDPOINT_URL = 'http://apilayer.net/api/live';
protected $_iaCurrency;
public function __construct($iaCurrency)
{
$this->_iaCurrency = $iaCurrency;
}
protected function _composeUrl($source, $currencies)
{
$params = [
'access_key' => $this->iaCore->get('commerce_apikey_jsonrates'),
'source' => $source,
'currencies' => implode(',', $currencies),
'format' => 1
];
return self::ENDPOINT_URL . '?' . http_build_query($params);
}
public function fetch()
{
$source = null;
$currencies = [];
foreach ($this->_iaCurrency->fetch() as $currency) {
if ($currency['default']) {
$source = $currency['code'];
} else {
$currencies[] = $currency['code'];
}
}
$url = $this->_composeUrl($source, $currencies);
$response = $this->_httpRequest($url);
if ($response) {
$array = json_decode($response, true);
if (!empty($array['quotes'])) {
$rates = [];
foreach ($array['quotes'] as $cur => $rate) {
$code = substr($cur, 3);
$rate = (float)$rate;
$rates[$code] = $rate;
}
return $rates;
}
}
return false;
}
protected function _httpRequest($url)
{
return iaUtil::getPageContent($url);
}
}
\ No newline at end of file
......@@ -25,9 +25,6 @@
<action name="products_list" url="commerce/products/" icon="list" pages="commerce_stats,products:add,products:edit">List</action>
<action name="products_add" url="commerce/products/add/" icon="plus-alt" pages="products,products:edit">New Product</action>
<action name="currencies_list" url="commerce/currencies/" icon="list" pages="commerce_stats,currencies:add,currencies:edit">List</action>
<action name="currencies_add" url="commerce/currencies/add/" icon="plus-alt" pages="currencies,currencies:edit">New Currency</action>
</actions>
<groups>
......@@ -36,8 +33,6 @@
<adminpages>
<page group="commerce" name="commerce_stats" url="commerce/" filename="statistics" menus="menu">Statistics</page>
<page group="commerce" menus="menu">Settings</page>
<page group="commerce" name="currencies" url="commerce/currencies/" filename="currencies" menus="menu">Currencies</page>
<page group="commerce" menus="menu">Orders</page>
<page group="commerce" name="orders" url="commerce/orders/" filename="orders" menus="menu">Orders</page>
<page group="commerce" menus="menu">Content</page>
......@@ -51,7 +46,6 @@
<page group="commerce" name="view_product" url="|PACKAGE|product/" filename="view" readonly="1">Product Details</page>
<page group="commerce" name="cart" url="|PACKAGE|cart/" filename="cart" readonly="1">Cart</page>
<page group="commerce" name="checkout" url="|PACKAGE|checkout/" filename="checkout" readonly="1">Checkout</page>
<page group="commerce" name="currency" url="|PACKAGE|currency/" filename="currency" service="1">Currencies</page>
</pages>
<permissions>
......@@ -64,9 +58,6 @@
</permissions>
<configgroup name="commerce">Commerce</configgroup>
<config group="commerce" type="divider">General</config>
<config group="commerce" name="commerce_rates_provider" values="jsonrates" type="select" description="Exchange rates provider">jsonrates</config>
<config group="commerce" name="commerce_apikey_jsonrates" type="text" description="jsonrates API Key" show="commerce_rates_provider|jsonrates"><![CDATA[f0419431ff596992b212b68a6df57d80]]></config>
<config group="commerce" type="divider">Limits</config>
<config group="commerce" name="commerce_products_per_page" type="text" description="Products per page">20</config>
<config group="commerce" name="commerce_featured_products_limit" type="text" description="Products in 'Featured Products' block" private="1">10</config>
......@@ -198,7 +189,7 @@
<field item="products" group="general" name="title" type="text" required="1" searchable="1" link_to="1" multilingual="1" length="255">Title</field>
<field item="products" group="general" name="snippet" type="textarea" editor="0" editable="0" searchable="1" multilingual="1">Snippet</field>
<field item="products" group="general" name="description" type="textarea" editor="1" editable="0" multilingual="1" searchable="1">Description</field>
<field item="products" group="pricing" name="price" type="number" length="8" editable="0">Price</field>
<field item="products" group="pricing" name="price" type="currency" length="8" editable="0">Price</field>
<field item="products" group="pictures" name="pictures" type="pictures" thumb_height="228" height="600" length="12" folder_name="products" mode="crop">Pictures</field>
<field item="products" group="seo" name="meta_description" type="textarea" length="255" adminonly="1" editable="0" multilingual="1">Meta-Description</field>
<field item="products" group="seo" name="meta_keywords" type="text" length="255" adminonly="1" editable="0" multilingual="1">Meta-Keywords</field>
......@@ -214,11 +205,8 @@
<field item="orders" group="other" name="comment" type="textarea" editable="0" length="5000" page="checkout">Comment</field>
</fields>
<cron name="Exchange rates update">0 0 0/12 1/1 * modules/commerce/includes/cron/exchange-rates.php</cron>
<phrases>
<phrase category="admin" key="add_category">Add Category</phrase>
<phrase category="admin" key="add_currency">Add Currency</phrase>
<phrase category="admin" key="add_product">Add Product</phrase>
<phrase category="admin" key="buyer">Buyer</phrase>
<phrase category="admin" key="commerce_package">&quot;Commerce&quot; Package</phrase>
......@@ -228,10 +216,7 @@
<phrase category="admin" key="do_you_want_to_delete_this_product">Do you really want to delete this product permanently?</phrase>
<phrase category="admin" key="do_you_want_to_remove_order">Do you really want to permanently remove this order?</phrase>
<phrase category="admin" key="edit_category">Edit Category</phrase>
<phrase category="admin" key="edit_currency">Edit Currency ":title"</phrase>
<phrase category="admin" key="edit_product">Edit Product</phrase>
<phrase category="admin" key="exchange_rate">Exchange rate</phrase>
<phrase category="admin" key="rate">Rate</phrase>
<phrase category="admin" key="order_removed">Order removed.</phrase>
<phrase category="admin" key="priority">Priority</phrase>
<phrase category="admin" key="product_with_similar_slug_exists_in_category">Product with the same slug already exists in category.</phrase>
......@@ -270,7 +255,6 @@
<blocks>
<block name="cart" title="Shopping Cart" position="account" type="smarty" header="0" filename="block.cart"><![CDATA[]]></block>
<block name="currencies" title="Currencies" position="account" type="smarty" header="0" filename="block.currencies"><![CDATA[]]></block>
<block name="subcategories" title="Subcategories" position="top" type="smarty" header="0" sticky="0" pages="storefront" filename="block.subcategories"><![CDATA[]]></block>
<block name="priority_categories" title="Priority Categories" position="right" type="smarty" header="1" filename="block.priority-categories"><![CDATA[]]></block>
<block name="featured_products" title="Featured Products" position="verytop" type="smarty" sticky="1" filename="block.featured-products"><![CDATA[]]></block>
......@@ -398,28 +382,6 @@ CREATE TABLE `{prefix}orders_items` (
) {mysql_version};
]]>
</sql>
<sql>
<![CDATA[
CREATE TABLE `{prefix}currencies` (
`code` char(3) NOT NULL,
`title` varchar(30) NOT NULL,
`rate` decimal(7,2) unsigned NOT NULL,
`sym` varchar(5) NOT NULL,
`sym_pos` enum('pre', 'post') NOT NULL default 'pre',
`default` tinyint(1) unsigned NOT NULL,
`order` tinyint(2) unsigned NOT NULL,
PRIMARY KEY (`code`)
) {mysql_version};
]]>
</sql>
<sql>
<![CDATA[
INSERT INTO `{prefix}currencies` VALUES
('USD', 'US Dollar', 1, '$', 'pre', 1, 1),
('EUR', 'Euro', 0.87, '€', 'post', 0, 2),
('GBP', 'Pound Sterling', 0.78, '£', 'pre', 0, 3);
]]>
</sql>
<code>
<![CDATA[
$iaCore->factoryModule('category', 'commerce', iaCore::ADMIN)->setupDbStructure();
......@@ -432,7 +394,7 @@ $iaCore->factoryModule('currency', 'commerce')->refreshRates();
<sql>
<![CDATA[
DROP TABLE IF EXISTS `{prefix}products`, `{prefix}categories`, `{prefix}categories_flat`,
`{prefix}cart`, `{prefix}cart_items`, `{prefix}orders`, `{prefix}orders_items`, `{prefix}currencies`;
`{prefix}cart`, `{prefix}cart_items`, `{prefix}orders`, `{prefix}orders_items`;
]]>
</sql>
</uninstall>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment