Skip to content

Commit

Permalink
Merge pull request #1 from Magmodules/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Magmodules authored Feb 23, 2017
2 parents dc1ce5b + 4e3862a commit 121b586
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,28 @@ public function render(Varien_Data_Form_Element_Abstract $element)
{
$helper = Mage::helper('channable');
$storeIds = $helper->getStoreIds('channable/connect/enabled');
$token = Mage::getStoreConfig('channable/connect/token');
$token = Mage::helper('channable')->getToken();
$sHtml = '';

foreach ($storeIds as $storeId) {
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$channableFeed = $baseUrl . 'channable/feed/get/code/' . $token . '/store/' . $storeId . '/array/1';
$storeTitle = Mage::app()->getStore($storeId)->getName();
$url = "https://app.channable.com/connect/magento.html?";
$url .= "store_id=' . $storeId . '&url=' . $baseUrl . '&token=' . $token . '";
$msg = $this->__('Click to auto connect with Channable');
if ($token) {
foreach ($storeIds as $storeId) {
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$channableFeed = $baseUrl . 'channable/feed/get/code/' . $token . '/store/' . $storeId . '/array/1';
$storeTitle = Mage::app()->getStore($storeId)->getName();
$url = 'https://app.channable.com/connect/magento.html?';
$url .= 'store_id=' . $storeId . '&url=' . $baseUrl . '&token=' . $token;
$msg = $this->__('Click to auto connect with Channable');

$sHtml .= '<tr>
<td>' . $storeTitle . '</td>
<td><a href="' . $channableFeed . '">' . $this->__('Preview') . '</a></td>
<td><a href="' . $url . '" target="_blank">' . $msg . '</a></td>
</tr>';
$sHtml .= '<tr>
<td>' . $storeTitle . '</td>
<td><a href="' . $channableFeed . '">' . $this->__('Preview') . '</a></td>
<td><a href="' . $url . '" target="_blank">' . $msg . '</a></td>
</tr>';
}
}

if (!$sHtml) {
$html = $helper->__('No enabled feed(s) found');
$html = $helper->__('No enabled feed(s) found or token missing');
} else {
$html = '<div class="grid">
<table cellpadding="0" cellspacing="0" class="border" style="width:425px;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class Magmodules_Channable_Block_Adminhtml_System_Config_Form_Field_Token
*/
public function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
return Mage::getStoreConfig('channable/connect/token');
if ($token = Mage::helper('channable')->getToken()) {
return $token;
}

return '<a href="' . $this->getUrl('adminhtml/channable/createToken') . '">Create Token</a>';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function render(Varien_Data_Form_Element_Abstract $element)

$logoLink = '//www.magmodules.eu/logo/channable/' . $moduleVersion . '/' . $magentoVersion . '/logo.png';


$html = '<div style="background:url(\'' . $logoLink . '\') no-repeat scroll 15px center #EAF0EE;border:1px solid #CCCCCC;margin-bottom:10px;padding:10px 5px 5px 200px;">
<h4>About Magmodules.eu</h4>
<p>We are a Magento only E-commerce Agency located in the Netherlands.<br>
Expand Down
38 changes: 37 additions & 1 deletion app/code/community/Magmodules/Channable/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,10 @@ public function getParentData($product, $config)
public function getTypePrices($config, $products)
{
$typePrices = array();
if (!empty($config['conf_enabled'])) {
$confEnabled = $config['conf_enabled'];
$simplePrice = $config['simple_price'];

if (!empty($confEnabled) && empty($simplePrice)) {
foreach ($products as $product) {
if ($product->getTypeId() == 'configurable') {
$parentId = $product->getEntityId();
Expand Down Expand Up @@ -1228,4 +1231,37 @@ public function getProductUrlSuffix($storeId)

return $suffix;
}

public function getToken()
{
$token = $this->getUncachedConfigValue('channable/connect/token', 0);
$token = Mage::helper('core')->decrypt($token);
$strlen = strlen($token);

if ($strlen == 32 || $strlen == 16) {
if (ctype_alnum($token)) {
return $token;
}
}

return false;
}

/**
* @param $path
* @param int $storeId
*
* @return mixed
*/
public function getUncachedConfigValue($path, $storeId = 0)
{
$collection = Mage::getModel('core/config_data')->getCollection()->addFieldToFilter('path', $path);
if ($storeId == 0) {
$collection = $collection->addFieldToFilter('scope_id', 0)->addFieldToFilter('scope', 'default');
} else {
$collection = $collection->addFieldToFilter('scope_id', $storeId)->addFieldToFilter('scope', 'stores');
}

return $collection->getFirstItem()->getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function getFeedConfig($storeId)
$config['conf_fields'] = Mage::getStoreConfig('channable/data/conf_fields', $storeId);
$config['parent_att'] = $this->getParentAttributeSelection($config['conf_fields']);
$config['conf_switch_urls'] = Mage::getStoreConfig('channable/data/conf_switch_urls', $storeId);
$config['simple_price'] = Mage::getStoreConfig('channable/data/simple_price', $storeId);
$config['stock_manage'] = Mage::getStoreConfig('cataloginventory/item_options/manage_stock');
$config['use_qty_increments'] = Mage::getStoreConfig('cataloginventory/item_options/enable_qty_increments');
$config['qty_increments'] = Mage::getStoreConfig('cataloginventory/item_options/qty_increments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,37 @@ public function addToFlatAction()
$this->_redirect('adminhtml/system_config/edit/section/channable');
}

/**~
/**
* Token create / update function
*/
public function createTokenAction()
{
$oldToken = Mage::getModel('core/config_data')->getCollection()
->addFieldToFilter('path', 'channable/connect/token')
->addFieldToFilter('scope_id', 0)
->addFieldToFilter('scope', 'default')
->getFirstItem()
->getValue();

$token = '';
$chars = str_split("abcdefghijklmnopqrstuvwxyz0123456789");
for ($i = 0; $i < 32; $i++) {
$token .= $chars[array_rand($chars)];
}

Mage::getModel('core/config')->saveConfig('channable/connect/token', Mage::helper('core')->encrypt($token));

if (!empty($oldToken)) {
$msg = 'New Token created, please update Channable Dashboard with this new token';
} else {
$msg = 'New Token created, please link your account using the auto update';
}

Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('channable')->__($msg));
$this->_redirect('adminhtml/system_config/edit/section/channable');
}

/**
* @return mixed
*/
protected function _isAllowed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getAction()
$code = $this->getRequest()->getParam('code');
$page = $this->getRequest()->getParam('page');
if ($storeId && $code) {
if ($code == Mage::getStoreConfig('channable/connect/token')) {
if ($code == Mage::helper('channable')->getToken()) {
$timeStart = microtime(true);
$limit = Mage::getStoreConfig('channable/connect/max_products', $storeId);
$appEmulation = Mage::getSingleton('core/app_emulation');
Expand Down
14 changes: 12 additions & 2 deletions ...mmunity/Magmodules/Channable/data/magmodules_channable_setup/data-upgrade-1.4.8-1.4.9.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,15 @@
}
}

Mage::getModel('core/config')->saveConfig('channable/connect/token', Mage::helper('core')->encrypt($token));
Mage::app()->getCacheInstance()->cleanType('config');
$tokenEncrypted = Mage::getModel('core/config_data')->getCollection()
->addFieldToFilter('path', 'channable/connect/token_encrypted')
->addFieldToFilter('scope_id', 0)
->addFieldToFilter('scope', 'default')
->getFirstItem()
->getValue();

if (empty($tokenEncrypted)) {
$encrypt = Mage::helper('core')->encrypt($token);
Mage::getModel('core/config')->saveConfig('channable/connect/token_encrypted', 1);
Mage::getModel('core/config')->saveConfig('channable/connect/token', $encrypt);
}
2 changes: 1 addition & 1 deletion app/code/community/Magmodules/Channable/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@
</server>
</channable>
</default>
</config>
</config>
18 changes: 16 additions & 2 deletions app/code/community/Magmodules/Channable/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,24 @@
</depends>
<comment>Use the parent data</comment>
</conf_fields>
<simple_price translate="label">
<label>Use Simple Product Pricing</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>73</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<conf_enabled>1</conf_enabled>
</depends>
<comment>Only enable this option when you have enabled an extension that is using the simple prices in your store.</comment>
</simple_price>
<conf_switch_urls translate="label">
<label>Configurable Switch Urls</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>93</sort_order>
<sort_order>94</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -473,7 +486,7 @@
<label>Grouped Price</label>
<frontend_type>select</frontend_type>
<source_model>channable/adminhtml_system_config_source_pricemodel</source_model>
<sort_order>94</sort_order>
<sort_order>95</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down Expand Up @@ -616,6 +629,7 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>This function is only working when you still have the product visible in the front-end when it's out of stock.</comment>
</stock>
<advanced_heading translate="label">
<label>Advanced</label>
Expand Down
1 change: 1 addition & 0 deletions app/locale/en_US/Magmodules_Channable.csv
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"This option allows you to include/exclude product from the Channable feed. <br>","This option allows you to include/exclude product from the Channable feed. <br>"
"This overwrites the maximum amount of memory in bytes that a script is allowed to allocate, eg 1024M.","This overwrites the maximum amount of memory in bytes that a script is allowed to allocate, eg 1024M."
"This overwrites the maximum time in seconds a script is allowed to run before it is terminated by the parser, eg: 300 (for 5 minutes).","This overwrites the maximum time in seconds a script is allowed to run before it is terminated by the parser, eg: 300 (for 5 minutes)."
"This function is only working when you still have the product visible in the front-end when it's out of stock.","This function is only working when you still have the product visible in the front-end when it's out of stock."
"Type of the filter","Type of the filter"
"Use default","Use default"
"Use the parent data","Use the parent data"
Expand Down
1 change: 1 addition & 0 deletions app/locale/nl_NL/Magmodules_Channable.csv
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"The Memory Limit","Geheugen limiet"
"Type of the filter","Type filter"
"This overwrites the maximum amount of memory in bytes that a script is allowed to allocate, eg 1024M.","Dit overschrijft de maximale hoeveelheid geheugen in bytes dat het script maximaal mag gebruiken, bijvoorbeeld 1024M."
"This function is only working when you still have the product visible in the front-end when it's out of stock.","Deze functie werkt enkel indien het product welke uit de voorraad is nog steeds zichtbaar is in de front-end."
"Max Execution Time","Maximale uitvoer tijd"
"This overwrites the maximum time in seconds a script is allowed to run before it is terminated by the parser, eg: 300 (for 5 minutes).","Dit overschrijft de maximale tijd in seconden dat het script mag draaien voordat het wordt beëindigd, bijvoorbeeld: 300 (5 minuten)."
"Only use this option if it's necessary to overwrite this setting because of your server memory limit or execution time.","Gebruik deze optie alleen als het nodig is om de instelling van het geheugen limiet of uitvoertijd van je server te overschrijven."
Expand Down

0 comments on commit 121b586

Please sign in to comment.