/** * Remove carts that have not been accessed for a given number of days (depending on store config) */ public function deleteOldCarts() { $this->import('Database'); $time = time() - $GLOBALS['TL_CONFIG']['iso_cartTimeout']; $objCarts = $this->Database->execute("SELECT id FROM tl_iso_cart WHERE tstamp<{$time}"); if ($objCarts->numRows) { $arrIds = array(); $objCart = new IsotopeCart(); foreach ($objCarts->fetchEach('id') as $id) { if ($objCart->findBy('id', $id)) { $objOrder = new IsotopeOrder(); if ($objOrder->findBy('cart_id', $objCart->id)) { if ($objOrder->status == '') { $objOrder->delete(); } } $objCart->delete(); $arrIds[] = $id; } } if (!empty($arrIds)) { $this->log('Purged ' . count($arrIds) . ' old guest carts', __METHOD__, TL_CRON); } } }
/** * Process the order checkout * @param object * @return boolean */ public function checkout($objCart = null) { if ($this->checkout_complete) { return true; } $this->import('Isotope'); // This is the case when not using ModuleIsotopeCheckout if (!is_object($objCart)) { $objCart = new IsotopeCart(); if (!$objCart->findBy('id', $this->cart_id)) { $this->log('Cound not find Cart ID ' . $this->cart_id . ' for Order ID ' . $this->id, __METHOD__, TL_ERROR); return false; } // Set the current system to the language when the user placed the order. // This will result in correct e-mails and payment description. $GLOBALS['TL_LANGUAGE'] = $this->language; $this->loadLanguageFile('default'); // Initialize system $this->Isotope->overrideConfig($this->config_id); $this->Isotope->Cart = $objCart; } // HOOK: process checkout if (isset($GLOBALS['ISO_HOOKS']['preCheckout']) && is_array($GLOBALS['ISO_HOOKS']['preCheckout'])) { foreach ($GLOBALS['ISO_HOOKS']['preCheckout'] as $callback) { $this->import($callback[0]); if ($this->{$callback}[0]->{$callback}[1]($this, $objCart) === false) { $this->log('Callback "' . $callback[0] . ':' . $callback[1] . '" cancelled checkout for Order ID ' . $this->id, __METHOD__, TL_ERROR); return false; } } } $arrItemIds = $this->transferFromCollection($objCart); $objCart->delete(); $this->checkout_complete = true; $this->status = $this->new_order_status; $arrData = $this->email_data; $arrData['order_id'] = $this->generateOrderId(); foreach ($this->billing_address as $k => $v) { $arrData['billing_' . $k] = $this->Isotope->formatValue('tl_iso_addresses', $k, $v); } foreach ($this->shipping_address as $k => $v) { $arrData['shipping_' . $k] = $this->Isotope->formatValue('tl_iso_addresses', $k, $v); } if ($this->pid > 0) { $objUser = $this->Database->execute("SELECT * FROM tl_member WHERE id=" . (int) $this->pid); foreach ($objUser->row() as $k => $v) { $arrData['member_' . $k] = $this->Isotope->formatValue('tl_member', $k, $v); } } $this->log('New order ID ' . $this->id . ' has been placed', 'IsotopeOrder checkout()', TL_ACCESS); if ($this->iso_mail_admin && $this->iso_sales_email != '') { $this->Isotope->sendMail($this->iso_mail_admin, $this->iso_sales_email, $this->language, $arrData, $this->iso_customer_email, $this); } if ($this->iso_mail_customer && $this->iso_customer_email != '') { $this->Isotope->sendMail($this->iso_mail_customer, $this->iso_customer_email, $this->language, $arrData, '', $this); } else { $this->log('Unable to send customer confirmation for order ID ' . $this->id, 'IsotopeOrder checkout()', TL_ERROR); } // Store address in address book if ($this->iso_addToAddressbook && $this->pid > 0) { $time = time(); foreach (array('billing', 'shipping') as $address) { $arrAddress = deserialize($this->arrData[$address . '_address'], true); if ($arrAddress['id'] == 0) { $arrAddress = array_intersect_key($arrAddress, array_flip($this->Isotope->Config->{$address . '_fields_raw'})); $arrAddress['pid'] = $this->pid; $arrAddress['tstamp'] = $time; $arrAddress['store_id'] = $this->Isotope->Config->store_id; $this->Database->prepare("INSERT INTO tl_iso_addresses %s")->set($arrAddress)->execute(); } } } // HOOK: process checkout if (isset($GLOBALS['ISO_HOOKS']['postCheckout']) && is_array($GLOBALS['ISO_HOOKS']['postCheckout'])) { foreach ($GLOBALS['ISO_HOOKS']['postCheckout'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this, $arrItemIds, $arrData); } } $this->save(); return true; }
/** * Load the current cart * @param integer * @param integer */ public function initializeCart($intConfig, $intStore) { $time = time(); $this->strHash = $this->Input->cookie($this->strCookie); // Check to see if the user is logged in. if (FE_USER_LOGGED_IN !== true) { if (!strlen($this->strHash)) { $this->strHash = sha1(session_id() . (!$GLOBALS['TL_CONFIG']['disableIpCheck'] ? $this->Environment->ip : '') . $intConfig . $this->strCookie); $this->setCookie($this->strCookie, $this->strHash, $time + $GLOBALS['TL_CONFIG']['iso_cartTimeout'], $GLOBALS['TL_CONFIG']['websitePath']); } $objCart = $this->Database->execute("SELECT * FROM tl_iso_cart WHERE session='{$this->strHash}' AND store_id=" . (int) $intStore); } else { $objCart = $this->Database->execute("SELECT * FROM tl_iso_cart WHERE pid=" . (int) $this->User->id . " AND store_id=" . (int) $intStore); } // Create new cart if ($objCart->numRows) { $this->setFromRow($objCart, $this->strTable, 'id'); $this->tstamp = $time; } else { $this->setData(array('pid' => $this->User->id ? $this->User->id : 0, 'session' => $this->User->id ? '' : $this->strHash, 'tstamp' => time(), 'store_id' => $intStore)); } // Temporary cart available, move to this cart. Must be after creating a new cart! if (FE_USER_LOGGED_IN === true && $this->strHash != '') { $objCart = new IsotopeCart(); if ($objCart->findBy('session', $this->strHash)) { $arrIds = $this->transferFromCollection($objCart, false); if (!empty($arrIds)) { $_SESSION['ISO_CONFIRM'][] = $GLOBALS['TL_LANG']['MSC']['cartMerged']; } $objCart->delete(); } // Delete cookie $this->setCookie($this->strCookie, '', $time - 3600, $GLOBALS['TL_CONFIG']['websitePath']); $this->reload(); } }