本文整理汇总了PHP中Magento\Eav\Model\Config类的典型用法代码示例。如果您正苦于以下问题:PHP Config类的具体用法?PHP Config怎么用?PHP Config使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLike
/**
* Test a search using 'like' condition
*/
public function testLike()
{
$attributeCode = 'description';
$attributeCodeId = 42;
$attribute = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
$attribute->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
$this->eavConfig->expects($this->once())->method('getAttribute')->with(Product::ENTITY, $attributeCodeId)->willReturn($attribute);
$filtersData = ['catalog_product_entity_text' => [$attributeCodeId => ['like' => 'search text']]];
$this->filterBuilder->expects($this->once())->method('setField')->with($attributeCode)->willReturn($this->filterBuilder);
$this->filterBuilder->expects($this->once())->method('setValue')->with('search text')->willReturn($this->filterBuilder);
$filter = $this->getMock('Magento\\Framework\\Api\\Filter');
$this->filterBuilder->expects($this->once())->method('create')->willReturn($filter);
$criteria = $this->getMock('Magento\\Framework\\Api\\Search\\SearchCriteria', [], [], '', false);
$this->criteriaBuilder->expects($this->once())->method('create')->willReturn($criteria);
$criteria->expects($this->once())->method('setRequestName')->with('advanced_search_container');
$tempTable = $this->getMock('Magento\\Framework\\DB\\Ddl\\Table', [], [], '', false);
$temporaryStorage = $this->getMock('Magento\\Framework\\Search\\Adapter\\Mysql\\TemporaryStorage', [], [], '', false);
$temporaryStorage->expects($this->once())->method('storeApiDocuments')->willReturn($tempTable);
$this->temporaryStorageFactory->expects($this->once())->method('create')->willReturn($temporaryStorage);
$searchResult = $this->getMock('Magento\\Framework\\Api\\Search\\SearchResultInterface', [], [], '', false);
$this->search->expects($this->once())->method('search')->willReturn($searchResult);
// addFieldsToFilter will load filters,
// then loadWithFilter will trigger _renderFiltersBefore code in Advanced/Collection
$this->assertSame($this->advancedCollection, $this->advancedCollection->addFieldsToFilter($filtersData)->loadWithFilter());
}
示例2: getEntityTypeId
/**
* Retrieve catalog_product entity type id
*
* @return int
*/
public function getEntityTypeId()
{
if ($this->_entityTypeId === null) {
$this->_entityTypeId = (int) $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
}
return $this->_entityTypeId;
}
示例3: upgrade
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
if (version_compare($context->getVersion(), '2.0.6', '<')) {
$this->upgradeVersionTwoZeroSix($customerSetup);
}
if (version_compare($context->getVersion(), '2.0.1', '<')) {
$this->upgradeVersionTwoZeroOne($customerSetup);
}
if (version_compare($context->getVersion(), '2.0.2') < 0) {
$this->upgradeVersionTwoZeroTwo($customerSetup);
}
if (version_compare($context->getVersion(), '2.0.3', '<')) {
$this->upgradeVersionTwoZeroThree($customerSetup);
}
if (version_compare($context->getVersion(), '2.0.4', '<')) {
$this->upgradeVersionTwoZeroFour($customerSetup);
}
if (version_compare($context->getVersion(), '2.0.5', '<')) {
$this->upgradeVersionTwoZeroFive($customerSetup, $setup);
}
if (version_compare($context->getVersion(), '2.0.6', '<')) {
$setup->getConnection()->delete($setup->getTable('customer_form_attribute'), ['form_code = ?' => 'checkout_register']);
}
if (version_compare($context->getVersion(), '2.0.7', '<')) {
$this->upgradeVersionTwoZeroSeven($customerSetup);
$this->upgradeCustomerPasswordResetlinkExpirationPeriodConfig($setup);
}
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->reindexAll();
$this->eavConfig->clear();
$setup->endSetup();
}
示例4: upgrade
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
if (version_compare($context->getVersion(), '2.0.1', '<')) {
$entityAttributes = ['customer' => ['website_id' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false], 'created_in' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true], 'email' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true], 'group_id' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false], 'dob' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false], 'taxvat' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true], 'confirmation' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false], 'created_at' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false], 'gender' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false]], 'customer_address' => ['company' => ['is_used_in_grid' => true, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true], 'street' => ['is_used_in_grid' => true, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true], 'city' => ['is_used_in_grid' => true, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true], 'country_id' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false], 'region' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true], 'region_id' => ['is_used_in_grid' => true, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false], 'postcode' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true], 'telephone' => ['is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true], 'fax' => ['is_used_in_grid' => true, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true]]];
$this->upgradeAttributes($entityAttributes, $customerSetup);
}
if (version_compare($context->getVersion(), '2.0.2') < 0) {
$entityTypeId = $customerSetup->getEntityTypeId(Customer::ENTITY);
$attributeId = $customerSetup->getAttributeId($entityTypeId, 'gender');
$option = ['attribute_id' => $attributeId, 'values' => [3 => 'Not Specified']];
$customerSetup->addAttributeOption($option);
}
if (version_compare($context->getVersion(), '2.0.3', '<')) {
$entityAttributes = ['customer_address' => ['region_id' => ['is_used_in_grid' => false, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => false], 'firstname' => ['is_used_in_grid' => true, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true], 'lastname' => ['is_used_in_grid' => true, 'is_visible_in_grid' => false, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true]]];
$this->upgradeAttributes($entityAttributes, $customerSetup);
}
if (version_compare($context->getVersion(), '2.0.4', '<')) {
$customerSetup->addAttribute(Customer::ENTITY, 'updated_at', ['type' => 'static', 'label' => 'Updated At', 'input' => 'date', 'required' => false, 'sort_order' => 87, 'visible' => false, 'system' => false]);
}
if (version_compare($context->getVersion(), '2.0.5', '<')) {
$this->upgradeHash($setup);
$entityAttributes = ['customer_address' => ['fax' => ['is_visible' => false, 'is_system' => false]]];
$this->upgradeAttributes($entityAttributes, $customerSetup);
}
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->reindexAll();
$this->eavConfig->clear();
$setup->endSetup();
}
示例5: run
/**
* {@inheritdoc}
*/
public function run()
{
$this->logger->log('Installing sales rules:');
$file = 'SalesRule/sales_rules.csv';
$fileName = $this->fixtureHelper->getPath($file);
$csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
$attribute = $this->eavConfig->getAttribute('catalog_product', 'sku');
if ($attribute->getIsUsedForPromoRules() == 0) {
$attribute->setIsUsedForPromoRules('1')->save();
}
foreach ($csvReader as $row) {
/** @var \Magento\SalesRule\Model\Resource\Rule\Collection $ruleCollection */
$ruleCollection = $this->ruleCollectionFactory->create();
$ruleCollection->addFilter('name', $row['name']);
if ($ruleCollection->count() > 0) {
continue;
}
$row['customer_group_ids'] = $this->catalogRule->getGroupIds();
$row['website_ids'] = $this->catalogRule->getWebsiteIds();
$row['conditions_serialized'] = $this->catalogRule->convertSerializedData($row['conditions_serialized']);
$row['actions_serialized'] = $this->catalogRule->convertSerializedData($row['actions_serialized']);
/** @var \Magento\SalesRule\Model\Rule $rule */
$rule = $this->ruleFactory->create();
$rule->loadPost($row);
$rule->save();
$this->logger->logInline('.');
}
}
示例6: install
/**
* @param array $productFixtures
* @param array $galleryFixtures
* @throws \Exception
*/
public function install(array $productFixtures, array $galleryFixtures)
{
$this->eavConfig->clear();
$this->setGalleryFixtures($galleryFixtures);
$product = $this->productFactory->create();
foreach ($productFixtures as $fileName) {
$fileName = $this->fixtureManager->getFixture($fileName);
if (!file_exists($fileName)) {
continue;
}
$rows = $this->csvReader->getData($fileName);
$header = array_shift($rows);
foreach ($rows as $row) {
$data = [];
foreach ($row as $key => $value) {
$data[$header[$key]] = $value;
}
$row = $data;
$attributeSetId = $this->catalogConfig->getAttributeSetId(4, $row['attribute_set']);
$this->converter->setAttributeSetId($attributeSetId);
$data = $this->converter->convertRow($row);
$product->unsetData();
$product->setData($data);
$product->setTypeId($this->productType)->setAttributeSetId($attributeSetId)->setWebsiteIds([$this->storeManager->getDefaultStoreView()->getWebsiteId()])->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setStockData(['is_in_stock' => 1, 'manage_stock' => 0])->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
if (empty($data['visibility'])) {
$product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
}
$this->prepareProduct($product, $data);
$product->save();
$this->installGallery($product);
}
}
}
示例7: afterSave
/**
* Save EAV default value after save
*
* @return $this
*/
public function afterSave()
{
$result = parent::afterSave();
$attributeObject = $this->eavConfig->getAttribute('customer', 'disable_auto_group_change');
$attributeObject->setData('default_value', $this->getValue());
$attributeObject->save();
return $result;
}
示例8: getAllAttributeCodes
/**
* Get all attribute codes for a given entity type and attribute set
*
* @param string $entityType
* @param int $attributeSetId
* @param string|null $storeId
* @return array Attribute codes
*/
public function getAllAttributeCodes($entityType, $attributeSetId = 0, $storeId = null)
{
if (null === $storeId) {
$storeId = $this->storeManager->getStore()->getId();
}
$object = new \Magento\Framework\DataObject(['store_id' => $storeId, 'attribute_set_id' => $attributeSetId]);
return $this->eavConfig->getEntityAttributeCodes($entityType, $object);
}
示例9: doesEntityHaveOverriddenUrlKeyForStore
/**
* Check that entity has overridden url key for specific store
*
* @param int $storeId
* @param int $entityId
* @param string $entityType
* @throws \InvalidArgumentException
* @return bool
*/
public function doesEntityHaveOverriddenUrlKeyForStore($storeId, $entityId, $entityType)
{
$attribute = $this->eavConfig->getAttribute($entityType, 'url_key');
if (!$attribute) {
throw new \InvalidArgumentException(sprintf('Cannot retrieve attribute for entity type "%s"', $entityType));
}
$select = $this->connection->select()->from($attribute->getBackendTable(), 'store_id')->where('attribute_id = ?', $attribute->getId())->where('entity_id = ?', $entityId);
return in_array($storeId, $this->connection->fetchCol($select));
}
示例10: __construct
/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\ImportExport\Model\Export\Factory $collectionFactory
* @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Eav\Model\Config $eavConfig
* @param array $data
*/
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $eavConfig, array $data = [])
{
$this->_localeDate = $localeDate;
parent::__construct($scopeConfig, $storeManager, $collectionFactory, $resourceColFactory, $data);
if (isset($data['entity_type_id'])) {
$this->_entityTypeId = $data['entity_type_id'];
} else {
$this->_entityTypeId = $eavConfig->getEntityType($this->getEntityTypeCode())->getEntityTypeId();
}
}
示例11: testAfterSave
public function testAfterSave()
{
$value = true;
$attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['save', 'setData'])->disableOriginalConstructor()->getMockForAbstractClass();
$this->eavConfigMock->expects($this->once())->method('getAttribute')->with('customer', 'disable_auto_group_change')->willReturn($attributeMock);
$attributeMock->expects($this->once())->method('setData')->with('default_value', $value);
$attributeMock->expects($this->once())->method('save');
$this->model->setValue($value);
$this->assertEquals($this->model, $this->model->afterSave());
}
示例12: __construct
/**
* @param FixtureHelper $fixtureHelper
* @param CsvReaderFactory $csvReaderFactory
* @param ProductFactory $productFactory
* @param GalleryAttribute $galleryAttribute
* @param \Magento\Eav\Model\Config $eavConfig
* @param Logger $logger
*/
public function __construct(FixtureHelper $fixtureHelper, CsvReaderFactory $csvReaderFactory, ProductFactory $productFactory, GalleryAttribute $galleryAttribute, \Magento\Eav\Model\Config $eavConfig, Logger $logger)
{
$this->fixtureHelper = $fixtureHelper;
$this->galleryAttribute = $galleryAttribute;
$this->productFactory = $productFactory;
$this->csvReaderFactory = $csvReaderFactory;
$this->mediaAttribute = $eavConfig->getAttribute('catalog_product', 'media_gallery');
$this->logger = $logger;
$this->loadFixtures();
}
示例13: setUp
protected function setUp()
{
$this->searchBuilderMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false);
$this->filterBuilderMock = $this->getMock('Magento\\Framework\\Api\\FilterBuilder', [], [], '', false);
$this->attributeRepositoryMock = $this->getMock('Magento\\Eav\\Api\\AttributeRepositoryInterface', [], [], '', false);
$this->searchResultMock = $this->getMock('Magento\\Framework\\Api\\SearchResultsInterface', ['getItems', 'getSearchCriteria', 'getTotalCount', 'setItems', 'setSearchCriteria', 'setTotalCount', '__wakeup'], [], '', false);
$this->eavConfigMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
$this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn(new \Magento\Framework\DataObject(['default_attribute_set_id' => 3]));
$this->model = (new ObjectManager($this))->getObject('Magento\\Catalog\\Model\\Category\\AttributeRepository', ['searchCriteriaBuilder' => $this->searchBuilderMock, 'filterBuilder' => $this->filterBuilderMock, 'eavAttributeRepository' => $this->attributeRepositoryMock, 'eavConfig' => $this->eavConfigMock]);
}
示例14: __construct
/**
* Constructor
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param EavValidationRules $eavValidationRules
* @param CustomerCollectionFactory $customerCollectionFactory
* @param Config $eavConfig
* @param FilterPool $filterPool
* @param array $meta
* @param array $data
*/
public function __construct($name, $primaryFieldName, $requestFieldName, EavValidationRules $eavValidationRules, CustomerCollectionFactory $customerCollectionFactory, Config $eavConfig, FilterPool $filterPool, array $meta = [], array $data = [])
{
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->eavValidationRules = $eavValidationRules;
$this->collection = $customerCollectionFactory->create();
$this->collection->addAttributeToSelect('*');
$this->eavConfig = $eavConfig;
$this->filterPool = $filterPool;
$this->meta['customer']['fields'] = $this->getAttributesMeta($this->eavConfig->getEntityType('customer'));
$this->meta['address']['fields'] = $this->getAttributesMeta($this->eavConfig->getEntityType('customer_address'));
}
示例15: validateSkeletonSet
/**
* @param int $skeletonId
* @return void
* @throws StateException
*/
protected function validateSkeletonSet($skeletonId)
{
try {
$skeletonSet = $this->attributeSetRepository->get($skeletonId);
$productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
if ($skeletonSet->getEntityTypeId() != $productEntityId) {
throw new StateException(__('Can not create attribute set based on non product attribute set.'));
}
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
throw new StateException(__('Can not create attribute set based on not existing attribute set'));
}
}