Guest User

Untitled

a guest
Jan 13th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. <fields>
  2. <goldprice translate="label">
  3. <label>GoldPrice</label>
  4. <frontend_type>text</frontend_type>
  5. <sort_order>0</sort_order>
  6. <show_in_default>1</show_in_default>
  7. <show_in_website>1</show_in_website>
  8. <show_in_store>1</show_in_store>
  9. <comment>Gold Price per 1gm</comment>
  10. </goldprice>
  11. <run translate="label">
  12. <frontend_type>button</frontend_type>
  13. <frontend_model>letsnurture_customgrid/adminhtml_system_config_customfield</frontend_model>
  14. <sort_order>30</sort_order>
  15. <show_in_default>1</show_in_default>
  16. <show_in_website>1</show_in_website>
  17. <show_in_store>1</show_in_store>
  18. </run>
  19. </fields>
  20.  
  21. <?xml version="1.0"?>
  22. <config>
  23. <modules>
  24. <LetsNurture_CustomGrid>
  25. <version>0.1.0</version>
  26. </LetsNurture_CustomGrid>
  27. </modules>
  28. <global>
  29. <blocks>
  30. <customgrid>
  31. <class>LetsNurture_CustomGrid_Block</class>
  32. </customgrid>
  33. </blocks>
  34. <models>
  35. <class>LetsNurture_CustomGrid_Model</class>
  36. </models>
  37. <helpers>
  38. <customgrid>
  39. <class>LetsNurture_CustomGrid_Helper</class>
  40. </customgrid>
  41. </helpers>
  42. <events>
  43. <admin_system_config_changed_section_gold> <!-- identifier of the event we want to catch -->
  44. <observers>
  45. <customgrid>
  46. <type>model</type>
  47. <class>LetsNurture_CustomGrid_Model_Observer</class>
  48. <method>UpdatePrice</method>
  49. </customgrid>
  50. </observers>
  51. </admin_system_config_changed_section_gold>
  52. </events>
  53. </global>
  54. </config>
  55.  
  56. class LetsNurture_CustomGrid_Block_Adminhtml_System_Config_Customfield extends Mage_Adminhtml_Block_System_Config_Form_Field
  57. {
  58. protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
  59. {
  60. $url = $this->getUrl('catalog/product'); //
  61.  
  62. $html = $this->getLayout()->createBlock('adminhtml/widget_button')
  63. ->setType('button')
  64. ->setClass('scalable')
  65. ->setLabel('Run Now !')
  66. ->setOnClick("setLocation('$url')")
  67. ->toHtml();
  68.  
  69.  
  70. return $html;
  71. }
  72. }
  73.  
  74. <frontend_model>NAMESPACE_MODULENAME/adminhtml_system_config_customfield</frontend_model>
  75.  
  76. class NAMESPACE_MODULENAME_Block_Adminhtml_System_Config_Customfield extends Mage_Adminhtml_Block_System_Config_Form_Field
  77. {
  78.  
  79.  
  80. protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
  81. {
  82. $html = parent::_getElementHtml($element);
  83. //Write your custom html here
  84. return $html;
  85. }
  86. }
  87.  
  88. <crontab>
  89. <jobs>
  90. <sariina_payvast_purchase_price_update>
  91. <schedule>
  92. <cron_expr>* 1 * * *</cron_expr>
  93. </schedule>
  94. <run>
  95. <model>sariina_payvast/observer::getMerchandiseLastBuyRate</model>
  96. </run>
  97. </sariina_payvast_purchase_price_update>
  98. <sariina_payvast_stock_update>
  99. <schedule>
  100. <cron_expr>30 1 * * *</cron_expr>
  101. </schedule>
  102. <run>
  103. <model>sariina_payvast/observer::getMerchandiseRemainForAllStockRooms</model>
  104. </run>
  105. </sariina_payvast_stock_update>
  106. </jobs>
  107. </crontab>
  108.  
  109. public function getMerchandiseLastBuyRate()
  110. {
  111. if (Mage::getStoreConfig('payvast/general/enable_purchase_price'))
  112. {
  113. Mage::log('Payvast LastBuyRate Update Start...', null, 'payvast.log');
  114.  
  115. $client = new SoapClient(Mage::getStoreConfig('payvast/general/url'));
  116. $products = Mage::getModel('catalog/product')->getCollection();
  117. $products->addAttributeToSelect('sku');
  118. $products->addAttributeToSelect('last_purchase_price');
  119. foreach($products as $product)
  120. {
  121. Mage::log('Updating Last Purchase Price for '.$product->getSku(), null, 'payvast.log');
  122. $params = array(
  123. 'merchandiseCode' => $product->getSku()
  124. );
  125. $response = $client->GetMerchandiseLastBuyRate($params);
  126. //Mage::log($response, null, 'payvast.log');
  127. if ($product->getLastPurchasePrice() != $response->GetMerchandiseLastBuyRateResult/10)
  128. {
  129. /* Rial to Toman */
  130. $product->setLastPurchasePrice($response->GetMerchandiseLastBuyRateResult/10)->save();
  131. }
  132. }
  133.  
  134. Mage::log('Payvast LastBuyRate Update Finished.', null, 'payvast.log');
  135. }
  136. }
  137.  
  138. public function getMerchandiseRemainForAllStockRooms()
  139. {
  140. if (Mage::getStoreConfig('payvast/general/enable_stock'))
  141. {
  142. Mage::log('Payvast Stock Update Start...', null, 'payvast.log');
  143.  
  144. $client = new SoapClient(Mage::getStoreConfig('payvast/general/url'));
  145. $products = Mage::getModel('catalog/product')->getCollection();
  146. $products->addAttributeToSelect('sku');
  147. foreach($products as $product)
  148. {
  149. Mage::log('Updating Stock for '.$product->getSku(), null, 'payvast.log');
  150. $date = date("Y-m-d");
  151. $fiscalPeriod = Mage::getStoreConfig('payvast/general/fiscal_period');
  152. $username = Mage::getStoreConfig('payvast/general/username');
  153. $password = Mage::getStoreConfig('payvast/general/password');
  154. $params = array(
  155. 'merchandiseCode' => $product->getSku(),
  156. 'date' => $date,
  157. 'fiscalPeriod' => $fiscalPeriod,
  158. 'username' => $username,
  159. 'password' => $password
  160. );
  161. $response = $client->GetMerchandiseRemainForAllStockRooms($params);
  162. //Mage::log($response, null, 'payvast.log');
  163. $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
  164. if ($stockItem->getId() > 0 and $stockItem->getManageStock())
  165. {
  166. $qty = $response->GetMerchandiseRemainForAllStockRoomsResult;
  167. if ($stockItem->getQty() != $qty)
  168. {
  169. $stockItem->setQty($qty);
  170. $stockItem->setIsInStock((int)($qty > 0));
  171. $stockItem->save();
  172. }
  173. }
  174. }
  175.  
  176. Mage::log('Payvast Stock Update Finished.', null, 'payvast.log');
  177. }
  178. }
Add Comment
Please, Sign In to add comment