/** * Initializes the catalog item. * * @param MW_Tree_Node_Interface $node Tree node * @param array $listItems List of list items * @param array $refItems List of referenced items */ public function __construct(MW_Tree_Node_Interface $node, array $children = array(), array $listItems = array(), array $refItems = array()) { parent::__construct('', array(), $listItems, $refItems); MW_Common_Abstract::checkClassList('MShop_Catalog_Item_Interface', $children); $this->_children = $children; $this->_node = $node; }
/** * Initializes the instance with the given values. * * @param array $values Node values for internal use * @param array $children Children of the node implementing MW_Tree_Node_Interface * @throws MW_Common_Exception if the children doesn't implement the interface */ public function __construct(array $values = array(), $children = array()) { MW_Common_Abstract::checkClassList('MW_Tree_Node_Interface', $children); $this->_values = $values; $this->_children = $children; $this->_modified = false; }
/** * Initializes the site object. * * @param array $values Possible params to be set on initialization */ public function __construct(array $values = array(), array $children = array()) { MW_Common_Abstract::checkClassList('MShop_Locale_Item_Site_Interface', $children); parent::__construct('locale.site.', $values); $this->_values = $values; $this->_children = $children; }
/** * Initializes the object. * * @param string $url Initial url * @param string $method Initial method (e.g. post or get) * @param array $values Form parameters implementing MW_Common_Criteria_Attribute_Interface * @param boolean $external True if URL points to an external site, false if it stays on the same site */ public function __construct($url = '', $method = '', array $values = array(), $external = true) { MW_Common_Abstract::checkClassList('MW_Common_Criteria_Attribute_Interface', $values); $this->_url = (string) $url; $this->_external = (bool) $external; $this->_method = (string) $method; $this->_values = $values; }
/** * Initializes the object. * * @param string $operator Operator used for the expressions * @param array $list List of expression objects */ public function __construct($operator, array $list) { if (!isset(self::$_operators[$operator])) { throw new MW_Common_Exception(sprintf('Invalid operator "%1$s"', $operator)); } MW_Common_Abstract::checkClassList('MW_Common_Criteria_Expression_Interface', $list); $this->_operator = $operator; $this->_expressions = $list; }
/** * Initializes the shopping cart. * * @param MShop_Price_Item_Interface $price Default price of the basket (usually 0.00) * @param MShop_Locale_Item_Interface $locale Locale item containing the site, language and currency * @param array $values Associative list of key/value pairs containing * e.g. the order or user ID */ public function __construct(MShop_Price_Item_Interface $price, MShop_Locale_Item_Interface $locale, array $values = array(), array $products = array(), array $addresses = array(), array $services = array(), array $coupons = array()) { MW_Common_Abstract::checkClassList('MShop_Order_Item_Base_Product_Interface', $products); MW_Common_Abstract::checkClassList('MShop_Order_Item_Base_Address_Interface', $addresses); MW_Common_Abstract::checkClassList('MShop_Order_Item_Base_Service_Interface', $services); foreach ($coupons as $couponProducts) { MW_Common_Abstract::checkClassList('MShop_Order_Item_Base_Product_Interface', $couponProducts); } $this->_price = $price; $this->_locale = $locale; $this->_values = $values; $this->_products = $products; $this->_addresses = $addresses; $this->_services = $services; $this->_coupons = $coupons; $this->_modified = false; }
/** * Sets the new list of attribute items for the product. * * @param array $attributes List of attribute items implementing MShop_Order_Item_Base_Product_Attribute_Interface */ public function setAttributes(array $attributes) { MW_Common_Abstract::checkClassList('MShop_Order_Item_Base_Product_Attribute_Interface', $attributes); $this->_attributes = $attributes; $this->_attributesMap = null; $this->setModified(); }
/** * Rebuilds the catalog index text for searching products or specified list of products. * This can be a long lasting operation. * * @param MShop_Common_Item_Interface[] $items Associative list of product IDs and items implementing MShop_Product_Item_Interface */ public function rebuildIndex(array $items = array()) { if (empty($items)) { return; } MW_Common_Abstract::checkClassList('MShop_Product_Item_Interface', $items); $context = $this->_getContext(); $sites = $context->getLocale()->getSitePath(); $siteid = $context->getLocale()->getSiteId(); $langIds = $this->_getLanguageIds($sites); $editor = $context->getEditor(); $date = date('Y-m-d H:i:s'); $dbm = $context->getDatabaseManager(); $dbname = $this->_getResourceName(); $conn = $dbm->acquire($dbname); try { foreach ($items as $item) { $parentId = $item->getId(); // id is not $item->getId() for sub-products $listTypes = array(); foreach ($item->getListItems('text') as $listItem) { $listTypes[$listItem->getRefId()][] = $listItem->getType(); } $stmt = $this->_getCachedStatement($conn, 'mshop/catalog/manager/index/text/default/item/insert'); foreach ($item->getRefItems('text') as $refId => $refItem) { if (!isset($listTypes[$refId])) { $msg = sprintf('List type for text item with ID "%1$s" not available', $refId); throw new MShop_Catalog_Exception($msg); } foreach ($listTypes[$refId] as $listType) { $this->_saveText($stmt, $parentId, $siteid, $refId, $refItem->getLanguageId(), $listType, $refItem->getType(), 'product', $refItem->getContent(), $date, $editor); } } $nameList = array(); foreach ($item->getRefItems('text', 'name') as $refItem) { $nameList[$refItem->getLanguageId()] = $refItem; } foreach ($langIds as $langId) { if (!isset($nameList[$langId])) { $this->_saveText($stmt, $parentId, $siteid, null, $langId, 'default', 'name', 'product', $item->getLabel(), $date, $editor); } } } $dbm->release($conn, $dbname); } catch (Exception $e) { $dbm->release($conn, $dbname); throw $e; } $this->_saveAttributeTexts($items); foreach ($this->_getSubManagers() as $submanager) { $submanager->rebuildIndex($items); } }
/** * Stores the sortation objects for sorting the result. * * @param MW_Common_Criteria_Expression_Sort_SQL[] $sortations List of objects implementing MW_Common_Criteria_Expression_Sort_Interface * @return MW_Common_Criteria_Interface Object instance for fluent interface */ public function setSortations(array $sortations) { MW_Common_Abstract::checkClassList('MW_Common_Criteria_Expression_Sort_Interface', $sortations); $this->_sortations = $sortations; return $this; }
/** * Rebuilds the catalog index catalog for searching products or specified list of products. * This can be a long lasting operation. * * @param MShop_Common_Item_Interface[] $items Associative list of product IDs and items implementing MShop_Product_Item_Interface */ public function rebuildIndex(array $items = array()) { if (empty($items)) { return; } MW_Common_Abstract::checkClassList('MShop_Product_Item_Interface', $items); $ids = $listItems = array(); $context = $this->_getContext(); $listManager = MShop_Factory::createManager($context, 'catalog/list'); foreach ($items as $id => $item) { $ids[] = $id; } $search = $listManager->createSearch(true); $expr = array($search->compare('==', 'catalog.list.refid', $ids), $search->compare('==', 'catalog.list.domain', 'product'), $search->getConditions()); $search->setConditions($search->combine('&&', $expr)); $search->setSlice(0, 0x7fffffff); $result = $listManager->searchItems($search); foreach ($result as $listItem) { $listItems[$listItem->getRefId()][] = $listItem; } $date = date('Y-m-d H:i:s'); $editor = $context->getEditor(); $siteid = $context->getLocale()->getSiteId(); $dbm = $context->getDatabaseManager(); $dbname = $this->_getResourceName(); $conn = $dbm->acquire($dbname); try { foreach ($items as $id => $item) { $parentId = $item->getId(); // $id is not $item->getId() for sub-products $stmt = $this->_getCachedStatement($conn, 'mshop/catalog/manager/index/catalog/default/item/insert'); if (!array_key_exists($parentId, $listItems)) { continue; } foreach ((array) $listItems[$parentId] as $listItem) { $stmt->bind(1, $parentId, MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(2, $siteid, MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(3, $listItem->getParentId(), MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(4, $listItem->getType()); $stmt->bind(5, $listItem->getPosition(), MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(6, $date); //mtime $stmt->bind(7, $editor); $stmt->bind(8, $date); //ctime try { $stmt->execute()->finish(); } catch (MW_DB_Exception $e) { } // Ignore duplicates } } $dbm->release($conn, $dbname); } catch (Exception $e) { $dbm->release($conn, $dbname); throw $e; } foreach ($this->_getSubManagers() as $submanager) { $submanager->rebuildIndex($items); } }
/** * Rebuilds the catalog index attribute for searching products or specified list of products. * This can be a long lasting operation. * * @param MShop_Common_Item_Interface[] $items Associative list of product IDs and items implementing MShop_Product_Item_Interface */ public function rebuildIndex(array $items = array()) { if (empty($items)) { return; } MW_Common_Abstract::checkClassList('MShop_Product_Item_Interface', $items); $context = $this->_getContext(); $siteid = $context->getLocale()->getSiteId(); $editor = $context->getEditor(); $date = date('Y-m-d H:i:s'); $dbm = $context->getDatabaseManager(); $dbname = $this->_getResourceName(); $conn = $dbm->acquire($dbname); try { foreach ($items as $item) { $listTypes = array(); foreach ($item->getListItems('attribute') as $listItem) { $listTypes[$listItem->getRefId()][] = $listItem->getType(); } $stmt = $this->_getCachedStatement($conn, 'mshop/catalog/manager/index/attribute/default/item/insert'); foreach ($item->getRefItems('attribute') as $refId => $refItem) { if (!isset($listTypes[$refId])) { $msg = sprintf('List type for attribute item with ID "%1$s" not available', $refId); throw new MShop_Catalog_Exception($msg); } foreach ($listTypes[$refId] as $listType) { $stmt->bind(1, $item->getId(), MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(2, $siteid, MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(3, $refItem->getId(), MW_DB_Statement_Abstract::PARAM_INT); $stmt->bind(4, $listType); $stmt->bind(5, $refItem->getType()); $stmt->bind(6, $refItem->getCode()); $stmt->bind(7, $date); // mtime $stmt->bind(8, $editor); $stmt->bind(9, $date); // ctime try { $stmt->execute()->finish(); } catch (MW_DB_Exception $e) { } // Ignore duplicates } } } $dbm->release($conn, $dbname); } catch (Exception $e) { $dbm->release($conn, $dbname); throw $e; } foreach ($this->_getSubManagers() as $submanager) { $submanager->rebuildIndex($items); } }
/** * Sets the new plugins for translating values. * * @param array $plugins Associative list of names and the plugin implementing MW_Common_Criteria_Plugin_Interface */ protected function _setPlugins(array $plugins) { MW_Common_Abstract::checkClassList('MW_Common_Criteria_Plugin_Interface', $plugins); $this->_plugins = $plugins; }