Example #1
0
 /**
  * Returns true if the product is available
  * ALMOST THE SAME AS THE PARENT, EXCEPT WE DON'T CHECK FOR PRICE
  *
  * @param IsotopeProductCollection|\Isotope\Model\ProductCollection $objCollection
  *
  * @return bool
  */
 public function isAvailableForCollection(IsotopeProductCollection $objCollection)
 {
     if ($objCollection->isLocked()) {
         return true;
     }
     if (BE_USER_LOGGED_IN !== true && !$this->isPublished()) {
         return false;
     }
     // Show to guests only
     if ($this->arrData['guests'] && $objCollection->member > 0 && BE_USER_LOGGED_IN !== true && !$this->arrData['protected']) {
         return false;
     }
     // Protected product
     if (BE_USER_LOGGED_IN !== true && $this->arrData['protected']) {
         if ($objCollection->member == 0) {
             return false;
         }
         $groups = deserialize($this->arrData['groups']);
         $memberGroups = deserialize($objCollection->getRelated('member')->groups);
         if (!is_array($groups) || empty($groups) || !is_array($memberGroups) || empty($memberGroups) || !count(array_intersect($groups, $memberGroups))) {
             return false;
         }
     }
     // Check that the product is in any page of the current site
     if (count(\Isotope\Frontend::getPagesInCurrentRoot($this->getCategories(), $objCollection->getRelated('member'))) == 0) {
         return false;
     }
     // Check if "advanced price" is available
     //if (null === $this->getPrice($objCollection) && (in_array('price', $this->getAttributes()) || $this->hasVariantPrices())) {
     //    return false;
     //}
     return true;
 }
 /**
  * Generate a single item and return it's HTML string
  * TEMPORARY UNTIL WE UPDATE THE AJAX STUFF
  * @return string
  */
 public function generateAjax()
 {
     $objItem = Isotope_Frontend::getProduct(\Input::get('item'));
     if ($objItem !== null) {
         return $objItem->generateAjax($this);
     }
     return '';
 }
Example #3
0
 /**
  * Include messages if enabled
  * @return string
  */
 public function generate()
 {
     $strBuffer = parent::generate();
     // Prepend any messages to the module output
     if ($this->iso_includeMessages) {
         $strBuffer = \Isotope\Frontend::getIsotopeMessages() . $strBuffer;
     }
     return $strBuffer;
 }
Example #4
0
 /**
  * Must be defined cause parent is protected.
  *
  * @access public
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     // Contao Hooks are not save to be run on the postsale script (e.g. parseFrontendTemplate)
     unset($GLOBALS['TL_HOOKS']);
     // Need to load our own Hooks (e.g. loadDataContainer)
     include TL_ROOT . '/system/modules/isotope/config/hooks.php';
     // Default parameters
     $this->setModule(strlen(\Input::post('mod')) ? \Input::post('mod') : \Input::get('mod'));
     $this->setModuleId(strlen(\Input::post('id')) ? \Input::post('id') : \Input::get('id'));
     // HOOK: allow to add custom hooks for postsale script
     if (isset($GLOBALS['ISO_HOOKS']['initializePostsale']) && is_array($GLOBALS['ISO_HOOKS']['initializePostsale'])) {
         foreach ($GLOBALS['ISO_HOOKS']['initializePostsale'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($this);
         }
     }
 }
Example #5
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->Template->messages = \Isotope\Frontend::getIsotopeMessages();
 }
Example #6
0
 /**
  * Add the collection to a template
  * @param   object
  * @param   array
  */
 public function addToTemplate(\Isotope\Template $objTemplate, array $arrConfig = array())
 {
     $arrGalleries = array();
     $arrItems = $this->addItemsToTemplate($objTemplate, $arrConfig['sorting']);
     $objTemplate->collection = $this;
     $objTemplate->config = $this->getRelated('config_id') || Isotope::getConfig();
     $objTemplate->surcharges = \Isotope\Frontend::formatSurcharges($this->getSurcharges());
     $objTemplate->subtotal = Isotope::formatPriceWithCurrency($this->getSubtotal());
     $objTemplate->total = Isotope::formatPriceWithCurrency($this->getTotal());
     $objTemplate->generateAttribute = function ($strAttribute, ProductCollectionItem $objItem) {
         if (!$objItem->hasProduct()) {
             return '';
         }
         $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strAttribute];
         if (!$objAttribute instanceof IsotopeAttribute) {
             throw new \InvalidArgumentException($strAttribute . ' is not a valid attribute');
         }
         return $objAttribute->generate($objItem->getProduct());
     };
     $objTemplate->getGallery = function ($strAttribute, ProductCollectionItem $objItem) use($arrConfig, &$arrGalleries) {
         if (!$objItem->hasProduct()) {
             return new \Isotope\Model\Gallery\Standard();
         }
         $strCacheKey = 'product' . $objItem->product_id . '_' . $strAttribute;
         $arrConfig['jumpTo'] = $objItem->getRelated('jumpTo');
         if (!isset($arrGalleries[$strCacheKey])) {
             $arrGalleries[$strCacheKey] = Gallery::createForProductAttribute($objItem->getProduct(), $strAttribute, $arrConfig);
         }
         return $arrGalleries[$strCacheKey];
     };
     // !HOOK: allow overriding of the template
     if (isset($GLOBALS['ISO_HOOKS']['addCollectionToTemplate']) && is_array($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objTemplate, $arrItems, $this);
         }
     }
 }
Example #7
0
 /**
  * Return true or false depending on if shipping method is available
  * @return bool
  * @todo must check availability for a specific product collection (and not hardcoded to the current cart)
  */
 public function isAvailable()
 {
     if (!$this->enabled && BE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->guests && FE_USER_LOGGED_IN === true || $this->protected && FE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->protected) {
         $arrGroups = deserialize($this->groups);
         if (!is_array($arrGroups) || empty($arrGroups) || !count(array_intersect($arrGroups, \FrontendUser::getInstance()->groups))) {
             return false;
         }
     }
     if ($this->minimum_total > 0 && $this->minimum_total > Isotope::getCart()->getSubtotal() || $this->maximum_total > 0 && $this->maximum_total < Isotope::getCart()->getSubtotal()) {
         return false;
     }
     $objScale = Isotope::getCart()->addToScale();
     if (($minWeight = Weight::createFromTimePeriod($this->minimum_weight)) !== null && $objScale->isLessThan($minWeight)) {
         return false;
     }
     if (($maxWeight = Weight::createFromTimePeriod($this->maximum_weight)) !== null && $objScale->isMoreThan($maxWeight)) {
         return false;
     }
     $objAddress = Isotope::getCart()->getShippingAddress();
     $arrCountries = deserialize($this->countries);
     if (is_array($arrCountries) && !empty($arrCountries) && !in_array($objAddress->country, $arrCountries)) {
         return false;
     }
     $arrSubdivisions = deserialize($this->subdivisions);
     if (is_array($arrSubdivisions) && !empty($arrSubdivisions) && !in_array($objAddress->subdivision, $arrSubdivisions)) {
         return false;
     }
     // Check if address has a valid postal code
     if ($this->postalCodes != '') {
         $arrCodes = \Isotope\Frontend::parsePostalCodes($this->postalCodes);
         if (!in_array($objAddress->postal, $arrCodes)) {
             return false;
         }
     }
     $arrTypes = deserialize($this->product_types);
     if (is_array($arrTypes) && !empty($arrTypes)) {
         $arrItems = Isotope::getCart()->getItems();
         foreach ($arrItems as $objItem) {
             if (!$objItem->hasProduct() || !in_array($objItem->getProduct()->type, $arrTypes)) {
                 return false;
             }
         }
     }
     return true;
 }
Example #8
0
 /**
  * Trigger order status update when changing the status in the backend
  *
  * @param   string
  * @param   DataContainer
  *
  * @return  string
  * @link    http://www.contao.org/callbacks.html#save_callback
  */
 public function updateOrderStatus($varValue, $dc)
 {
     if ($dc->activeRecord && $dc->activeRecord->order_status != $varValue) {
         /** @var Order $objOrder */
         if (($objOrder = Order::findByPk($dc->id)) !== null) {
             if (TL_MODE == 'BE') {
                 if ($objOrder->pageId == 0) {
                     unset($GLOBALS['objPage']);
                 }
                 Frontend::loadOrderEnvironment($objOrder);
             }
             // Status update has been cancelled, do not update
             if (!$objOrder->updateOrderStatus($varValue)) {
                 return $dc->activeRecord->order_status;
             }
         }
     }
     return $varValue;
 }
Example #9
0
 /**
  * Determine if this tax rate is applicable
  *
  * @param float $fltPrice
  * @param array $arrAddresses
  *
  * @return bool
  */
 public function isApplicable($fltPrice, $arrAddresses)
 {
     // Tax rate is limited to another store config
     if ($this->config > 0 && $this->config != Isotope::getConfig()->id) {
         return false;
     }
     // Tax rate is for guests only
     if ($this->guests && FE_USER_LOGGED_IN === true && !$this->protected) {
         return false;
     }
     // Tax rate is protected but no member is logged in
     if ($this->protected && FE_USER_LOGGED_IN !== true && !$this->guests) {
         return false;
     }
     // Tax rate is protected and member logged in, check member groups
     if ($this->protected && FE_USER_LOGGED_IN === true) {
         $groups = deserialize($this->groups);
         if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, \FrontendUser::getInstance()->groups))) {
             return false;
         }
     }
     // !HOOK: use tax rate
     if (isset($GLOBALS['ISO_HOOKS']['useTaxRate']) && is_array($GLOBALS['ISO_HOOKS']['useTaxRate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['useTaxRate'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $varValue = $objCallback->{$callback}[1]($this, $fltPrice, $arrAddresses);
             if ($varValue !== true) {
                 return false;
             }
         }
     }
     $arrAddress = deserialize($this->address);
     if (!empty($arrAddress) && is_array($arrAddress)) {
         foreach ($arrAddresses as $name => $objAddress) {
             if (!in_array($name, $arrAddress)) {
                 continue;
             }
             if ($this->countries != '' && !in_array($objAddress->country, trimsplit(',', $this->countries))) {
                 continue;
             }
             if ($this->subdivisions != '' && !in_array($objAddress->subdivision, trimsplit(',', $this->subdivisions))) {
                 continue;
             }
             // Check if address has a valid postal code
             if ($this->postalCodes != '') {
                 $arrCodes = \Isotope\Frontend::parsePostalCodes($this->postalCodes);
                 if (!in_array($objAddress->postal, $arrCodes)) {
                     continue;
                 }
             }
             $arrPrice = deserialize($this->amount);
             if (is_array($arrPrice) && !empty($arrPrice) && strlen($arrPrice[0])) {
                 if (strlen($arrPrice[1])) {
                     if ($arrPrice[0] > $fltPrice || $arrPrice[1] < $fltPrice) {
                         continue;
                     }
                 } else {
                     if ($arrPrice[0] != $fltPrice) {
                         continue;
                     }
                 }
             }
             if ($this->exemptOnValidVAT) {
                 $validators = deserialize(Isotope::getConfig()->vatNoValidators);
                 if (!empty($validators) && is_array($validators)) {
                     foreach ($validators as $type) {
                         /** @type IsotopeVatNoValidator $service */
                         $service = new $GLOBALS['ISO_VAT'][$type]();
                         if ($service->exemptTax($objAddress, $this)) {
                             continue 2;
                         }
                     }
                 }
             }
             // This address is valid, otherwise one of the check would have skipped this (continue)
             return true;
         }
         // No address has passed all checks and returned true
         return false;
     }
     // Addresses are not checked at all, return true
     return true;
 }
Example #10
0
 /**
  * Loads the page configuration and language before generating a PDF.
  *
  * @param IsotopeProductCollection $objCollection
  */
 protected function prepareEnvironment(IsotopeProductCollection $objCollection)
 {
     global $objPage;
     if (!is_object($objPage) && $objCollection->pageId > 0) {
         $objPage = \PageModel::findWithDetails($objCollection->pageId);
         $objPage = \Isotope\Frontend::loadPageConfig($objPage);
         \System::loadLanguageFile('default', $GLOBALS['TL_LANGUAGE'], true);
     }
 }
 public function addToTemplate($intProductType, Order $objOrder, \Template $objTemplate, array $arrConfig = array())
 {
     $arrGalleries = array();
     // FIX - call to custom function since addItemsToTemplate isn't static
     $arrItems = static::addItemsToTemplate($intProductType, $objOrder, $objTemplate, $arrConfig['sorting']);
     $objTemplate->id = $objOrder->id;
     $objTemplate->collection = $objOrder;
     $objTemplate->config = $objOrder->getRelated('config_id') || Isotope::getConfig();
     $objTemplate->surcharges = Frontend::formatSurcharges($objOrder->getSurcharges());
     $objTemplate->subtotal = Isotope::formatPriceWithCurrency($objOrder->getSubtotal());
     $objTemplate->total = Isotope::formatPriceWithCurrency($objOrder->getTotal());
     $objTemplate->tax_free_subtotal = Isotope::formatPriceWithCurrency($objOrder->getTaxFreeSubtotal());
     $objTemplate->tax_free_total = Isotope::formatPriceWithCurrency($objOrder->getTaxFreeTotal());
     $objTemplate->hasAttribute = function ($strAttribute, ProductCollectionItem $objItem) {
         if (!$objItem->hasProduct()) {
             return false;
         }
         $objProduct = $objItem->getProduct();
         return in_array($strAttribute, $objProduct->getAttributes()) || in_array($strAttribute, $objProduct->getVariantAttributes());
     };
     $objTemplate->generateAttribute = function ($strAttribute, ProductCollectionItem $objItem, array $arrOptions = array()) {
         if (!$objItem->hasProduct()) {
             return '';
         }
         $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strAttribute];
         if (!$objAttribute instanceof IsotopeAttribute) {
             throw new \InvalidArgumentException($strAttribute . ' is not a valid attribute');
         }
         return $objAttribute->generate($objItem->getProduct(), $arrOptions);
     };
     $objTemplate->getGallery = function ($strAttribute, ProductCollectionItem $objItem) use($arrConfig, &$arrGalleries) {
         if (!$objItem->hasProduct()) {
             return new Standard();
         }
         $strCacheKey = 'product' . $objItem->product_id . '_' . $strAttribute;
         $arrConfig['jumpTo'] = $objItem->getRelated('jumpTo');
         if (!isset($arrGalleries[$strCacheKey])) {
             $arrGalleries[$strCacheKey] = Gallery::createForProductAttribute($objItem->getProduct(), $strAttribute, $arrConfig);
         }
         return $arrGalleries[$strCacheKey];
     };
     // !HOOK: allow overriding of the template
     if (isset($GLOBALS['ISO_HOOKS']['addCollectionToTemplate']) && is_array($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['addCollectionToTemplate'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objTemplate, $arrItems, $objOrder);
         }
     }
 }
Example #12
0
 /**
  * Return true or false depending on if shipping method is available
  * @return  bool
  * @todo must check availability for a specific product collection (and not hardcoded to the current cart)
  */
 public function isAvailable()
 {
     if (!$this->enabled && BE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->guests && FE_USER_LOGGED_IN === true || $this->protected && FE_USER_LOGGED_IN !== true) {
         return false;
     }
     if ($this->protected) {
         $arrGroups = deserialize($this->groups);
         if (!is_array($arrGroups) || empty($arrGroups) || !count(array_intersect($arrGroups, \FrontendUser::getInstance()->groups))) {
             return false;
         }
     }
     if ($this->minimum_total > 0 && $this->minimum_total > Isotope::getCart()->getSubtotal() || $this->maximum_total > 0 && $this->maximum_total < Isotope::getCart()->getSubtotal()) {
         return false;
     }
     $objScale = Isotope::getCart()->addToScale();
     if (($minWeight = Weight::createFromTimePeriod($this->minimum_weight)) !== null && $objScale->isLessThan($minWeight)) {
         return false;
     }
     if (($maxWeight = Weight::createFromTimePeriod($this->maximum_weight)) !== null && $objScale->isMoreThan($maxWeight)) {
         return false;
     }
     if ($this->minimum_quantity > 0 || $this->maximum_quantity > 0) {
         $quantity = 0;
         if ('cart_items' !== $this->quantity_mode && 'cart_products' !== $this->quantity_mode) {
             throw new \InvalidArgumentException(sprintf('Unknown quantity mode "%s"', $this->quantity_mode));
         }
         foreach (Isotope::getCart()->getItems() as $item) {
             if (!$item->hasProduct() || !$item->getProduct()->isExemptFromShipping()) {
                 $quantity += 'cart_items' === $this->quantity_mode ? $item->quantity : 1;
             }
         }
         if ($this->minimum_quantity > 0 && $this->minimum_quantity > $quantity || $this->maximum_quantity > 0 && $this->maximum_quantity < $quantity) {
             return false;
         }
     }
     $arrConfigs = deserialize($this->config_ids);
     if (is_array($arrConfigs) && !empty($arrConfigs) && !in_array(Isotope::getConfig()->id, $arrConfigs)) {
         return false;
     }
     $objAddress = Isotope::getCart()->getShippingAddress();
     $arrCountries = deserialize($this->countries);
     if (is_array($arrCountries) && !empty($arrCountries)) {
         if (!in_array($objAddress->country, $arrCountries)) {
             return false;
         }
         $arrSubdivisions = deserialize($this->subdivisions);
         if (is_array($arrSubdivisions) && !empty($arrSubdivisions) && !in_array($objAddress->subdivision, $arrSubdivisions)) {
             return false;
         }
     }
     // Check if address has a valid postal code
     if ($this->postalCodes != '') {
         $arrCodes = \Isotope\Frontend::parsePostalCodes($this->postalCodes);
         if (!in_array($objAddress->postal, $arrCodes)) {
             return false;
         }
     }
     if ($this->product_types_condition != 'calculation') {
         $arrConfigTypes = deserialize($this->product_types);
         if (is_array($arrConfigTypes) && !empty($arrConfigTypes)) {
             $arrItems = Isotope::getCart()->getItems();
             $arrItemTypes = array();
             foreach ($arrItems as $objItem) {
                 if ($objItem->hasProduct()) {
                     $arrItemTypes[] = $objItem->getProduct()->type;
                 } elseif ($this->product_types_condition == 'onlyAvailable') {
                     // If one product in cart is not of given type, shipping method is not available
                     return false;
                 }
             }
             $arrItemTypes = array_unique($arrItemTypes);
             switch ($this->product_types_condition) {
                 case 'onlyAvailable':
                     if (count(array_diff($arrItemTypes, $arrConfigTypes)) > 0) {
                         return false;
                     }
                     break;
                 case 'oneAvailable':
                     if (count(array_intersect($arrConfigTypes, $arrItemTypes)) == 0) {
                         return false;
                     }
                     break;
                 case 'allAvailable':
                     if (count(array_intersect($arrConfigTypes, $arrItemTypes)) != count($arrConfigTypes)) {
                         return false;
                     }
                     break;
                 default:
                     throw new \UnexpectedValueException('Unknown product type condition "' . $this->product_types_condition . '"');
             }
         }
     }
     return true;
 }
Example #13
0
 /**
  * Find jumpTo page for current category scope
  *
  * @param \Isotope\Model\Product\Standard $objProduct
  *
  * @return \PageModel
  */
 protected function findJumpToPage($objProduct)
 {
     global $objPage;
     global $objIsotopeListPage;
     $productCategories = $objProduct->getCategories(true);
     $arrCategories = array();
     if ($this->iso_category_scope != 'current_category' && $this->iso_category_scope != '' && $objPage->alias != 'index') {
         $arrCategories = array_intersect($productCategories, $this->findCategories());
     }
     // If our current category scope does not match with any product category,
     // use the first allowed product category in the current root page
     if (empty($arrCategories)) {
         $arrCategories = $productCategories;
     }
     $arrCategories = Frontend::getPagesInCurrentRoot($arrCategories, \FrontendUser::getInstance());
     if (!empty($arrCategories) && ($objCategories = \PageModel::findMultipleByIds($arrCategories)) !== null) {
         $blnMoreThanOne = $objCategories->count() > 1;
         foreach ($objCategories as $objCategory) {
             if ($objCategory->alias == 'index' && $blnMoreThanOne) {
                 continue;
             }
             return $objCategory;
         }
     }
     return $objIsotopeListPage ?: $objPage;
 }
Example #14
0
 /**
  * Returns true if the product is available
  *
  * @param IsotopeProductCollection|\Isotope\Model\ProductCollection $objCollection
  *
  * @return bool
  */
 public function isAvailableForCollection(IsotopeProductCollection $objCollection)
 {
     if ($objCollection->isLocked()) {
         return true;
     }
     if (isset($GLOBALS['ISO_HOOKS']['productIsAvailable']) && is_array($GLOBALS['ISO_HOOKS']['productIsAvailable'])) {
         foreach ($GLOBALS['ISO_HOOKS']['productIsAvailable'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $available = $objCallback->{$callback}[1]($this, $objCollection);
             // If return value is boolean then we accept it as result
             if (true === $available || false === $available) {
                 return $available;
             }
         }
     }
     if (BE_USER_LOGGED_IN !== true && !$this->isPublished()) {
         return false;
     }
     // Show to guests only
     if ($this->arrData['guests'] && $objCollection->member > 0 && BE_USER_LOGGED_IN !== true && !$this->arrData['protected']) {
         return false;
     }
     // Protected product
     if (BE_USER_LOGGED_IN !== true && $this->arrData['protected']) {
         if ($objCollection->member == 0) {
             return false;
         }
         $groups = deserialize($this->arrData['groups']);
         $memberGroups = deserialize($objCollection->getRelated('member')->groups);
         if (!is_array($groups) || empty($groups) || !is_array($memberGroups) || empty($memberGroups) || !count(array_intersect($groups, $memberGroups))) {
             return false;
         }
     }
     // Check that the product is in any page of the current site
     if (count(\Isotope\Frontend::getPagesInCurrentRoot($this->getCategories(), $objCollection->getRelated('member'))) == 0) {
         return false;
     }
     // Check if "advanced price" is available
     if (null === $this->getPrice($objCollection) && (in_array('price', $this->getAttributes()) || $this->hasVariantPrices())) {
         return false;
     }
     return true;
 }
Example #15
0
 /**
  * Use generatePage Hook to inject necessary javascript
  */
 public function injectScripts()
 {
     if (!empty($GLOBALS['AJAX_PRODUCTS']) && is_array($GLOBALS['AJAX_PRODUCTS'])) {
         $GLOBALS['TL_MOOTOOLS'][] = "\n<script>\nwindow.addEvent('domready', function() {\n    IsotopeProducts.setLoadMessage('" . specialchars($GLOBALS['TL_LANG']['MSC']['loadingProductData']) . "');\n    IsotopeProducts.attach(JSON.decode('" . json_encode($GLOBALS['AJAX_PRODUCTS']) . "'));\n});\n</script>";
     }
     $strMessages = \Isotope\Frontend::getIsotopeMessages();
     if ($strMessages != '') {
         $GLOBALS['TL_MOOTOOLS'][] = "\n<script>\nwindow.addEvent('domready', function()\n{\n    Isotope.displayBox('" . $strMessages . "', true);\n});\n</script>";
     }
 }
Example #16
0
 /**
  * Run the controller
  */
 public function run()
 {
     $objMethod = null;
     try {
         $strMod = $this->getModule();
         $intId = $this->getModuleId();
         if ($strMod == '' || $intId == 0) {
             \System::log('Invalid post-sale request (param error): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Bad Request', 400);
             $objResponse->send();
         }
         switch (strtolower($strMod)) {
             case 'pay':
                 $objMethod = Payment::findByPk($intId);
                 break;
             case 'ship':
                 $objMethod = Shipping::findByPk($intId);
                 break;
         }
         if (null === $objMethod) {
             \System::log('Invalid post-sale request (model not found): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Found', 404);
             $objResponse->send();
         }
         \System::log('New post-sale request: ' . \Environment::get('request'), __METHOD__, TL_ACCESS);
         if (!$objMethod instanceof IsotopePostsale) {
             \System::log('Invalid post-sale request (interface not implemented): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Implemented', 501);
             $objResponse->send();
         }
         $objOrder = $objMethod->getPostsaleOrder();
         if (null === $objOrder || !$objOrder instanceof IsotopeProductCollection) {
             \System::log(get_class($objMethod) . ' did not return a valid order', __METHOD__, TL_ERROR);
             $objResponse = new Response('Failed Dependency', 424);
             $objResponse->send();
         }
         global $objPage;
         // Load page configuration
         if (!is_object($objPage) && $objOrder->pageId > 0) {
             $objPage = \PageModel::findWithDetails($objOrder->pageId);
             $objPage = \Isotope\Frontend::loadPageConfig($objPage);
         }
         // Set the current system to the language when the user placed the order.
         // This will result in correct e-mails and payment description.
         if ($GLOBALS['TL_LANGUAGE'] != $objOrder->language) {
             $GLOBALS['TL_LANGUAGE'] = $objOrder->language;
             \System::loadLanguageFile('default', $objOrder->language, true);
         }
         Isotope::setConfig($objOrder->getRelated('config_id'));
         if (($objCart = $objOrder->getRelated('source_collection_id')) !== null && $objCart instanceof Cart) {
             Isotope::setCart($objCart);
         }
         $objMethod->processPostsale($objOrder);
         $objResponse = new Response();
         $objResponse->send();
     } catch (\Exception $e) {
         \System::log(sprintf('Exception in post-sale request in file "%s" on line "%s" with message "%s".', $e->getFile(), $e->getLine(), $e->getMessage()), __METHOD__, TL_ERROR);
         $objResponse = new Response('Internal Server Error', 500);
         $objResponse->send();
     }
 }
Example #17
0
 /**
  * Run the controller
  */
 public function run()
 {
     $this->logRequest();
     $objMethod = null;
     try {
         $strMod = $this->getModule();
         $intId = $this->getModuleId();
         if ($strMod == '' || $intId == 0) {
             \System::log('Invalid post-sale request (param error): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Bad Request', 400);
             $objResponse->send();
         }
         switch (strtolower($strMod)) {
             case 'pay':
                 $objMethod = Payment::findByPk($intId);
                 break;
             case 'ship':
                 $objMethod = Shipping::findByPk($intId);
                 break;
         }
         if (null === $objMethod) {
             \System::log('Invalid post-sale request (model not found): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Found', 404);
             $objResponse->send();
         }
         \System::log('New post-sale request: ' . \Environment::get('request'), __METHOD__, TL_ACCESS);
         if (!$objMethod instanceof IsotopePostsale) {
             \System::log('Invalid post-sale request (interface not implemented): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Implemented', 501);
             $objResponse->send();
         }
         /** @type Order $objOrder */
         $objOrder = $objMethod->getPostsaleOrder();
         if (null === $objOrder || !$objOrder instanceof IsotopeProductCollection) {
             \System::log(get_class($objMethod) . ' did not return a valid order', __METHOD__, TL_ERROR);
             $objResponse = new Response('Failed Dependency', 424);
             $objResponse->send();
         }
         Frontend::loadOrderEnvironment($objOrder);
         $objMethod->processPostsale($objOrder);
         $objResponse = new Response();
         $objResponse->send();
     } catch (\Exception $e) {
         \System::log(sprintf('Exception in post-sale request. See system/logs/isotope_postsale.log for details.', $e->getFile(), $e->getLine(), $e->getMessage()), __METHOD__, TL_ERROR);
         log_message(sprintf("Exception in post-sale request\n%s\n\n", $e->getTraceAsString()), 'isotope_postsale.log');
         $objResponse = new Response('Internal Server Error', 500);
         $objResponse->send();
     }
 }