Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Aquatuning Software Development - Multishop Order Number Group - Bootstrap
- *
- * 1.0.0
- * - initial release
- *
- * 1.0.1
- * - code cleanup
- *
- * @category Aquatuning
- * @package Shopware\Plugins\AtsdMultishopOrderNumberGroup
- * @copyright Copyright (c) 2013, Aquatuning GmbH
- */
- class Shopware_Plugins_Frontend_AtsdMultishopOrderNumberGroup_Bootstrap extends Shopware_Components_Plugin_Bootstrap
- {
- // info
- private $plugin_info = array(
- 'version' => "1.0.1",
- 'label' => "ATSD - Präfix für Bestellnummer",
- 'description' => "Setzt einen Präfix vor die Bestellnummer je nach Shop (Haupt- oder Multishop)",
- '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
- );
- // length
- private $orderNumberLength = 8;
- // first digit
- private $orderNumberFirst = 10000;
- /**
- * 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" )
- );
- }
- /**
- * Registers all necessary events and hooks.
- *
- * @return void
- */
- private function installSubscribeEvents()
- {
- //
- $this->subscribeEvent(
- "sOrder::sGetOrderNumber::replace",
- "replaceGetOrderNumberHook"
- );
- }
- /**
- * Creates the configuration form for the plugin
- *
- * @return void
- */
- protected function installCreateConfigForm()
- {
- // get the form
- $form = $this->Form();
- // create the element
- $form->setElement( "number", "orderPrefix", array(
- 'label' => "Präfix für Bestellnummer",
- 'description' => "Präfix für Bestellnummer für Haupt- und Multishops getrennt",
- 'minValue' => 10,
- 'maxValue' => 99,
- 'required' => true,
- 'value' => 10,
- 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
- ));
- }
- /**
- * ...
- *
- * @param Enlight_Hook_HookArgs $arguments
- *
- * @return void
- */
- public function replaceGetOrderNumberHook( Enlight_Hook_HookArgs $arguments )
- {
- // get shop id
- $shop = Shopware()->Shop()->getMain() !== null ? Shopware()->Shop()->getMain() : Shopware()->Shop();
- $subshopId = $shop->getId();
- // get prefix from configuration
- $prefix = $this->Config()->get( "orderPrefix" );
- // get invoice sub-name
- $invoice = "invoice-shop-" . $subshopId;
- // get current max order id
- $query = "SELECT number FROM s_order_number WHERE name = '" . $invoice . "'";
- $res = Shopware()->Db()->query( $query );
- $row = $res->fetch();
- // current order found?
- if ( $row === false )
- {
- // create number
- $number = $prefix . str_pad( $this->orderNumberFirst, $this->orderNumberLength - 2, "0", STR_PAD_LEFT );
- // insert order number
- $query = "INSERT INTO s_order_number SET `number` = '" . $number . "', `name` = '" . $invoice . "', `desc` = '" . $invoice . "'";
- Shopware()->Db()->query( $query );
- }
- else
- {
- // add 1 to the number
- $number = $row['number'] + 1;
- // update max order
- $query = "UPDATE s_order_number SET number = number + 1 WHERE name = '" . $invoice . "'";
- Shopware()->Db()->query( $query );
- }
- // cast it
- $number = (string) $number;
- // save it
- $arguments->setReturn( $number );
- // finished
- return;
- }
- /**
- * Uninstall our plugin.
- *
- * @return boolean
- */
- public function uninstall()
- {
- // done
- return true;
- }
- /**
- * Update our plugin if necessary.
- *
- * @return boolean
- */
- public function update()
- {
- // nothing to do here
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement