예제 #1
0
 /**
  * Initialize a new collection and duplicate everything from the source
  * @param   IsotopeProductCollection
  */
 public static function createFromCollection(IsotopeProductCollection $objSource)
 {
     global $objPage;
     $objCollection = new static();
     $objConfig = $objSource->getRelated('config_id');
     if (null === $objConfig) {
         $objConfig = Isotope::getConfig();
     }
     $objCollection->uniqid = uniqid(Haste::getInstance()->call('replaceInsertTags', array((string) $objConfig->orderPrefix, false)), true);
     $objCollection->source_collection_id = (int) $objSource->id;
     $objCollection->config_id = (int) $objConfig->id;
     $objCollection->store_id = (int) $objSource->store_id;
     $objCollection->member = (int) $objSource->member;
     $objCollection->language = (string) $GLOBALS['TL_LANGUAGE'];
     $objCollection->currency = (string) $objConfig->currency;
     $objCollection->pageId = (int) $objPage->id;
     $objCollection->setShippingMethod($objSource->getShippingMethod());
     $objCollection->setPaymentMethod($objSource->getPaymentMethod());
     $objCollection->setShippingAddress($objSource->getShippingAddress());
     $objCollection->setBillingAddress($objSource->getBillingAddress());
     $arrItemIds = $objCollection->copyItemsFrom($objSource);
     $arrSurchargeIds = $objCollection->copySurchargesFrom($objSource, $arrItemIds);
     $objCollection->updateDatabase();
     // HOOK: order status has been updated
     if (isset($GLOBALS['ISO_HOOKS']['createFromProductCollection']) && is_array($GLOBALS['ISO_HOOKS']['createFromProductCollection'])) {
         foreach ($GLOBALS['ISO_HOOKS']['createFromProductCollection'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objCollection, $objSource, $arrItemIds, $arrSurchargeIds);
         }
     }
     return $objCollection;
 }
예제 #2
0
 /**
  * Replace insert tag for a product collection.
  *
  * @param IsotopeProductCollection $collection
  * @param array                    $tokens
  *
  * @return string
  */
 private function getValueForCollectionTag(IsotopeProductCollection $collection, array $tokens)
 {
     switch ($tokens[1]) {
         case 'items':
             return $collection->countItems();
         case 'quantity':
             return $collection->sumItemsQuantity();
         case 'items_label':
             $intCount = $collection->countItems();
             if (!$intCount) {
                 return '';
             }
             if ($intCount == 1) {
                 return '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')';
             } else {
                 return sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount);
             }
             break;
         case 'quantity_label':
             $intCount = $collection->sumItemsQuantity();
             if (!$intCount) {
                 return '';
             }
             if ($intCount == 1) {
                 return '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')';
             } else {
                 return sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount);
             }
             break;
         case 'subtotal':
             return Isotope::formatPriceWithCurrency($collection->getSubtotal());
         case 'taxfree_subtotal':
             return Isotope::formatPriceWithCurrency($collection->getTaxFreeSubtotal());
         case 'total':
             return Isotope::formatPriceWithCurrency($collection->getTotal());
         case 'taxfree_total':
             return Isotope::formatPriceWithCurrency($collection->getTaxFreeTotal());
         case 'billing_address':
             if (!$collection instanceof IsotopeOrderableCollection || ($address = $collection->getBillingAddress()) === null) {
                 return '';
             }
             return $this->getValueForAddressTag($address, $tokens[2]);
         case 'shipping_address':
             if (!$collection instanceof IsotopeOrderableCollection || !$collection->hasShipping() || ($address = $collection->getShippingAddress()) === null) {
                 return '';
             }
             return $this->getValueForAddressTag($address, $tokens[2]);
         default:
             return $collection->{$tokens[1]};
     }
 }
예제 #3
0
 /**
  * Initialize a new collection and duplicate everything from the source
  *
  * @param IsotopeProductCollection $objSource
  *
  * @return static
  */
 public static function createFromCollection(IsotopeProductCollection $objSource)
 {
     $objCollection = new static();
     $objConfig = $objSource->getRelated('config_id');
     if (null === $objConfig) {
         $objConfig = Isotope::getConfig();
     }
     $objCollection->source_collection_id = (int) $objSource->id;
     $objCollection->config_id = (int) $objConfig->id;
     $objCollection->store_id = (int) $objSource->store_id;
     $objCollection->member = (int) $objSource->member;
     $objCollection->setShippingMethod($objSource->getShippingMethod());
     $objCollection->setPaymentMethod($objSource->getPaymentMethod());
     $objCollection->setShippingAddress($objSource->getShippingAddress());
     $objCollection->setBillingAddress($objSource->getBillingAddress());
     $arrItemIds = $objCollection->copyItemsFrom($objSource);
     $objCollection->updateDatabase();
     // HOOK: order status has been updated
     if (isset($GLOBALS['ISO_HOOKS']['createFromProductCollection']) && is_array($GLOBALS['ISO_HOOKS']['createFromProductCollection'])) {
         foreach ($GLOBALS['ISO_HOOKS']['createFromProductCollection'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objCollection, $objSource, $arrItemIds);
         }
     }
     return $objCollection;
 }
예제 #4
0
 /**
  * Build a Hash string based on the shipping address
  * @param IsotopeProductCollection
  * @return string
  */
 protected static function makeHash(IsotopeProductCollection $objCollection, $arrExtras = array())
 {
     $strBase = get_called_class();
     $strBase .= !empty($arrExtras) ? implode(',', $arrExtras) : '';
     $objShippingAddress = $objCollection->getShippingAddress();
     $strBase .= $objShippingAddress->street_1;
     $strBase .= $objShippingAddress->city;
     $strBase .= $objShippingAddress->subdivision;
     $strBase .= $objShippingAddress->postal;
     // Hash the cart too
     foreach ($objCollection->getItems() as $item) {
         $strBase .= $item->quantity;
         $strBase .= $item->id;
         $strBase .= implode(',', $item->getOptions());
     }
     return md5($strBase);
 }