Advertisement
Guest User

Untitled

a guest
Jun 15th, 2014
914
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.04 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Aquatuning Software Development - Country Choice Plugin - Bootstrap
  5. *
  6. * @category Aquatuning
  7. * @package Shopware\Plugins\AtsdCountryChoice
  8. * @copyright Copyright (c) 2013, Aquatuning GmbH
  9. */
  10.  
  11. class Shopware_Plugins_Frontend_AtsdCountryChoice_Bootstrap extends Shopware_Components_Plugin_Bootstrap
  12. {
  13.  
  14. // info
  15. private $plugin_info = array(
  16. 'version' => "1.0.0",
  17. 'label' => "ATSD - Länderauswahl definieren",
  18. 'description' => "Wahlweise Länder sperren, hinzufügen oder Reihenfolge ändern",
  19. 'supplier' => "Aquatuning GmbH",
  20. 'autor' => "Aquatuning GmbH",
  21. 'support' => "Aquatuning GmbH",
  22. 'copyright' => "Aquatuning GmbH",
  23. 'link' => 'http://www.aquatuning.de',
  24. 'source' => null,
  25. 'changes' => null,
  26. 'license' => null,
  27. 'revision' => null
  28. );
  29.  
  30. // getCapabilities
  31. private $plugin_capabilities = array(
  32. 'install' => true,
  33. 'update' => true,
  34. 'enable' => true
  35. );
  36.  
  37.  
  38.  
  39. /**
  40. * Returns the current version of the plugin.
  41. *
  42. * @return string
  43. */
  44.  
  45. public function getVersion()
  46. {
  47. return $this->plugin_info['version'];
  48. }
  49.  
  50.  
  51.  
  52. /**
  53. * Get (nice) name for the plugin manager list
  54. *
  55. * @return string
  56. */
  57.  
  58. public function getLabel()
  59. {
  60. return $this->plugin_info['label'];
  61. }
  62.  
  63.  
  64.  
  65. /**
  66. * Get full information for the plugin manager list
  67. * @return array
  68. */
  69.  
  70. public function getInfo()
  71. {
  72. return $this->plugin_info;
  73. }
  74.  
  75.  
  76.  
  77. /**
  78. * Get capabilities for the plugin manager
  79. *
  80. * @return array
  81. */
  82.  
  83. public function getCapabilities()
  84. {
  85. return $this->plugin_capabilities;
  86. }
  87.  
  88.  
  89.  
  90. /**
  91. * Creates the configuration fields and subscribes the post dispatch event of the frontend listing container.
  92. *
  93. * @return bool
  94. */
  95.  
  96. public function install()
  97. {
  98. // subscribe to events
  99. $this->installSubscribeEvents();
  100.  
  101. // create the form
  102. $this->installCreateConfigForm();
  103.  
  104. // done
  105. return array(
  106. 'success' => true,
  107. 'invalidateCache' => array( "frontend", "backend", "config" )
  108. );
  109. }
  110.  
  111.  
  112.  
  113. /**
  114. * Creates the configuration form for the plugin
  115. *
  116. * @return void
  117. */
  118.  
  119. protected function installCreateConfigForm()
  120. {
  121. // get the form
  122. $form = $this->Form();
  123.  
  124. // create the element
  125. $form->setElement( "text", "availableCountries", array(
  126. 'label' => "Freigeschaltete Länder",
  127. 'description' => "Alle für den angegebenen Shop freigegebenen Länder im ISO 2 Format per Komma getrennt (zb DE,GB,FR). Freilassen für alle Länder",
  128. 'required' => false,
  129. 'value' => "",
  130. 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
  131. ));
  132.  
  133. // create the element
  134. $form->setElement( "text", "restrictedCountries", array(
  135. 'label' => "Gesperrte Länder",
  136. 'description' => "Alle für den angegebenen Shop gesperrten Länder im ISO 2 Format per Komma getrennt (zb DE,GB,FR).",
  137. 'required' => false,
  138. 'value' => "",
  139. 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
  140. ));
  141.  
  142. // create the element
  143. $form->setElement( "text", "sortCountries", array(
  144. 'label' => "Reihenfolge",
  145. 'description' => "Die hier angegebenen Länder werden in der Reihenfolge ganz oben angezeigt (zb DE,GB,FR).",
  146. 'required' => false,
  147. 'value' => "",
  148. 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
  149. ));
  150. }
  151.  
  152.  
  153.  
  154. /**
  155. * Registers all necessary events and hooks.
  156. *
  157. * @return void
  158. */
  159.  
  160. private function installSubscribeEvents()
  161. {
  162. $this->subscribeEvent(
  163. "Shopware_Modules_Admin_GetCountries_FilterResult",
  164. "getCountriesFilter"
  165. );
  166. }
  167.  
  168.  
  169.  
  170. public function getCountriesFilter( Enlight_Event_EventArgs $arguments )
  171. {
  172. // get parent return
  173. $countries = $arguments->getReturn();
  174.  
  175. // get shop id
  176. $shopid = $arguments->getSubject()->subshopId;
  177.  
  178.  
  179.  
  180. // get configuration
  181. $availableCountries = $this->Config()->get( "availableCountries" );
  182. $restrictedCountries = $this->Config()->get( "restrictedCountries" );
  183. $sortCountries = $this->Config()->get( "sortCountries" );
  184.  
  185. // trim it
  186. $availableCountries = trim( $availableCountries );
  187. $restrictedCountries = trim( $restrictedCountries );
  188. $sortCountries = trim( $sortCountries );
  189.  
  190.  
  191.  
  192. // available countries?
  193. if ( !empty( $availableCountries ) )
  194. {
  195. // make it an array
  196. $availableCountries = explode( ",", $availableCountries );
  197.  
  198. // my new array
  199. $arr = array();
  200.  
  201. // loop through all countries
  202. foreach ( $countries as $country )
  203. {
  204. // country available?
  205. if ( in_array( $country['countryiso'], $availableCountries ) )
  206. // use it
  207. array_push( $arr, $country );
  208. }
  209.  
  210. // save it back
  211. $countries = $arr;
  212. }
  213.  
  214.  
  215.  
  216. // restricted countries?
  217. if ( !empty( $restrictedCountries ) )
  218. {
  219. // make it an array
  220. $restrictedCountries = explode( ",", $restrictedCountries );
  221.  
  222. // my new array
  223. $arr = array();
  224.  
  225. // loop through all countries
  226. foreach ( $countries as $country )
  227. {
  228. // country available?
  229. if ( !in_array( $country['countryiso'], $restrictedCountries ) )
  230. // use it
  231. array_push( $arr, $country );
  232. }
  233.  
  234. // save it back
  235. $countries = $arr;
  236. }
  237.  
  238.  
  239.  
  240. // sort it?
  241. if ( !empty( $sortCountries ) )
  242. {
  243. // make it an array
  244. $sortCountries = explode( ",", $sortCountries );
  245.  
  246. // both array to merge
  247. $sorted = array();
  248. $rest = array();
  249.  
  250. // loop all countries
  251. foreach ( $countries as $country )
  252. {
  253. // to sort?
  254. if ( in_array( $country['countryiso'], $sortCountries ) )
  255. // save the shit
  256. $sorted[array_search( $country['countryiso'], $sortCountries )] = $country;
  257. // not to sort
  258. else
  259. // just add to the rest
  260. array_push( $rest, $country );
  261. }
  262.  
  263. // sort our sorted by key
  264. ksort( $sorted );
  265.  
  266. // the new array
  267. $countries = array();
  268.  
  269. // add our sorted to the beginning
  270. foreach ( $sorted as $country )
  271. array_push( $countries, $country );
  272.  
  273. // then the remaining countries
  274. foreach ( $rest as $country )
  275. array_push( $countries, $country );
  276.  
  277. }
  278.  
  279.  
  280.  
  281. // and return them
  282. return $countries;
  283. }
  284.  
  285.  
  286.  
  287. public function uninstall()
  288. {
  289. return true;
  290. }
  291.  
  292. public function update()
  293. {
  294. return true;
  295. }
  296.  
  297.  
  298.  
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement