Guest User

Untitled

a guest
Sep 6th, 2016
9
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * @copyright Metaways Infosystems GmbH, 2011
  5.  * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
  6.  * @copyright Aimeos (aimeos.org), 2015
  7.  * @package MShop
  8.  * @subpackage Order
  9.  */
  10.  
  11.  
  12. namespace Aimeos\MShop\Order\Manager\Base\Address;
  13.  
  14.  
  15. /**
  16.  * Default order address manager implementation.
  17.  *
  18.  * @package MShop
  19.  * @subpackage Order
  20.  */
  21. class MarchioAddressManager
  22.     extends \Aimeos\MShop\Order\Manager\Base\Address\Standard
  23. {
  24.     protected function createItemBase(array $values = array())
  25.     {
  26.         return new \Aimeos\MShop\Order\Item\Base\Address\MarchioAddressItem($values);
  27.     }
  28.  
  29.     public function saveItem(\Aimeos\MShop\Common\Item\Iface $item, $fetch = true)
  30.     {
  31.         $iface = '\\Aimeos\\MShop\\Order\\Item\\Base\\Address\\Iface';
  32.         if (!($item instanceof $iface)) {
  33.             throw new \Aimeos\MShop\Order\Exception(sprintf('Object is not of required type "%1$s"', $iface));
  34.         }
  35.  
  36.         if (!$item->isModified()) {
  37.             return;
  38.         }
  39.  
  40.         $context = $this->getContext();
  41.  
  42.         $dbm = $context->getDatabaseManager();
  43.         $dbname = $this->getResourceName();
  44.         $conn = $dbm->acquire($dbname);
  45.  
  46.         try {
  47.             $id = $item->getId();
  48.             $date = date('Y-m-d H:i:s');
  49.  
  50.             if ($id === null) {
  51.                 /** mshop/order/manager/base/address/standard/insert/mysql
  52.                  * Inserts a new order record into the database table
  53.                  *
  54.                  * @see mshop/order/manager/base/address/standard/insert/ansi
  55.                  */
  56.  
  57.                 /** mshop/order/manager/base/address/standard/insert/ansi
  58.                  * Inserts a new order record into the database table
  59.                  *
  60.                  * Items with no ID yet (i.e. the ID is NULL) will be created in
  61.                  * the database and the newly created ID retrieved afterwards
  62.                  * using the "newid" SQL statement.
  63.                  *
  64.                  * The SQL statement must be a string suitable for being used as
  65.                  * prepared statement. It must include question marks for binding
  66.                  * the values from the order item to the statement before they are
  67.                  * sent to the database server. The number of question marks must
  68.                  * be the same as the number of columns listed in the INSERT
  69.                  * statement. The order of the columns must correspond to the
  70.                  * order in the saveItems() method, so the correct values are
  71.                  * bound to the columns.
  72.                  *
  73.                  * The SQL statement should conform to the ANSI standard to be
  74.                  * compatible with most relational database systems. This also
  75.                  * includes using double quotes for table and column names.
  76.                  *
  77.                  * @param string SQL statement for inserting records
  78.                  * @since 2014.03
  79.                  * @category Developer
  80.                  * @see mshop/order/manager/base/address/standard/update/ansi
  81.                  * @see mshop/order/manager/base/address/standard/newid/ansi
  82.                  * @see mshop/order/manager/base/address/standard/delete/ansi
  83.                  * @see mshop/order/manager/base/address/standard/search/ansi
  84.                  * @see mshop/order/manager/base/address/standard/count/ansi
  85.                  */
  86.                 $path = 'mshop/order/manager/base/address/standard/insert';
  87.             } else {
  88.                 /** mshop/order/manager/base/address/standard/update/mysql
  89.                  * Updates an existing order record in the database
  90.                  *
  91.                  * @see mshop/order/manager/base/address/standard/update/ansi
  92.                  */
  93.  
  94.                 /** mshop/order/manager/base/address/standard/update/ansi
  95.                  * Updates an existing order record in the database
  96.                  *
  97.                  * Items which already have an ID (i.e. the ID is not NULL) will
  98.                  * be updated in the database.
  99.                  *
  100.                  * The SQL statement must be a string suitable for being used as
  101.                  * prepared statement. It must include question marks for binding
  102.                  * the values from the order item to the statement before they are
  103.                  * sent to the database server. The order of the columns must
  104.                  * correspond to the order in the saveItems() method, so the
  105.                  * correct values are bound to the columns.
  106.                  *
  107.                  * The SQL statement should conform to the ANSI standard to be
  108.                  * compatible with most relational database systems. This also
  109.                  * includes using double quotes for table and column names.
  110.                  *
  111.                  * @param string SQL statement for updating records
  112.                  * @since 2014.03
  113.                  * @category Developer
  114.                  * @see mshop/order/manager/base/address/standard/insert/ansi
  115.                  * @see mshop/order/manager/base/address/standard/newid/ansi
  116.                  * @see mshop/order/manager/base/address/standard/delete/ansi
  117.                  * @see mshop/order/manager/base/address/standard/search/ansi
  118.                  * @see mshop/order/manager/base/address/standard/count/ansi
  119.                  */
  120.                 $path = 'mshop/order/manager/base/address/standard/update';
  121.                 /*
  122.                  * TODO: NEXT
  123.                  * 1 - Set new config with mysql statement.
  124.                  * 2 - Update bindings
  125.                  * 3 - Check if values are updated correctly on DB.
  126.                  * 4 - Solve bug (see https://aimeos.org/help/post3349.html#p3349)
  127.                  * 5 - Finish payment sending "real" data
  128.                  * 6 - Complete payment with credit card.
  129.                  * 7 - Handle PS notifications
  130.                  * 8 - Validate if order status are updated as status changes in PS.
  131.                  * 9 - Commit. Be Happy!
  132.                  * */
  133.             }
  134.  
  135.  
  136.             $stmt = $this->getCachedStatement($conn, $path);
  137.             $stmt->bind(1, $item->getBaseId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT);
  138.             $stmt->bind(2, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT);
  139.             $stmt->bind(3, $item->getAddressId(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  140.             $stmt->bind(4, $item->getType(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  141.             $stmt->bind(5, $item->getCompany(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  142.             $stmt->bind(6, $item->getVatID(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  143.             $stmt->bind(7, $item->getSalutation(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  144.             $stmt->bind(8, $item->getTitle(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  145.             $stmt->bind(9, $item->getFirstname(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  146.             $stmt->bind(10, $item->getLastname(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  147.             $stmt->bind(11, $item->getAddress1(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  148.             $stmt->bind(12, $item->getAddress2(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  149.             $stmt->bind(13, $item->getAddress3(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  150.             $stmt->bind(14, $item->getPostal(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  151.             $stmt->bind(15, $item->getCity(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  152.             $stmt->bind(16, $item->getState(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  153.             $stmt->bind(17, $item->getCountryId(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  154.             $stmt->bind(18, $item->getLanguageId(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  155.             $stmt->bind(19, $item->getTelephone(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  156.             $stmt->bind(20, $item->getEmail(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  157.             $stmt->bind(21, $item->getTelefax(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  158.             $stmt->bind(22, $item->getWebsite(), \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  159.             $stmt->bind(23, $item->getFlag(), \Aimeos\MW\DB\Statement\Base::PARAM_INT);
  160.             $stmt->bind(24, $date, \Aimeos\MW\DB\Statement\Base::PARAM_STR);
  161.             $stmt->bind(25, $context->getEditor());
  162.  
  163.             if ($id !== null) {
  164.                 $stmt->bind(26, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT);
  165.                 $item->setId($id);
  166.             } else {
  167.                 $stmt->bind(26, $date); // ctime
  168.             }
  169.  
  170.             $stmt->execute()->finish();
  171.  
  172.             if ($id === null && $fetch === true) {
  173.                 /** mshop/order/manager/base/address/standard/newid/mysql
  174.                  * Retrieves the ID generated by the database when inserting a new record
  175.                  *
  176.                  * @see mshop/order/manager/base/address/standard/newid/ansi
  177.                  */
  178.  
  179.                 /** mshop/order/manager/base/address/standard/newid/ansi
  180.                  * Retrieves the ID generated by the database when inserting a new record
  181.                  *
  182.                  * As soon as a new record is inserted into the database table,
  183.                  * the database server generates a new and unique identifier for
  184.                  * that record. This ID can be used for retrieving, updating and
  185.                  * deleting that specific record from the table again.
  186.                  *
  187.                  * For MySQL:
  188.                  *  SELECT LAST_INSERT_ID()
  189.                  * For PostgreSQL:
  190.                  *  SELECT currval('seq_mord_id')
  191.                  * For SQL Server:
  192.                  *  SELECT SCOPE_IDENTITY()
  193.                  * For Oracle:
  194.                  *  SELECT "seq_mord_id".CURRVAL FROM DUAL
  195.                  *
  196.                  * There's no way to retrive the new ID by a SQL statements that
  197.                  * fits for most database servers as they implement their own
  198.                  * specific way.
  199.                  *
  200.                  * @param string SQL statement for retrieving the last inserted record ID
  201.                  * @since 2014.03
  202.                  * @category Developer
  203.                  * @see mshop/order/manager/base/address/standard/insert/ansi
  204.                  * @see mshop/order/manager/base/address/standard/update/ansi
  205.                  * @see mshop/order/manager/base/address/standard/delete/ansi
  206.                  * @see mshop/order/manager/base/address/standard/search/ansi
  207.                  * @see mshop/order/manager/base/address/standard/count/ansi
  208.                  */
  209.                 $path = 'mshop/order/manager/base/address/standard/newid';
  210.                 $item->setId($this->newId($conn, $path));
  211.             }
  212.  
  213.             $dbm->release($conn, $dbname);
  214.         } catch (\Exception $e) {
  215.             $dbm->release($conn, $dbname);
  216.             throw $e;
  217.         }
  218.     }
  219. }
RAW Paste Data