Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Aquatuning Software Development - Country Choice Plugin - Bootstrap
- *
- * @category Aquatuning
- * @package Shopware\Plugins\AtsdCountryChoice
- * @copyright Copyright (c) 2013, Aquatuning GmbH
- */
- class Shopware_Plugins_Frontend_AtsdCountryChoice_Bootstrap extends Shopware_Components_Plugin_Bootstrap
- {
- // info
- private $plugin_info = array(
- 'version' => "1.0.0",
- 'label' => "ATSD - Länderauswahl definieren",
- 'description' => "Wahlweise Länder sperren, hinzufügen oder Reihenfolge ändern",
- 'supplier' => "Aquatuning GmbH",
- 'autor' => "Aquatuning GmbH",
- 'support' => "Aquatuning GmbH",
- 'copyright' => "Aquatuning GmbH",
- 'link' => 'http://www.aquatuning.de',
- 'source' => null,
- 'changes' => null,
- 'license' => null,
- 'revision' => null
- );
- // getCapabilities
- private $plugin_capabilities = array(
- 'install' => true,
- 'update' => true,
- 'enable' => true
- );
- /**
- * Returns the current version of the plugin.
- *
- * @return string
- */
- public function getVersion()
- {
- return $this->plugin_info['version'];
- }
- /**
- * Get (nice) name for the plugin manager list
- *
- * @return string
- */
- public function getLabel()
- {
- return $this->plugin_info['label'];
- }
- /**
- * Get full information for the plugin manager list
- * @return array
- */
- public function getInfo()
- {
- return $this->plugin_info;
- }
- /**
- * Get capabilities for the plugin manager
- *
- * @return array
- */
- public function getCapabilities()
- {
- return $this->plugin_capabilities;
- }
- /**
- * Creates the configuration fields and subscribes the post dispatch event of the frontend listing container.
- *
- * @return bool
- */
- public function install()
- {
- // subscribe to events
- $this->installSubscribeEvents();
- // create the form
- $this->installCreateConfigForm();
- // done
- return array(
- 'success' => true,
- 'invalidateCache' => array( "frontend", "backend", "config" )
- );
- }
- /**
- * Creates the configuration form for the plugin
- *
- * @return void
- */
- protected function installCreateConfigForm()
- {
- // get the form
- $form = $this->Form();
- // create the element
- $form->setElement( "text", "availableCountries", array(
- 'label' => "Freigeschaltete Länder",
- '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",
- 'required' => false,
- 'value' => "",
- 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
- ));
- // create the element
- $form->setElement( "text", "restrictedCountries", array(
- 'label' => "Gesperrte Länder",
- 'description' => "Alle für den angegebenen Shop gesperrten Länder im ISO 2 Format per Komma getrennt (zb DE,GB,FR).",
- 'required' => false,
- 'value' => "",
- 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
- ));
- // create the element
- $form->setElement( "text", "sortCountries", array(
- 'label' => "Reihenfolge",
- 'description' => "Die hier angegebenen Länder werden in der Reihenfolge ganz oben angezeigt (zb DE,GB,FR).",
- 'required' => false,
- 'value' => "",
- 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
- ));
- }
- /**
- * Registers all necessary events and hooks.
- *
- * @return void
- */
- private function installSubscribeEvents()
- {
- $this->subscribeEvent(
- "Shopware_Modules_Admin_GetCountries_FilterResult",
- "getCountriesFilter"
- );
- }
- public function getCountriesFilter( Enlight_Event_EventArgs $arguments )
- {
- // get parent return
- $countries = $arguments->getReturn();
- // get shop id
- $shopid = $arguments->getSubject()->subshopId;
- // get configuration
- $availableCountries = $this->Config()->get( "availableCountries" );
- $restrictedCountries = $this->Config()->get( "restrictedCountries" );
- $sortCountries = $this->Config()->get( "sortCountries" );
- // trim it
- $availableCountries = trim( $availableCountries );
- $restrictedCountries = trim( $restrictedCountries );
- $sortCountries = trim( $sortCountries );
- // available countries?
- if ( !empty( $availableCountries ) )
- {
- // make it an array
- $availableCountries = explode( ",", $availableCountries );
- // my new array
- $arr = array();
- // loop through all countries
- foreach ( $countries as $country )
- {
- // country available?
- if ( in_array( $country['countryiso'], $availableCountries ) )
- // use it
- array_push( $arr, $country );
- }
- // save it back
- $countries = $arr;
- }
- // restricted countries?
- if ( !empty( $restrictedCountries ) )
- {
- // make it an array
- $restrictedCountries = explode( ",", $restrictedCountries );
- // my new array
- $arr = array();
- // loop through all countries
- foreach ( $countries as $country )
- {
- // country available?
- if ( !in_array( $country['countryiso'], $restrictedCountries ) )
- // use it
- array_push( $arr, $country );
- }
- // save it back
- $countries = $arr;
- }
- // sort it?
- if ( !empty( $sortCountries ) )
- {
- // make it an array
- $sortCountries = explode( ",", $sortCountries );
- // both array to merge
- $sorted = array();
- $rest = array();
- // loop all countries
- foreach ( $countries as $country )
- {
- // to sort?
- if ( in_array( $country['countryiso'], $sortCountries ) )
- // save the shit
- $sorted[array_search( $country['countryiso'], $sortCountries )] = $country;
- // not to sort
- else
- // just add to the rest
- array_push( $rest, $country );
- }
- // sort our sorted by key
- ksort( $sorted );
- // the new array
- $countries = array();
- // add our sorted to the beginning
- foreach ( $sorted as $country )
- array_push( $countries, $country );
- // then the remaining countries
- foreach ( $rest as $country )
- array_push( $countries, $country );
- }
- // and return them
- return $countries;
- }
- public function uninstall()
- {
- return true;
- }
- public function update()
- {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement