本文整理汇总了PHP中Magento\Store\Model\Website类的典型用法代码示例。如果您正苦于以下问题:PHP Website类的具体用法?PHP Website怎么用?PHP Website使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Website类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundSave
/**
* Invalidate design config grid indexer on website creation
*
* @param StoreWebsite $subject
* @param \Closure $proceed
* @return StoreWebsite
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundSave(StoreWebsite $subject, \Closure $proceed)
{
$isObjectNew = $subject->getId() == 0;
$result = $proceed();
if ($isObjectNew) {
$this->indexerRegistry->get(Config::DESIGN_CONFIG_GRID_INDEXER_ID)->invalidate();
}
return $result;
}
示例2: afterGetDefaultStore
/**
* @param \Magento\Store\Model\Website $subject
* @param \Magento\Store\Model\Store $store
* @return \Magento\Store\Model\Store
*/
public function afterGetDefaultStore(Website $subject, Store $store)
{
if ($this->generalConfig->isAvailable() && $this->storeSwitcher->isInitialized()) {
$storeId = $this->storeSwitcher->getStoreId();
if ($store->getId() != $storeId && in_array($storeId, $subject->getStoreIds())) {
$store = $this->storeRepository->getById($storeId);
}
}
return $store;
}
示例3: testGetStoreValuesForForm
/**
* @dataProvider getStoreValuesForFormDataProvider
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function testGetStoreValuesForForm($empty, $all, $storeId, $groupId, $websiteId, $storeName, $groupName, $websiteName, $storeGroupId, $groupWebsiteId, $expectedResult)
{
$this->websiteMock->expects($this->any())->method('getId')->willReturn($websiteId);
$this->websiteMock->expects($this->any())->method('getName')->willReturn($websiteName);
$this->groupMock->expects($this->any())->method('getId')->willReturn($groupId);
$this->groupMock->expects($this->any())->method('getName')->willReturn($groupName);
$this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn($groupWebsiteId);
$this->storeMock->expects($this->any())->method('getId')->willReturn($storeId);
$this->storeMock->expects($this->any())->method('getName')->willReturn($storeName);
$this->storeMock->expects($this->any())->method('getGroupId')->willReturn($storeGroupId);
$this->model->setIsAdminScopeAllowed(true);
$this->assertEquals($this->model->getStoreValuesForForm($empty, $all), $expectedResult);
}
示例4: setUp
/**
* Set up
*/
public function setUp()
{
$this->sessionMock = $this->getMock('Magento\\Framework\\Session\\Generic', ['getCurrencyCode'], [], '', false);
$this->httpContextMock = $this->getMock('Magento\\Framework\\App\\Http\\Context', [], [], '', false);
$this->httpRequestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
$this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
$this->storeCookieManager = $this->getMock('Magento\\Store\\Api\\StoreCookieManagerInterface');
$this->storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$this->currentStoreMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$this->websiteMock = $this->getMock('Magento\\Store\\Model\\Website', ['getDefaultStore', '__wakeup'], [], '', false);
$this->closureMock = function () {
return 'ExpectedValue';
};
$this->subjectMock = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
$this->requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface');
$this->plugin = (new ObjectManager($this))->getObject('Magento\\Store\\App\\Action\\Plugin\\Context', ['session' => $this->sessionMock, 'httpContext' => $this->httpContextMock, 'httpRequest' => $this->httpRequestMock, 'storeManager' => $this->storeManager, 'storeCookieManager' => $this->storeCookieManager]);
$this->storeManager->expects($this->once())->method('getWebsite')->will($this->returnValue($this->websiteMock));
$this->storeManager->method('getDefaultStoreView')->willReturn($this->storeMock);
$this->storeManager->method('getStore')->willReturn($this->currentStoreMock);
$this->websiteMock->expects($this->once())->method('getDefaultStore')->will($this->returnValue($this->storeMock));
$this->storeMock->expects($this->once())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_DEFAULT));
$this->storeMock->expects($this->once())->method('getCode')->willReturn('default');
$this->currentStoreMock->expects($this->once())->method('getCode')->willReturn('custom_store');
$this->storeCookieManager->expects($this->once())->method('getStoreCodeFromCookie')->will($this->returnValue('storeCookie'));
$this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue('default'));
$this->currentStoreMock->expects($this->any())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_CURRENT_STORE));
}
示例5: setUp
protected function setUp()
{
$this->objectManager = new ObjectManager($this);
$this->assignedWebsites = [self::SECOND_WEBSITE_ID];
$this->websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
$this->secondWebsiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
$this->websiteRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\WebsiteRepositoryInterface')->setMethods(['getList', 'getDefault'])->getMockForAbstractClass();
$this->websiteRepositoryMock->expects($this->any())->method('getDefault')->willReturn($this->websiteMock);
$this->websiteRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->websiteMock, $this->secondWebsiteMock]);
$this->groupRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\GroupRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
$this->storeRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\StoreRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
$this->locatorMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Locator\\LocatorInterface')->setMethods(['getProduct', 'getWebsiteIds'])->getMockForAbstractClass();
$this->productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['getId'])->getMockForAbstractClass();
$this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
$this->locatorMock->expects($this->any())->method('getWebsiteIds')->willReturn($this->assignedWebsites);
$this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->setMethods(['isSingleStoreMode'])->getMockForAbstractClass();
$this->storeManagerMock->expects($this->any())->method('isSingleStoreMode')->willReturn(false);
$this->groupMock = $this->getMockBuilder('Magento\\Store\\Model\\ResourceModel\\Group\\Collection')->setMethods(['getId', 'getName', 'getWebsiteId'])->disableOriginalConstructor()->getMock();
$this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn(self::WEBSITE_ID);
$this->groupMock->expects($this->any())->method('getId')->willReturn(self::GROUP_ID);
$this->groupRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->groupMock]);
$this->storeViewMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getName', 'getId', 'getStoreGroupId'])->disableOriginalConstructor()->getMock();
$this->storeViewMock->expects($this->any())->method('getName')->willReturn(self::STORE_VIEW_NAME);
$this->storeViewMock->expects($this->any())->method('getStoreGroupId')->willReturn(self::GROUP_ID);
$this->storeViewMock->expects($this->any())->method('getId')->willReturn(self::STORE_VIEW_ID);
$this->storeRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->storeViewMock]);
$this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
$this->secondWebsiteMock->expects($this->any())->method('getId')->willReturn($this->assignedWebsites[0]);
$this->websiteMock->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
}
示例6: _processWebsite
/**
* Process website info
*
* @param \Magento\Store\Model\System\Store $storeModel
* @param \Magento\Store\Model\Website $website
* @param string $section
* @param string $curStore
* @param string $curWebsite
* @param array $options
* @return array
*/
protected function _processWebsite(\Magento\Store\Model\System\Store $storeModel, \Magento\Store\Model\Website $website, $section, $curStore, $curWebsite, array $options)
{
$websiteShow = false;
foreach ($storeModel->getGroupCollection() as $group) {
if ($group->getWebsiteId() != $website->getId()) {
continue;
}
$groupShow = false;
foreach ($storeModel->getStoreCollection() as $store) {
if ($store->getGroupId() != $group->getId()) {
continue;
}
if (!$websiteShow) {
$websiteShow = true;
$options['website_' . $website->getCode()] = array('label' => $website->getName(), 'url' => $this->getUrl('*/*/*', array('section' => $section, 'website' => $website->getCode())), 'selected' => !$curStore && $curWebsite == $website->getCode(), 'style' => 'padding-left:16px; background:#DDD; font-weight:bold;');
}
if (!$groupShow) {
$groupShow = true;
$options['group_' . $group->getId() . '_open'] = array('is_group' => true, 'is_close' => false, 'label' => $group->getName(), 'style' => 'padding-left:32px;');
}
$options['store_' . $store->getCode()] = array('label' => $store->getName(), 'url' => $this->getUrl('*/*/*', array('section' => $section, 'website' => $website->getCode(), 'store' => $store->getCode())), 'selected' => $curStore == $store->getCode(), 'style' => '');
}
if ($groupShow) {
$options['group_' . $group->getId() . '_close'] = array('is_group' => true, 'is_close' => true);
}
}
return $options;
}
示例7: testGetStoreIds
public function testGetStoreIds()
{
$expectedStoreIds = [1, 2, 3];
$websiteIds = ['test'];
$this->resource->expects($this->once())->method('getWebsiteIds')->will($this->returnValue($websiteIds));
$this->website->expects($this->once())->method('getStoreIds')->will($this->returnValue($expectedStoreIds));
$this->assertEquals($expectedStoreIds, $this->model->getStoreIds());
}
示例8: getWebsites
/**
* Get loaded websites
*
* @param bool $withDefault
* @param bool|string $codeKey
* @return \Magento\Store\Model\Website[]
*/
public function getWebsites($withDefault = false, $codeKey = false)
{
$websites = [];
if ($withDefault) {
$key = $codeKey ? $this->_website->getCode() : $this->_website->getId();
$websites[$key] = $this->_website;
}
return $websites;
}
示例9: afterGetDefault
/**
* @param \Magento\Store\Model\WebsiteRepository $subject
* @param \Magento\Store\Model\Website $website
* @return \Magento\Store\Model\Website
*/
public function afterGetDefault(WebsiteRepository $subject, Website $website)
{
if (!$this->isNeededProcess()) {
return $website;
}
if ($this->geoWebsite->getId() != $website->getId()) {
$website = $subject->getById($this->geoWebsite->getId());
}
return $website;
}
示例10: testToOptionArray
public function testToOptionArray()
{
$websiteCollection = [$this->websiteMock];
$groupCollection = [$this->groupMock];
$storeCollection = [$this->storeMock];
$expectedOptions = [['label' => __('All Store Views'), 'value' => '0'], ['label' => 'Main Website', 'value' => [['label' => ' Main Website Store', 'value' => [['label' => ' Default Store View', 'value' => '1']]]]]];
$this->systemStoreMock->expects($this->once())->method('getWebsiteCollection')->willReturn($websiteCollection);
$this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn($groupCollection);
$this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn($storeCollection);
$this->websiteMock->expects($this->atLeastOnce())->method('getId')->willReturn('1');
$this->websiteMock->expects($this->any())->method('getName')->willReturn('Main Website');
$this->groupMock->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn('1');
$this->groupMock->expects($this->atLeastOnce())->method('getId')->willReturn('1');
$this->groupMock->expects($this->atLeastOnce())->method('getName')->willReturn('Main Website Store');
$this->storeMock->expects($this->atLeastOnce())->method('getGroupId')->willReturn('1');
$this->storeMock->expects($this->atLeastOnce())->method('getName')->willReturn('Default Store View');
$this->storeMock->expects($this->atLeastOnce())->method('getId')->willReturn('1');
$this->escaperMock->expects($this->atLeastOnce())->method('escapeHtml')->willReturnMap([['Default Store View', null, 'Default Store View'], ['Main Website Store', null, 'Main Website Store'], ['Main Website', null, 'Main Website']]);
$this->assertEquals($expectedOptions, $this->options->toOptionArray());
}
示例11: testCallbackValidateProduct
/**
* @dataProvider dataProviderCallbackValidateProduct
* @param bool $validate
*
* @return void
*/
public function testCallbackValidateProduct($validate)
{
$args['product'] = $this->productModel;
$args['attributes'] = [];
$args['idx'] = 0;
$args['row'] = ['entity_id' => '1', 'entity_type_id' => '4', 'attribute_set_id' => '4', 'type_id' => 'simple', 'sku' => 'Product', 'has_options' => '0', 'required_options' => '0', 'created_at' => '2014-06-25 13:14:30', 'updated_at' => '2014-06-25 14:37:15'];
$this->storeManager->expects($this->any())->method('getWebsites')->with(false)->will($this->returnValue([$this->websiteModel, $this->websiteModel]));
$this->websiteModel->expects($this->at(0))->method('getId')->will($this->returnValue('1'));
$this->websiteModel->expects($this->at(2))->method('getId')->will($this->returnValue('2'));
$this->websiteModel->expects($this->any())->method('getDefaultStore')->will($this->returnValue($this->storeModel));
$this->storeModel->expects($this->at(0))->method('getId')->will($this->returnValue('1'));
$this->storeModel->expects($this->at(1))->method('getId')->will($this->returnValue('2'));
$this->combineFactory->expects($this->any())->method('create')->will($this->returnValue($this->condition));
$this->condition->expects($this->any())->method('validate')->will($this->returnValue($validate));
$this->condition->expects($this->any())->method('setRule')->will($this->returnSelf());
$this->productModel->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->rule->callbackValidateProduct($args);
$matchingProducts = $this->rule->getMatchingProductIds();
foreach ($matchingProducts['1'] as $matchingRules) {
$this->assertEquals($validate, $matchingRules);
}
}
示例12: clearWebsiteCache
/**
* Unset website by id from app cache
*
* @param null|bool|int|string|Website $websiteId
* @return void
*/
public function clearWebsiteCache($websiteId = null)
{
if (is_null($websiteId)) {
$websiteId = $this->getStore()->getWebsiteId();
} elseif ($websiteId instanceof Website) {
$websiteId = $websiteId->getId();
} elseif ($websiteId === true) {
$websiteId = $this->_website->getId();
}
if (!empty($this->_websites[$websiteId])) {
$website = $this->_websites[$websiteId];
unset($this->_websites[$website->getWebsiteId()]);
unset($this->_websites[$website->getCode()]);
}
}
示例13: testTierPrices
/**
* testGetTierPrices
* testSetTierPrices
*
* @dataProvider pricesDataProvider
*/
public function testTierPrices($priceScope, $expectedWebsiteId)
{
// establish the behavior of the mocks
$this->scopeConfigMock->expects($this->any())->method('getValue')->will($this->returnValue($priceScope));
$this->websiteMock->expects($this->any())->method('getId')->will($this->returnValue($expectedWebsiteId));
$this->tpFactory->expects($this->any())->method('create')->will($this->returnCallback(function () {
return $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\TierPrice');
}));
// create sample TierPrice objects that would be coming from a REST call
$tp1 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\TierPrice');
$tp1->setValue(10);
$tp1->setCustomerGroupId(1);
$tp1->setQty(11);
$tp2 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\TierPrice');
$tp2->setValue(20);
$tp2->setCustomerGroupId(2);
$tp2->setQty(22);
$tps = [$tp1, $tp2];
// force the product to have null tier prices
$this->product->setData($this::KEY_TIER_PRICE, null);
$this->assertNull($this->product->getData($this::KEY_TIER_PRICE));
// set the product with the TierPrice objects
$this->model->setTierPrices($this->product, $tps);
// test the data actually set on the product
$tpArray = $this->product->getData($this::KEY_TIER_PRICE);
$this->assertNotNull($tpArray);
$this->assertTrue(is_array($tpArray));
$this->assertEquals(sizeof($tps), sizeof($tpArray));
for ($i = 0; $i < sizeof($tps); $i++) {
$tpData = $tpArray[$i];
$this->assertEquals($expectedWebsiteId, $tpData['website_id'], 'Website Id does not match');
$this->assertEquals($tps[$i]->getValue(), $tpData['price'], 'Price/Value does not match');
$this->assertEquals($tps[$i]->getValue(), $tpData['website_price'], 'WebsitePrice/Value does not match');
$this->assertEquals($tps[$i]->getCustomerGroupId(), $tpData['cust_group'], 'Customer group Id does not match');
$this->assertEquals($tps[$i]->getQty(), $tpData['price_qty'], 'Qty does not match');
}
// test with the data retrieved as a REST object
$tpRests = $this->model->getTierPrices($this->product);
$this->assertNotNull($tpRests);
$this->assertTrue(is_array($tpRests));
$this->assertEquals(sizeof($tps), sizeof($tpRests));
for ($i = 0; $i < sizeof($tps); $i++) {
$this->assertEquals($tps[$i]->getValue(), $tpRests[$i]->getValue(), 'REST: Price/Value does not match');
$this->assertEquals($tps[$i]->getCustomerGroupId(), $tpRests[$i]->getCustomerGroupId(), 'REST: Customer group Id does not match');
$this->assertEquals($tps[$i]->getQty(), $tpRests[$i]->getQty(), 'REST: Qty does not match');
}
}
示例14: getMappedStoreName
/**
* Store name datafield.
*
* @param \Magento\Store\Model\Website $website
*
* @return mixed|string
*/
public function getMappedStoreName(\Magento\Store\Model\Website $website)
{
$mapped = $website->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME);
$storeName = $mapped ? $mapped : '';
return $storeName;
}
示例15: setWebsite
/**
* Set relation to the website
*
* @param Website $website
* @return void
*/
public function setWebsite(Website $website)
{
$this->setWebsiteId($website->getId());
}