本文整理汇总了PHP中Magento\Framework\StoreManagerInterface::getWebsites方法的典型用法代码示例。如果您正苦于以下问题:PHP StoreManagerInterface::getWebsites方法的具体用法?PHP StoreManagerInterface::getWebsites怎么用?PHP StoreManagerInterface::getWebsites使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\StoreManagerInterface
的用法示例。
在下文中一共展示了StoreManagerInterface::getWebsites方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Set new customer group to all his quotes
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function dispatch(\Magento\Framework\Event\Observer $observer)
{
/** @var CustomerData $customerDataObject */
$customerDataObject = $observer->getEvent()->getCustomerDataObject();
/** @var CustomerData $origCustomerDataObject */
$origCustomerDataObject = $observer->getEvent()->getOrigCustomerDataObject();
if ($customerDataObject->getGroupId() !== $origCustomerDataObject->getGroupId()) {
/**
* It is needed to process customer's quotes for all websites
* if customer accounts are shared between all of them
*/
/** @var $websites \Magento\Store\Model\Website[] */
$websites = $this->_config->isWebsiteScope() ? array($this->_storeManager->getWebsite($customerDataObject->getWebsiteId())) : $this->_storeManager->getWebsites();
foreach ($websites as $website) {
$quote = $this->_quoteFactory->create();
$quote->setWebsite($website);
$quote->loadByCustomer($customerDataObject->getId());
if ($quote->getId()) {
$quote->setCustomerGroupId($customerDataObject->getGroupId());
$quote->collectTotals();
$quote->save();
}
}
}
}
示例2: toOptionArray
/**
* @return array
*/
public function toOptionArray()
{
if (!$this->_options) {
$this->_options = array();
foreach ($this->_storeManager->getWebsites() as $website) {
$id = $website->getId();
$name = $website->getName();
if ($id != 0) {
$this->_options[] = array('value' => $id, 'label' => $name);
}
}
}
return $this->_options;
}
示例3: _initWebsites
/**
* Initialize website values
*
* @param bool $withDefault
* @return $this
*/
protected function _initWebsites($withDefault = false)
{
/** @var $website \Magento\Store\Model\Website */
foreach ($this->_storeManager->getWebsites($withDefault) as $website) {
$this->_websiteCodeToId[$website->getCode()] = $website->getId();
}
return $this;
}
示例4: getWebsiteOptionHash
/**
* Get websites as id => name associative array
*
* @param bool $withDefault
* @param string $attribute
* @return array
*/
public function getWebsiteOptionHash($withDefault = false, $attribute = 'name')
{
$options = array();
foreach ($this->_storeManager->getWebsites((bool) $withDefault && $this->_isAdminScopeAllowed) as $website) {
$options[$website->getId()] = $website->getDataUsingMethod($attribute);
}
return $options;
}
示例5: _getWebsites
/**
* Retrieve website collection array
*
* @return array
*/
protected function _getWebsites()
{
if (is_null($this->_websites)) {
try {
$this->_websites = $this->_storeManager->getWebsites();
} catch (\Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
return $this->_websites;
}
示例6: getSharedWebsiteIds
/**
* Returns shared website Ids.
*
* @param int $websiteId the ID to use if website scope is on
* @return int[]
*/
public function getSharedWebsiteIds($websiteId)
{
$ids = array();
if ($this->isWebsiteScope()) {
$ids[] = $websiteId;
} else {
foreach ($this->_storeManager->getWebsites() as $website) {
$ids[] = $website->getId();
}
}
return $ids;
}
示例7: _checkSingleStoreMode
/**
* Set correct scope if isSingleStoreMode = true
*
* @param \Magento\Backend\Model\Config\Structure\Element\Field $fieldConfig
* @param \Magento\Framework\App\Config\ValueInterface $dataObject
* @return void
*/
protected function _checkSingleStoreMode(\Magento\Backend\Model\Config\Structure\Element\Field $fieldConfig, $dataObject)
{
$isSingleStoreMode = $this->_storeManager->isSingleStoreMode();
if (!$isSingleStoreMode) {
return;
}
if (!$fieldConfig->showInDefault()) {
$websites = $this->_storeManager->getWebsites();
$singleStoreWebsite = array_shift($websites);
$dataObject->setScope('websites');
$dataObject->setWebsiteCode($singleStoreWebsite->getCode());
$dataObject->setScopeCode($singleStoreWebsite->getCode());
$dataObject->setScopeId($singleStoreWebsite->getId());
}
}
示例8: _getWebsitesMap
/**
* Prepare website map
*
* @return array
*/
protected function _getWebsitesMap()
{
$map = array();
$websites = $this->_storeManager->getWebsites(true);
foreach ($websites as $website) {
$map[$website->getId()] = $website->getDefaultStore()->getId();
}
return $map;
}
示例9: _getStoreByWebsite
/**
* @param \Magento\Framework\StoreManagerInterface $storage
* @param string $scopeCode
* @return null|string
*/
protected function _getStoreByWebsite(\Magento\Framework\StoreManagerInterface $storage, $scopeCode)
{
$websites = $storage->getWebsites(true, true);
if (!isset($websites[$scopeCode])) {
return null;
}
if (!$websites[$scopeCode]->getDefaultGroupId()) {
return null;
}
return $this->_getStoreByGroup($storage, $websites[$scopeCode]->getDefaultGroupId());
}
示例10: applyAllRulesForDateRange
/**
* Generate catalog price rules prices for specified date range
* If from date is not defined - will be used previous day by UTC
* If to date is not defined - will be used next day by UTC
*
* @param int|string|null $fromDate
* @param int|string|null $toDate
* @param int $productId
* @return $this
* @throws \Exception
*/
public function applyAllRulesForDateRange($fromDate = null, $toDate = null, $productId = null)
{
$write = $this->_getWriteAdapter();
$write->beginTransaction();
$this->_eventManager->dispatch('catalogrule_before_apply', array('resource' => $this));
$clearOldData = false;
if ($fromDate === null) {
$fromDate = mktime(0, 0, 0, date('m'), date('d') - 1);
/**
* If fromDate not specified we can delete all data oldest than 1 day
* We have run it for clear table in case when cron was not installed
* and old data exist in table
*/
$clearOldData = true;
}
if (is_string($fromDate)) {
$fromDate = strtotime($fromDate);
}
if ($toDate === null) {
$toDate = mktime(0, 0, 0, date('m'), date('d') + 1);
}
if (is_string($toDate)) {
$toDate = strtotime($toDate);
}
$product = null;
if ($productId instanceof Product) {
$product = $productId;
$productId = $productId->getId();
}
$this->removeCatalogPricesForDateRange($fromDate, $toDate, $productId);
if ($clearOldData) {
$this->deleteOldData($fromDate, $productId);
}
$dayPrices = array();
try {
/**
* Update products rules prices per each website separately
* because of max join limit in mysql
*/
foreach ($this->_storeManager->getWebsites(false) as $website) {
$productsStmt = $this->_getRuleProductsStmt($fromDate, $toDate, $productId, $website->getId());
$dayPrices = array();
$stopFlags = array();
$prevKey = null;
while ($ruleData = $productsStmt->fetch()) {
$ruleProductId = $ruleData['product_id'];
$productKey = $ruleProductId . '_' . $ruleData['website_id'] . '_' . $ruleData['customer_group_id'];
if ($prevKey && $prevKey != $productKey) {
$stopFlags = array();
}
/**
* Build prices for each day
*/
for ($time = $fromDate; $time <= $toDate; $time += self::SECONDS_IN_DAY) {
if (($ruleData['from_time'] == 0 || $time >= $ruleData['from_time']) && ($ruleData['to_time'] == 0 || $time <= $ruleData['to_time'])) {
$priceKey = $time . '_' . $productKey;
if (isset($stopFlags[$priceKey])) {
continue;
}
if (!isset($dayPrices[$priceKey])) {
$dayPrices[$priceKey] = array('rule_date' => $time, 'website_id' => $ruleData['website_id'], 'customer_group_id' => $ruleData['customer_group_id'], 'product_id' => $ruleProductId, 'rule_price' => $this->_calcRuleProductPrice($ruleData), 'latest_start_date' => $ruleData['from_time'], 'earliest_end_date' => $ruleData['to_time']);
} else {
$dayPrices[$priceKey]['rule_price'] = $this->_calcRuleProductPrice($ruleData, $dayPrices[$priceKey]);
$dayPrices[$priceKey]['latest_start_date'] = max($dayPrices[$priceKey]['latest_start_date'], $ruleData['from_time']);
$dayPrices[$priceKey]['earliest_end_date'] = min($dayPrices[$priceKey]['earliest_end_date'], $ruleData['to_time']);
}
if ($ruleData['action_stop']) {
$stopFlags[$priceKey] = true;
}
}
}
$prevKey = $productKey;
if (count($dayPrices) > 1000) {
$this->_saveRuleProductPrices($dayPrices);
$dayPrices = array();
}
}
$this->_saveRuleProductPrices($dayPrices);
}
$this->_saveRuleProductPrices($dayPrices);
$write->delete($this->getTable('catalogrule_group_website'), array());
$timestamp = $this->_coreDate->gmtTimestamp();
$select = $write->select()->distinct(true)->from($this->getTable('catalogrule_product'), array('rule_id', 'customer_group_id', 'website_id'))->where("{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)");
$query = $select->insertFromSelect($this->getTable('catalogrule_group_website'));
$write->query($query);
$write->commit();
} catch (\Exception $e) {
$this->_logger->logException($e);
$write->rollback();
//.........这里部分代码省略.........
示例11: _initWebsites
/**
* Initialize website values.
*
* @return $this
*/
protected function _initWebsites()
{
/** @var $website \Magento\Store\Model\Website */
foreach ($this->_storeManager->getWebsites() as $website) {
$this->_websiteCodeToId[$website->getCode()] = $website->getId();
$this->_websiteCodeToStoreIds[$website->getCode()] = array_flip($website->getStoreCodes());
}
return $this;
}
示例12: getSharedWebsiteIds
/**
* Retrieve shared website ids
*
* @return int[]
*/
public function getSharedWebsiteIds()
{
$ids = $this->_getData('shared_website_ids');
if ($ids === null) {
$ids = array();
if ((bool) $this->getSharingConfig()->isWebsiteScope()) {
$ids[] = $this->getWebsiteId();
} else {
foreach ($this->_storeManager->getWebsites() as $website) {
$ids[] = $website->getId();
}
}
$this->setData('shared_website_ids', $ids);
}
return $ids;
}