예제 #1
0
 /**
  * Copy product collection items from another collection to this one (e.g. Cart to Order)
  * @param   IsotopeProductCollection
  * @return  array
  */
 public function copyItemsFrom(IsotopeProductCollection $objSource)
 {
     $this->ensureNotLocked();
     $this->updateDatabase();
     // Make sure database table has the latest prices
     $objSource->updateDatabase();
     $time = time();
     $arrIds = array();
     $arrOldItems = $objSource->getItems();
     foreach ($arrOldItems as $objOldItem) {
         // !HOOK: additional functionality when copying product to collection
         if (isset($GLOBALS['ISO_HOOKS']['copyCollectionItem']) && is_array($GLOBALS['ISO_HOOKS']['copyCollectionItem'])) {
             foreach ($GLOBALS['ISO_HOOKS']['copyCollectionItem'] as $callback) {
                 $objCallback = \System::importStatic($callback[0]);
                 if ($objCallback->{$callback}[1]($objOldItem, $objSource, $this) === false) {
                     continue;
                 }
             }
         }
         if ($objOldItem->hasProduct() && $this->hasProduct($objOldItem->getProduct())) {
             $objNewItem = $this->getItemForProduct($objOldItem->getProduct());
             $objNewItem->increaseQuantityBy($objOldItem->quantity);
         } else {
             $objNewItem = clone $objOldItem;
             $objNewItem->pid = $this->id;
             $objNewItem->tstamp = $time;
             $objNewItem->save();
         }
         $arrIds[$objOldItem->id] = $objNewItem->id;
     }
     if (!empty($arrIds)) {
         $this->tstamp = $time;
     }
     // !HOOK: additional functionality when adding product to collection
     if (isset($GLOBALS['ISO_HOOKS']['copiedCollectionItems']) && is_array($GLOBALS['ISO_HOOKS']['copiedCollectionItems'])) {
         foreach ($GLOBALS['ISO_HOOKS']['copiedCollectionItems'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($objSource, $this, $arrIds);
         }
     }
     // Empty cache
     $this->arrItems = null;
     $this->arrCache = null;
     return $arrIds;
 }