protected function processForm()
 {
     // get a product collection (aka cart)
     global $objPage;
     $objCart = new Cart();
     // Can't call the individual rows here, it would trigger markModified and a save()
     $objCart->setRow(array_merge($objCart->row(), array('tstamp' => time(), 'member' => 0, 'uniqid' => null, 'config_id' => $this->iso_config_id, 'store_id' => (int) \PageModel::findByPk($objPage->rootId)->iso_store_id)));
     $objSubmission = $this->getSubmission(false);
     // add products to cart
     foreach ($this->arrProducts as $arrProduct) {
         $strProduct = 'product_' . $arrProduct['product']->id;
         $strQuantity = 'quantity_' . $arrProduct['product']->id;
         if (($this->getProductCount() > 1 || $this->getTypeCount() > 1) && !$objSubmission->{$strProduct}) {
             continue;
         }
         if (!$objCart->addProduct($arrProduct['product'], $arrProduct['useQuantity'] ? $objSubmission->{$strQuantity} : 1)) {
             $this->transformIsotopeErrorMessages();
             return;
         }
     }
     $objCart->save();
     $objOrder = $objCart->getDraftOrder();
     // temporarily override the cart for generating the reviews...
     $objCartTmp = Isotope::getCart();
     Isotope::setCart($objCart);
     // create steps
     $arrSteps = array();
     $arrCheckoutInfo = array();
     // billing address
     $objBillingAddress = new Address();
     foreach ($this->arrBillingAddressFields as $strName) {
         $objBillingAddress->{$strName} = $objSubmission->{$strName};
     }
     $objBillingAddress->save();
     $objOrder->setBillingAddress($objBillingAddress);
     $objBillingAddressStep = new BillingAddress($this->objCheckoutModule);
     $arrSteps[] = $objBillingAddressStep;
     $arrCheckoutInfo['billing_address'] = $objBillingAddressStep->review()['billing_address'];
     // shipping address
     $objShippingAddress = new Address();
     // standard isotope handling for distinguishing between the address types:
     // -> if only a billing address is available, it's also the shipping address
     foreach ($objSubmission->shippingaddress ? $this->arrShippingAddressFields : $this->arrBillingAddressFields as $strName) {
         $objShippingAddress->{str_replace('shippingaddress_', '', $strName)} = $objSubmission->{$objSubmission->shippingaddress ? $strName : str_replace('shippingaddress_', 'billingaddress_', $strName)};
     }
     $objShippingAddress->save();
     //        $objOrder->setShippingAddress($objShippingAddress);
     //        $objShippingAddressStep              = new ShippingAddress($this->objCheckoutModule);
     //        $arrSteps[]                          = $objShippingAddressStep;
     //        $arrCheckoutInfo['shipping_address'] = $objShippingAddressStep->review()['shipping_address'];
     // add shipping method
     $objIsotopeShipping = Flat::findByPk($this->iso_shipping_modules);
     $objOrder->setShippingMethod($objIsotopeShipping);
     $objShippingMethodStep = new ShippingMethod($this->objCheckoutModule);
     $arrSteps[] = $objShippingMethodStep;
     $arrCheckoutInfo['shipping_method'] = $objShippingMethodStep->review()['shipping_method'];
     // add all the checkout info to the order
     $objOrder->checkout_info = $arrCheckoutInfo;
     $objOrder->notes = $objSubmission->notes;
     //... restore the former cart again
     Isotope::setCart($objCartTmp);
     $objOrder->nc_notification = $this->nc_notification;
     $objOrder->email_data = $this->getNotificationTokensFromSteps($arrSteps, $objOrder);
     // !HOOK: pre-process checkout
     if (isset($GLOBALS['ISO_HOOKS']['preCheckout']) && is_array($GLOBALS['ISO_HOOKS']['preCheckout'])) {
         foreach ($GLOBALS['ISO_HOOKS']['preCheckout'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             if ($objCallback->{$callback}[1]($objOrder, $this->objCheckoutModule) === false) {
                 \System::log('Callback ' . $callback[0] . '::' . $callback[1] . '() cancelled checkout for Order ID ' . $this->id, __METHOD__, TL_ERROR);
                 $this->objCheckoutModule->redirectToStep('failed');
             }
         }
     }
     $objOrder->lock();
     $objOrder->checkout();
     $objOrder->complete();
     if (is_array($this->dca['config']['onsubmit_callback'])) {
         foreach ($this->dca['config']['onsubmit_callback'] as $key => $callback) {
             if ($callback[0] == 'Isotope\\Backend\\ProductCollection\\Callback' && $callback[1] == 'executeSaveHook') {
                 unset($this->dca['config']['onsubmit_callback'][$key]);
                 break;
             }
         }
     }
     $this->transformIsotopeErrorMessages();
     parent::processForm();
 }
Exemplo n.º 2
0
 /**
  * Make sure the addresses belong to this collection only, so they will never be modified
  */
 protected function createPrivateAddresses()
 {
     $this->ensureNotLocked();
     if (!$this->id) {
         throw new \UnderflowException('Product collection must be saved before creating unique addresses.');
     }
     $objBillingAddress = $this->getBillingAddress();
     $objShippingAddress = $this->getShippingAddress();
     // Store address in address book
     if ($this->iso_addToAddressbook && $this->member > 0) {
         if (null !== $objBillingAddress && $objBillingAddress->ptable != \MemberModel::getTable()) {
             $objAddress = clone $objBillingAddress;
             $objAddress->pid = $this->member;
             $objAddress->tstamp = time();
             $objAddress->ptable = \MemberModel::getTable();
             $objAddress->store_id = $this->store_id;
             $objAddress->save();
             $this->updateDefaultAddress($objAddress);
         }
         if (null !== $objBillingAddress && null !== $objShippingAddress && $objBillingAddress->id != $objShippingAddress->id && $objShippingAddress->ptable != \MemberModel::getTable()) {
             $objAddress = clone $objShippingAddress;
             $objAddress->pid = $this->member;
             $objAddress->tstamp = time();
             $objAddress->ptable = \MemberModel::getTable();
             $objAddress->store_id = $this->store_id;
             $objAddress->save();
             $this->updateDefaultAddress($objAddress);
         }
     }
     /** @type Config $config */
     $config = $this->getRelated('config_id');
     $billingFields = null === $config ? array() : $config->getBillingFields();
     $shippingFields = null === $config ? array() : $config->getShippingFields();
     if (null !== $objBillingAddress && ($objBillingAddress->ptable != static::$strTable || $objBillingAddress->pid != $this->id)) {
         $arrData = array_intersect_key($objBillingAddress->row(), array_flip($billingFields));
         $objNew = new Address();
         $objNew->setRow($arrData);
         $objNew->pid = $this->id;
         $objNew->tstamp = time();
         $objNew->ptable = static::$strTable;
         $objNew->store_id = $this->store_id;
         $objNew->save();
         $this->setBillingAddress($objNew);
         if (null !== $objShippingAddress && $objBillingAddress->id == $objShippingAddress->id) {
             $this->setShippingAddress($objNew);
             // Stop here, we do not need to check shipping address
             return;
         }
     }
     if (null !== $objShippingAddress && ($objShippingAddress->ptable != static::$strTable || $objShippingAddress->pid != $this->id)) {
         $arrData = array_intersect_key($objShippingAddress->row(), array_flip($shippingFields));
         $objNew = new Address();
         $objNew->setRow($arrData);
         $objNew->pid = $this->id;
         $objNew->tstamp = time();
         $objNew->ptable = static::$strTable;
         $objNew->store_id = $this->store_id;
         $objNew->save();
         $this->setShippingAddress($objNew);
     }
 }