Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <fields>
- <goldprice translate="label">
- <label>GoldPrice</label>
- <frontend_type>text</frontend_type>
- <sort_order>0</sort_order>
- <show_in_default>1</show_in_default>
- <show_in_website>1</show_in_website>
- <show_in_store>1</show_in_store>
- <comment>Gold Price per 1gm</comment>
- </goldprice>
- <run translate="label">
- <frontend_type>button</frontend_type>
- <frontend_model>letsnurture_customgrid/adminhtml_system_config_customfield</frontend_model>
- <sort_order>30</sort_order>
- <show_in_default>1</show_in_default>
- <show_in_website>1</show_in_website>
- <show_in_store>1</show_in_store>
- </run>
- </fields>
- <?xml version="1.0"?>
- <config>
- <modules>
- <LetsNurture_CustomGrid>
- <version>0.1.0</version>
- </LetsNurture_CustomGrid>
- </modules>
- <global>
- <blocks>
- <customgrid>
- <class>LetsNurture_CustomGrid_Block</class>
- </customgrid>
- </blocks>
- <models>
- <class>LetsNurture_CustomGrid_Model</class>
- </models>
- <helpers>
- <customgrid>
- <class>LetsNurture_CustomGrid_Helper</class>
- </customgrid>
- </helpers>
- <events>
- <admin_system_config_changed_section_gold> <!-- identifier of the event we want to catch -->
- <observers>
- <customgrid>
- <type>model</type>
- <class>LetsNurture_CustomGrid_Model_Observer</class>
- <method>UpdatePrice</method>
- </customgrid>
- </observers>
- </admin_system_config_changed_section_gold>
- </events>
- </global>
- </config>
- class LetsNurture_CustomGrid_Block_Adminhtml_System_Config_Customfield extends Mage_Adminhtml_Block_System_Config_Form_Field
- {
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
- {
- $url = $this->getUrl('catalog/product'); //
- $html = $this->getLayout()->createBlock('adminhtml/widget_button')
- ->setType('button')
- ->setClass('scalable')
- ->setLabel('Run Now !')
- ->setOnClick("setLocation('$url')")
- ->toHtml();
- return $html;
- }
- }
- <frontend_model>NAMESPACE_MODULENAME/adminhtml_system_config_customfield</frontend_model>
- class NAMESPACE_MODULENAME_Block_Adminhtml_System_Config_Customfield extends Mage_Adminhtml_Block_System_Config_Form_Field
- {
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
- {
- $html = parent::_getElementHtml($element);
- //Write your custom html here
- return $html;
- }
- }
- <crontab>
- <jobs>
- <sariina_payvast_purchase_price_update>
- <schedule>
- <cron_expr>* 1 * * *</cron_expr>
- </schedule>
- <run>
- <model>sariina_payvast/observer::getMerchandiseLastBuyRate</model>
- </run>
- </sariina_payvast_purchase_price_update>
- <sariina_payvast_stock_update>
- <schedule>
- <cron_expr>30 1 * * *</cron_expr>
- </schedule>
- <run>
- <model>sariina_payvast/observer::getMerchandiseRemainForAllStockRooms</model>
- </run>
- </sariina_payvast_stock_update>
- </jobs>
- </crontab>
- public function getMerchandiseLastBuyRate()
- {
- if (Mage::getStoreConfig('payvast/general/enable_purchase_price'))
- {
- Mage::log('Payvast LastBuyRate Update Start...', null, 'payvast.log');
- $client = new SoapClient(Mage::getStoreConfig('payvast/general/url'));
- $products = Mage::getModel('catalog/product')->getCollection();
- $products->addAttributeToSelect('sku');
- $products->addAttributeToSelect('last_purchase_price');
- foreach($products as $product)
- {
- Mage::log('Updating Last Purchase Price for '.$product->getSku(), null, 'payvast.log');
- $params = array(
- 'merchandiseCode' => $product->getSku()
- );
- $response = $client->GetMerchandiseLastBuyRate($params);
- //Mage::log($response, null, 'payvast.log');
- if ($product->getLastPurchasePrice() != $response->GetMerchandiseLastBuyRateResult/10)
- {
- /* Rial to Toman */
- $product->setLastPurchasePrice($response->GetMerchandiseLastBuyRateResult/10)->save();
- }
- }
- Mage::log('Payvast LastBuyRate Update Finished.', null, 'payvast.log');
- }
- }
- public function getMerchandiseRemainForAllStockRooms()
- {
- if (Mage::getStoreConfig('payvast/general/enable_stock'))
- {
- Mage::log('Payvast Stock Update Start...', null, 'payvast.log');
- $client = new SoapClient(Mage::getStoreConfig('payvast/general/url'));
- $products = Mage::getModel('catalog/product')->getCollection();
- $products->addAttributeToSelect('sku');
- foreach($products as $product)
- {
- Mage::log('Updating Stock for '.$product->getSku(), null, 'payvast.log');
- $date = date("Y-m-d");
- $fiscalPeriod = Mage::getStoreConfig('payvast/general/fiscal_period');
- $username = Mage::getStoreConfig('payvast/general/username');
- $password = Mage::getStoreConfig('payvast/general/password');
- $params = array(
- 'merchandiseCode' => $product->getSku(),
- 'date' => $date,
- 'fiscalPeriod' => $fiscalPeriod,
- 'username' => $username,
- 'password' => $password
- );
- $response = $client->GetMerchandiseRemainForAllStockRooms($params);
- //Mage::log($response, null, 'payvast.log');
- $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
- if ($stockItem->getId() > 0 and $stockItem->getManageStock())
- {
- $qty = $response->GetMerchandiseRemainForAllStockRoomsResult;
- if ($stockItem->getQty() != $qty)
- {
- $stockItem->setQty($qty);
- $stockItem->setIsInStock((int)($qty > 0));
- $stockItem->save();
- }
- }
- }
- Mage::log('Payvast Stock Update Finished.', null, 'payvast.log');
- }
- }
Add Comment
Please, Sign In to add comment