Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
1,317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.86 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Aquatuning Software Development - Multishop Order Number Group - Bootstrap
  5.  *
  6.  * 1.0.0
  7.  * - initial release
  8.  *
  9.  * 1.0.1
  10.  * - code cleanup
  11.  *
  12.  * @category  Aquatuning
  13.  * @package   Shopware\Plugins\AtsdMultishopOrderNumberGroup
  14.  * @copyright Copyright (c) 2013, Aquatuning GmbH
  15.  */
  16.  
  17. class Shopware_Plugins_Frontend_AtsdMultishopOrderNumberGroup_Bootstrap extends Shopware_Components_Plugin_Bootstrap
  18. {
  19.    
  20.     // info
  21.     private $plugin_info = array(
  22.         'version'     => "1.0.1",
  23.         'label'       => "ATSD - Präfix für Bestellnummer",
  24.         'description' => "Setzt einen Präfix vor die Bestellnummer je nach Shop (Haupt- oder Multishop)",
  25.         'supplier'    => "Aquatuning GmbH",
  26.         'autor'       => "Aquatuning GmbH",
  27.         'support'     => "Aquatuning GmbH",
  28.         'copyright'   => "Aquatuning GmbH",
  29.         'link'        => 'http://www.aquatuning.de',
  30.         'source'      => null,
  31.         'changes'     => null,
  32.         'license'     => null,
  33.         'revision'    => null
  34.     );
  35.    
  36.     // getCapabilities
  37.     private $plugin_capabilities = array(
  38.         'install' => true,
  39.         'update'  => true,
  40.         'enable'  => true
  41.     );
  42.    
  43.     // length
  44.     private $orderNumberLength = 8;
  45.    
  46.     // first digit
  47.     private $orderNumberFirst = 10000;
  48.        
  49.    
  50.    
  51.     /**
  52.      * Returns the current version of the plugin.
  53.      *
  54.      * @return string
  55.      */
  56.    
  57.     public function getVersion()
  58.     {
  59.         return $this->plugin_info['version'];
  60.     }
  61.    
  62.    
  63.    
  64.     /**
  65.      * Get (nice) name for the plugin manager list
  66.      *
  67.      * @return string
  68.      */
  69.    
  70.     public function getLabel()
  71.     {
  72.         return $this->plugin_info['label'];
  73.     }
  74.    
  75.  
  76.    
  77.     /**
  78.      * Get full information for the plugin manager list
  79.      * @return array
  80.      */
  81.    
  82.     public function getInfo()
  83.     {
  84.         return $this->plugin_info;
  85.     }
  86.      
  87.  
  88.      
  89.     /**
  90.      * Get capabilities for the plugin manager
  91.      *
  92.      * @return array
  93.      */
  94.    
  95.     public function getCapabilities()
  96.     {
  97.         return $this->plugin_capabilities;
  98.     }    
  99.    
  100.    
  101.    
  102.     /**
  103.      * Creates the configuration fields and subscribes the post dispatch event of the frontend listing container.
  104.      *
  105.      * @return bool
  106.      */
  107.    
  108.     public function install()
  109.     {
  110.         // subscribe to events
  111.         $this->installSubscribeEvents();
  112.  
  113.         // create the form
  114.         $this->installCreateConfigForm();
  115.        
  116.         // done
  117.         return array(
  118.             'success'         => true,
  119.             'invalidateCache' => array( "frontend", "backend", "config" )
  120.         );
  121.     }
  122.  
  123.  
  124.  
  125.    
  126.    
  127.     /**
  128.      * Registers all necessary events and hooks.
  129.      *
  130.      * @return void
  131.      */
  132.    
  133.     private function installSubscribeEvents()
  134.     {
  135.         //
  136.         $this->subscribeEvent(
  137.             "sOrder::sGetOrderNumber::replace",
  138.             "replaceGetOrderNumberHook"
  139.         );
  140.     }
  141.    
  142.    
  143.    
  144.  
  145.     /**
  146.      * Creates the configuration form for the plugin
  147.      *
  148.      * @return void
  149.      */
  150.    
  151.     protected function installCreateConfigForm()
  152.     {
  153.         // get the form
  154.         $form = $this->Form();
  155.        
  156.         // create the element
  157.         $form->setElement( "number", "orderPrefix", array(
  158.             'label'       => "Präfix für Bestellnummer",
  159.             'description' => "Präfix für Bestellnummer für Haupt- und Multishops getrennt",
  160.             'minValue'    => 10,
  161.             'maxValue'    => 99,
  162.             'required'    => true,
  163.             'value'       => 10,
  164.             'scope'       => \Shopware\Models\Config\Element::SCOPE_SHOP
  165.         ));
  166.     }
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.     /**
  174.      * ...
  175.      *
  176.      * @param Enlight_Hook_HookArgs   $arguments
  177.      *
  178.      * @return void
  179.      */
  180.  
  181.     public function replaceGetOrderNumberHook( Enlight_Hook_HookArgs $arguments )
  182.     {
  183.         // get shop id
  184.         $shop = Shopware()->Shop()->getMain() !== null ? Shopware()->Shop()->getMain() : Shopware()->Shop();
  185.         $subshopId = $shop->getId();
  186.  
  187.         // get prefix from configuration
  188.         $prefix = $this->Config()->get( "orderPrefix" );
  189.        
  190.         // get invoice sub-name
  191.         $invoice = "invoice-shop-" . $subshopId;
  192.        
  193.         // get current max order id
  194.         $query = "SELECT number FROM s_order_number WHERE name = '" . $invoice . "'";
  195.         $res = Shopware()->Db()->query( $query );
  196.         $row = $res->fetch();
  197.        
  198.         // current order found?
  199.         if ( $row === false )
  200.         {
  201.             // create number
  202.             $number = $prefix . str_pad( $this->orderNumberFirst, $this->orderNumberLength - 2, "0", STR_PAD_LEFT );
  203.            
  204.             // insert order number
  205.             $query = "INSERT INTO s_order_number SET `number` = '" . $number . "', `name` = '" . $invoice . "', `desc` = '" . $invoice . "'";
  206.             Shopware()->Db()->query( $query );
  207.         }
  208.         else
  209.         {
  210.             // add 1 to the number
  211.             $number = $row['number'] + 1;
  212.            
  213.             // update max order
  214.             $query = "UPDATE s_order_number SET number = number + 1 WHERE name = '" . $invoice . "'";
  215.             Shopware()->Db()->query( $query );
  216.         }
  217.        
  218.         // cast it
  219.         $number = (string) $number;
  220.        
  221.         // save it
  222.         $arguments->setReturn( $number );
  223.        
  224.         // finished
  225.         return;
  226.     }
  227.  
  228.  
  229.  
  230.  
  231.  
  232.     /**
  233.      * Uninstall our plugin.
  234.      *
  235.      * @return boolean
  236.      */
  237.  
  238.     public function uninstall()
  239.     {
  240.         // done
  241.         return true;
  242.     }
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.     /**
  251.      * Update our plugin if necessary.
  252.      *
  253.      * @return boolean
  254.      */
  255.  
  256.     public function update()
  257.     {
  258.         // nothing to do here
  259.         return true;
  260.     }
  261.  
  262.  
  263.  
  264.  
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement