| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Pagantis\Pagantis\Controller\Payment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Magento\Framework\App\Action\Action; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Magento\Framework\App\Action\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Magento\Quote\Model\QuoteRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Magento\Sales\Model\ResourceModel\Order\Collection as OrderCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Magento\Checkout\Model\Session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Pagantis\OrdersApiClient\Model\Order; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Pagantis\Pagantis\Helper\Config; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Pagantis\Pagantis\Helper\ExtraConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Magento\Framework\App\ResourceConnection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Magento\Framework\App\ProductMetadataInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Magento\Framework\Module\ModuleList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Magento\Store\Api\Data\StoreInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Pagantis\OrdersApiClient\Model\Order\User\Address; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Magento\Framework\DB\Ddl\Table; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Pagantis\OrdersApiClient\Model\Order\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Pagantis\OrdersApiClient\Model\Order\User\OrderHistory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Pagantis\OrdersApiClient\Model\Order\ShoppingCart; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Pagantis\OrdersApiClient\Model\Order\Metadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Pagantis\OrdersApiClient\Model\Order\Configuration\Urls; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Pagantis\OrdersApiClient\Model\Order\Configuration\Channel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Pagantis\OrdersApiClient\Model\Order\Configuration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Pagantis\OrdersApiClient\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * Class Index | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @package Pagantis\Pagantis\Controller\Payment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | class Index extends Action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** Orders tablename */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     const ORDERS_TABLE = 'cart_process'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** Concurrency tablename */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     const LOGS_TABLE = 'Pagantis_logs'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** @var Context $context */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     protected $context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** @var QuoteRepository  $quoteRepository */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     protected $quoteRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** @var OrderCollection $orderCollection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     protected $orderCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** @var Session $session */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     protected $session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** @var mixed $config */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     protected $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** @var ResourceConnection $dbObject */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     protected $dbObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** @var ProductMetadataInterface $productMetadataInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     protected $productMetadataInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** @var ModuleList $moduleList */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     protected $moduleList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** @var ExtraConfig $extraConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     protected $extraConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** @var StoreInterface $store */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     protected $store; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Index constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param Context                  $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param QuoteRepository          $quoteRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @param OrderCollection          $orderCollection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @param Session                  $session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @param Config                   $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @param ResourceConnection       $dbObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @param ProductMetadataInterface $productMetadataInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param ModuleList               $moduleList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @param ExtraConfig              $extraConfig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @param StoreInterface           $storeInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         Context $context, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         QuoteRepository $quoteRepository, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         OrderCollection $orderCollection, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         Session $session, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         Config $config, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         ResourceConnection $dbObject, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         ProductMetadataInterface $productMetadataInterface, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         ModuleList $moduleList, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         ExtraConfig $extraConfig, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         StoreInterface $storeInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         parent::__construct($context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $this->session = $session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $this->context = $context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $this->config = $config->getConfig(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $this->quoteRepository = $quoteRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $this->orderCollection = $orderCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $this->dbObject = $dbObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $this->moduleList = $moduleList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $this->productMetadataInterface = $productMetadataInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $this->extraConfig = $extraConfig->getExtraConfig(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $this->store = $storeInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * Main function | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * @throws \Zend_Db_Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     public function execute() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             $cancelUrl = $this->_url->getUrl('checkout', ['_fragment' => 'payment']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             $quote = $this->session->getQuote(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             /** @var Order $order */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             $lastOrder = $this->session->getLastRealOrder(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             $params = $this->getRequest()->getParams(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             $customer = $quote->getCustomer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             $shippingAddress = $quote->getShippingAddress(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             if (isset($params['email']) && $params['email']!='') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 $this->session->setEmail($params['email']); //Get guest email after refresh page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 $customer->setEmail($params['email']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                 $quote->setCheckoutMethod('guest'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                 $quote->getBillingAddress()->setEmail($params['email']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             } elseif ($customer->getEmail()=='') { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                 $customer->setEmail($this->session->getEmail()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 $quote->setCheckoutMethod('guest'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                 $quote->getBillingAddress()->setEmail($this->session->getEmail()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |             /** @var Quote $currentQuote */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             $currentQuote = $this->quoteRepository->get($quote->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             $currentQuote->setCustomerEmail($customer->getEmail()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             $this->quoteRepository->save($currentQuote); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             $userAddress =  new Address(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             $userAddress | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                 ->setZipCode($shippingAddress->getPostcode()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                 ->setFullName($shippingAddress->getFirstname()." ".$shippingAddress->getLastname()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                 ->setCountryCode('ES') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                 ->setCity($shippingAddress->getCity()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                 ->setAddress($shippingAddress->getStreetFull()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             $tax_id = $this->getTaxId($quote->getBillingAddress()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             $orderShippingAddress = new Address(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             $orderShippingAddress | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |                 ->setZipCode($shippingAddress->getPostcode()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |                 ->setFullName($shippingAddress->getFirstname()." ".$shippingAddress->getLastname()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |                 ->setCountryCode('ES') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |                 ->setCity($shippingAddress->getCity()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |                 ->setAddress($shippingAddress->getStreetFull()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |                 ->setFixPhone($shippingAddress->getTelephone()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |                 ->setMobilePhone($shippingAddress->getTelephone()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                 ->setTaxId($tax_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             $orderBillingAddress =  new Address(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             $billingAddress = $quote->getBillingAddress(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             $orderBillingAddress | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |                 ->setZipCode($billingAddress->getPostcode()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |                 ->setFullName($billingAddress->getFirstname()." ".$shippingAddress->getLastname()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |                 ->setCountryCode('ES') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |                 ->setCity($billingAddress->getCity()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                 ->setAddress($billingAddress->getStreetFull()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |                 ->setFixPhone($billingAddress->getTelephone()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |                 ->setMobilePhone($billingAddress->getTelephone()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |                 ->setTaxId($tax_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             $orderUser = new User(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |             $billingAddress->setEmail($customer->getEmail()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |             $orderUser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                 ->setAddress($userAddress) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                 ->setFullName($shippingAddress->getFirstname()." ".$shippingAddress->getLastname()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |                 ->setBillingAddress($orderBillingAddress) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |                 ->setEmail($customer->getEmail()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |                 ->setFixPhone($shippingAddress->getTelephone()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |                 ->setMobilePhone($shippingAddress->getTelephone()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |                 ->setShippingAddress($orderShippingAddress) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                 ->setTaxId($tax_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             if ($customer->getDob()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |                 $orderUser->setDateOfBirth($customer->getDob()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |             if ($customer->getTaxvat()!='') { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |                 $orderUser->setDni($customer->getTaxvat()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |                 $orderBillingAddress->setDni($customer->getTaxvat()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |                 $orderShippingAddress->setDni($customer->getTaxvat()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |                 $orderUser->setNationalId($customer->getTaxvat()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |                 $orderBillingAddress->setNationalId($customer->getTaxvat()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |                 $orderShippingAddress->setNationalId($customer->getTaxvat()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             $previousOrders = $this->getOrders($customer->getId()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             foreach ($previousOrders as $orderElement) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 $orderHistory = new OrderHistory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |                 $orderHistory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |                     ->setAmount(intval(100 * $orderElement['grand_total'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |                     ->setDate(new \DateTime($orderElement['created_at'])) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |                 ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |                 $orderUser->addOrderHistory($orderHistory); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |             $metadataOrder = new Metadata(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |             $metadata = $this->getMetadata(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             foreach ($metadata as $key => $metadatum) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |                 $metadataOrder->addMetadata($key, $metadatum); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |             $details = new Details(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             $shippingCost = $quote->collectTotals()->getTotals()['shipping']->getData('value'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |             $details->setShippingCost(intval(strval(100 * $shippingCost))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |             $items = $quote->getAllVisibleItems(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |             $promotedAmount = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |             foreach ($items as $key => $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |                 $product = new Product(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |                 $product | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |                     ->setAmount(intval(100 * $item->getPrice())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |                     ->setQuantity($item->getQty()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |                     ->setDescription($item->getName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |                 $details->addProduct($product); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |                 $promotedProduct = $this->isPromoted($item); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |                 if ($promotedProduct == 'true') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |                     $promotedAmount+=$product->getAmount()*$item->getQty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |                     $promotedMessage = 'Promoted Item: ' . $item->getName() . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |                                        ' Price: ' . $item->getPrice() . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |                                        ' Qty: ' . $item->getQty() . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |                                        ' Item ID: ' . $item->getItemId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |                     $metadataOrder->addMetadata('promotedProduct', $promotedMessage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |             $orderShoppingCart = new ShoppingCart(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |             $orderShoppingCart | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |                 ->setDetails($details) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |                 ->setOrderReference($quote->getId()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |                 ->setPromotedAmount(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |                 ->setTotalAmount(intval(strval(100 * $quote->getGrandTotal()))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |             $orderConfigurationUrls = new Urls(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |             $quoteId = $quote->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |             $okUrl = $this->_url->getUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |                 'pagantis/notify/index', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |                 ['_query' => ['quoteId'=>$quoteId]] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |             if (version_compare($metadata['magento'], '2.3.0') >= 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |                 $okUrl = $this->_url->getUrl('pagantis/notify/indexV2', ['_query' => ['quoteId'=>$quoteId]]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |             $orderConfigurationUrls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |                 ->setCancel($cancelUrl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |                 ->setKo($okUrl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |                 ->setAuthorizedNotificationCallback($okUrl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |                 ->setRejectedNotificationCallback($okUrl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |                 ->setOk($okUrl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |             $orderChannel = new Channel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |             $orderChannel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |                 ->setAssistedSale(false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |                 ->setType(Channel::ONLINE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |             $haystack  = $this->store->getLocale(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |             $language = strstr($haystack, '_', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |             $orderConfiguration = new Configuration(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |             $orderConfiguration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |                 ->setChannel($orderChannel) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |                 ->setUrls($orderConfigurationUrls) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |                 ->setPurchaseCountry($language) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |             $order = new Order(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |             $order | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |                 ->setConfiguration($orderConfiguration) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |                 ->setMetadata($metadataOrder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |                 ->setShoppingCart($orderShoppingCart) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |                 ->setUser($orderUser) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |             ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |             if ($this->config['pagantis_public_key']=='' || $this->config['pagantis_private_key']=='') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |                 throw new \Exception('Public and Secret Key not found'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |             $orderClient = new Client( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |                 $this->config['pagantis_public_key'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |                 $this->config['pagantis_private_key'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |             $order = $orderClient->createOrder($order); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |             if ($order instanceof Order) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |                 $url = $order->getActionUrls()->getForm(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |                 $result = $this->insertRow($quote->getId(), $order->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |                 if (!$result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |                     throw new \Exception('Unable to save pagantis-order-id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |                 throw new \Exception('Order not created'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |         } catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |             $this->insertLog($exception); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |             echo $cancelUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |             exit; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |         $displayMode = $this->extraConfig['PAGANTIS_FORM_DISPLAY_TYPE']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |         if ($displayMode==='0') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |             echo $url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |             exit; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |             $iframeUrl = $this->_url->getUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |                 "pagantis/Payment/iframe", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |                 ['_query' => ["orderId"=>$order->getId()]] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |             echo $iframeUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |             exit; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |      * Get the orders of a customer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |      * @param $customerId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |     private function getOrders($customerId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |         $orderCollection = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |         if ($customerId!='') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |             $this->orderCollection->addAttributeToFilter('customer_id', $customerId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |                             ->addAttributeToFilter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |                                 'status', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |                                 ['in' => ['processing','pending','complete']] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |                             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |                             ->load(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |             $orderCollection = $this->orderCollection->getData(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |         return $orderCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |      * @return void|\Zend_Db_Statement_Interface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |      * @throws \Zend_Db_Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |     private function checkDbTable() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |         $dbConnection = $this->dbObject->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |         $tableName = $this->dbObject->getTableName(self::ORDERS_TABLE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |         if (!$dbConnection->isTableExists($tableName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |             $table = $dbConnection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |                 ->newTable($tableName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |                 ->addColumn('id', Table::TYPE_SMALLINT, null, array('primary'=>true, 'nullable' => false)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |                 ->addColumn('order_id', Table::TYPE_TEXT, 50) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |                 ->addColumn('mg_order_id', Table::TYPE_TEXT, 50); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |             return $dbConnection->createTable($table); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |         return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |      * Create relationship between quote_id & Pagantis_order_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |      * @param $quoteId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |      * @param $pagantisOrderId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |      * @throws \Zend_Db_Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |     private function insertRow($quoteId, $pagantisOrderId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |         $this->checkDbTable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |         $dbConnection = $this->dbObject->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |         $tableName = $this->dbObject->getTableName(self::ORDERS_TABLE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |         return $dbConnection->insertOnDuplicate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |             $tableName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |             array('id'=>$quoteId,'order_id'=>$pagantisOrderId), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |             array('order_id') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |     private function getMetadata() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |         $curlInfo = curl_version(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |         $curlVersion = $curlInfo['version']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |         $magentoVersion = $this->productMetadataInterface->getVersion(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |         $moduleInfo = $this->moduleList->getOne('Pagantis_Pagantis'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |         return array(  'magento' => $magentoVersion, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |                        'pagantis' => $moduleInfo['setup_version'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |                        'php' => phpversion(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |                        'curl' => $curlVersion); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |      * Check if log table exists, otherwise create it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |      * @return void|\Zend_Db_Statement_Interface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |      * @throws \Zend_Db_Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |     private function checkDbLogTable() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |         /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |         $dbConnection = $this->dbObject->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |         $tableName = $this->dbObject->getTableName(self::LOGS_TABLE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |         if (!$dbConnection->isTableExists($tableName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |             $table = $dbConnection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |                 ->newTable($tableName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |                 ->addColumn('id', Table::TYPE_SMALLINT, null, array('nullable'=>false, 'auto_increment'=>true, 'primary'=>true)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |                 ->addColumn('log', Table::TYPE_TEXT, null, array('nullable'=>false)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |                 ->addColumn('createdAt', Table::TYPE_TIMESTAMP, null, array('nullable'=>false, 'default'=>Table::TIMESTAMP_INIT)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |             return $dbConnection->createTable($table); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |         return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |      * @param $exceptionMessage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |      * @throws \Zend_Db_Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |     private function insertLog($exceptionMessage) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |         if ($exceptionMessage instanceof \Exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |             $this->checkDbLogTable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |             $logObject          = new \stdClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |             $logObject->message = $exceptionMessage->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |             $logObject->code    = $exceptionMessage->getCode(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |             $logObject->line    = $exceptionMessage->getLine(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |             $logObject->file    = $exceptionMessage->getFile(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |             $logObject->trace   = $exceptionMessage->getTraceAsString(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |             /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |             $dbConnection = $this->dbObject->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |             $tableName    = $this->dbObject->getTableName(self::LOGS_TABLE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |             $dbConnection->insert($tableName, array('log' => json_encode($logObject))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |      * @param $billingAdd | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |      * @return null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |     private function getTaxId($billingAdd) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |         if (isset($billingAdd['vat_id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |             return $billingAdd['vat_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |         } elseif (isset($billingAdd['cod_fisc'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |             return $billingAdd['cod_fisc']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |      * @param $item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 475 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 476 |  |  |     private function isPromoted($item) | 
            
                                                                        
                            
            
                                    
            
            
                | 477 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 478 |  |  |         $magentoProductId = $item->getProductId(); | 
            
                                                                        
                            
            
                                    
            
            
                | 479 |  |  |         $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | 
            
                                                                        
                            
            
                                    
            
            
                | 480 |  |  |         $product = $objectManager->create('Magento\Catalog\Model\Product')->load($magentoProductId); | 
            
                                                                        
                            
            
                                    
            
            
                | 481 |  |  |         return ($product->getData('pagantis_promoted') === '1') ? 'true' : 'false'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 483 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 484 |  |  |  | 
            
                        
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: