示例#1
0
 /**
  * Initialize the object
  * @param array
  */
 public function __construct(\Database\Result $objResult = null)
 {
     parent::__construct($objResult);
     $this->arrData['allowed_cc_types'] = deserialize($this->arrData['allowed_cc_types']);
     if (is_array($this->arrData['allowed_cc_types'])) {
         $this->arrData['allowed_cc_types'] = array_intersect(static::getAllowedCCTypes(), $this->arrData['allowed_cc_types']);
     }
 }
 /**
  * Set the current record from an array
  *
  * @param array $arrData The data record
  *
  * @return \Model The model object
  */
 public function setRow(array $arrData)
 {
     $this->arrProducts = deserialize($arrData['products']);
     $this->arrTaxIds = explode(',', $arrData['tax_id']);
     if (!is_array($this->arrProducts)) {
         $this->arrProducts = array();
     }
     if (!is_array($this->arrTaxIds)) {
         $this->arrTaxIds = array();
     }
     unset($arrData['products'], $arrData['tax_id']);
     return parent::setRow($arrData);
 }
示例#3
0
 /**
  * Also delete child table records when dropping this collection
  * @return integer
  */
 public function delete()
 {
     $this->ensureNotLocked();
     // !HOOK: additional functionality when deleting a collection
     if (isset($GLOBALS['ISO_HOOKS']['deleteCollection']) && is_array($GLOBALS['ISO_HOOKS']['deleteCollection'])) {
         foreach ($GLOBALS['ISO_HOOKS']['deleteCollection'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $blnRemove = $objCallback->{$callback}[1]($this);
             if ($blnRemove === false) {
                 return 0;
             }
         }
     }
     $intPid = $this->id;
     $intAffectedRows = parent::delete();
     if ($intAffectedRows > 0 && $intPid > 0) {
         \Database::getInstance()->query("DELETE FROM " . \Isotope\Model\ProductCollectionItem::getTable() . " WHERE pid={$intPid}");
         \Database::getInstance()->query("DELETE FROM " . \Isotope\Model\Address::getTable() . " WHERE ptable='" . static::$strTable . "' AND pid={$intPid}");
     }
     $this->arrCache = array();
     $this->arrItems = null;
     $this->arrSurcharges = null;
     return $intAffectedRows;
 }
示例#4
0
文件: Product.php 项目: Aziz-JH/core
 /**
  * Return a model or collection based on the database result type
  */
 protected static function find(array $arrOptions)
 {
     $arrOptions['group'] = static::getTable() . '.id' . (null === $arrOptions['group'] ? '' : ', ' . $arrOptions['group']);
     $objProducts = parent::find($arrOptions);
     if (null === $objProducts) {
         return null;
     }
     $arrFilters = $arrOptions['filters'];
     $arrSorting = $arrOptions['sorting'];
     if (!empty($arrFilters) || !empty($arrSorting)) {
         $arrProducts = $objProducts->getModels();
         if (!empty($arrFilters)) {
             $arrProducts = array_filter($arrProducts, function ($objProduct) use($arrFilters) {
                 $arrGroups = array();
                 foreach ($arrFilters as $objFilter) {
                     $blnMatch = $objFilter->matches($objProduct);
                     if ($objFilter->hasGroup()) {
                         $arrGroups[$objFilter->getGroup()] = $arrGroups[$objFilter->getGroup()] ?: $blnMatch;
                     } elseif (!$blnMatch) {
                         return false;
                     }
                 }
                 if (!empty($arrGroups) && in_array(false, $arrGroups)) {
                     return false;
                 }
                 return true;
             });
         }
         // $arrProducts can be empty if the filter removed all records
         if (!empty($arrSorting) && !empty($arrProducts)) {
             $arrParam = array();
             $arrData = array();
             foreach ($arrSorting as $strField => $arrConfig) {
                 foreach ($arrProducts as $objProduct) {
                     // Both SORT_STRING and SORT_REGULAR are case sensitive, strings starting with a capital letter will come before strings starting with a lowercase letter.
                     // To perform a case insensitive search, force the sorting order to be determined by a lowercase copy of the original value.
                     // Temporary fix for price attribute (see #945)
                     if ($strField == 'price') {
                         $arrData[$strField][$objProduct->id] = $objProduct->getPrice() !== null ? $objProduct->getPrice()->getAmount() : 0;
                     } else {
                         $arrData[$strField][$objProduct->id] = strtolower(str_replace('"', '', $objProduct->{$strField}));
                     }
                 }
                 $arrParam[] =& $arrData[$strField];
                 $arrParam[] = $arrConfig[0];
                 $arrParam[] = $arrConfig[1];
             }
             // Add product array as the last item. This will sort the products array based on the sorting of the passed in arguments.
             $arrParam[] =& $arrProducts;
             call_user_func_array('array_multisort', $arrParam);
         }
         $objProducts = new \Model\Collection($arrProducts, static::$strTable);
     }
     return $objProducts;
 }