• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Data\Collection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Magento\Framework\Data\Collection的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Collection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: testAddFiltersVerifyAddConditionsToRegistry

 /**
  * @param array $attributes
  * @param array $values
  * @param string $currentCurrencyCode
  * @param string $baseCurrencyCode
  * @dataProvider addFiltersDataProvider
  */
 public function testAddFiltersVerifyAddConditionsToRegistry(array $attributes, array $values, $currentCurrencyCode = 'GBP', $baseCurrencyCode = 'USD')
 {
     $registry = new \Magento\Framework\Registry();
     $this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(['like' => '%simple%']));
     $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator($attributes)));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $advancedFactory = $this->getMockBuilder('Magento\\CatalogSearch\\Model\\ResourceModel\\AdvancedFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $advancedFactory->expects($this->once())->method('create')->willReturn($this->resource);
     $productCollectionFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $productCollectionFactory->expects($this->any())->method('create')->willReturn($this->collection);
     $this->store->expects($this->any())->method('getCurrentCurrencyCode')->willReturn($currentCurrencyCode);
     $this->store->expects($this->any())->method('getBaseCurrencyCode')->willReturn($baseCurrencyCode);
     $this->currency->expects($this->any())->method('getRate')->with($currentCurrencyCode)->willReturn(1.5);
     $currency = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->setMethods(['load', 'format'])->disableOriginalConstructor()->getMock();
     $currency->expects($this->any())->method('load')->willReturnSelf();
     $currency->expects($this->any())->method('format')->willReturnArgument(0);
     $currencyFactory = $this->getMockBuilder('Magento\\Directory\\Model\\CurrencyFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $currencyFactory->expects($this->any())->method('create')->willReturn($currency);
     /** @var \Magento\CatalogSearch\Model\Advanced $instance */
     $instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', ['registry' => $registry, 'resourceProvider' => $this->resourceProvider, 'data' => ['attributes' => $this->dataCollection], 'advancedFactory' => $advancedFactory, 'productCollectionFactory' => $productCollectionFactory, 'storeManager' => $this->storeManager, 'currencyFactory' => $currencyFactory]);
     $instance->addFilters($values);
     $this->assertNotNull($registry->registry('advanced_search_conditions'));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:37,代码来源:AdvancedTest.php


示例2: testAddFiltersVerifyAddConditionsToRegistry

 public function testAddFiltersVerifyAddConditionsToRegistry()
 {
     $registry = new \Magento\Framework\Registry();
     $values = ['sku' => 'simple'];
     $this->resourceProvider->expects($this->once())->method('getResource')->willReturn($this->resource);
     $this->resourceProvider->expects($this->once())->method('getResourceCollection')->willReturn($this->collection);
     $this->resourceProvider->expects($this->once())->method('getAdvancedResultCollection')->willReturn($this->collection);
     $this->skuAttribute->expects($this->once())->method('getTable')->will($this->returnValue('catalog_product_entity'));
     $this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(['like' => '%simple%']));
     $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue('sku'));
     $this->attribute->expects($this->any())->method('getStoreLabel')->will($this->returnValue('SKU'));
     $this->attribute->expects($this->any())->method('getFrontendInput')->will($this->returnValue('text'));
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->skuAttribute));
     $this->attribute->expects($this->any())->method('getBackendType')->will($this->returnValue('static'));
     $this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->attribute])));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     /** @var \Magento\CatalogSearch\Model\Advanced $instance */
     $instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', ['registry' => $registry, 'resourceProvider' => $this->resourceProvider, 'data' => ['attributes' => $this->dataCollection]]);
     $instance->addFilters($values);
     $this->assertNotNull($registry->registry('advanced_search_conditions'));
 }
开发者ID:,项目名称:,代码行数:28,代码来源:


示例3: update

 /**
  * Update specified argument
  *
  * @param \Magento\Framework\Data\Collection $argument
  * @return \Magento\Framework\Data\Collection
  */
 public function update($argument)
 {
     $calls = $argument->getUpdaterCall();
     $calls[] = 'updater call';
     $argument->setUpdaterCall($calls);
     return $argument;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:LayoutArgumentObjectUpdater.php


示例4: filterTermsCondition

 /**
  * Apply term filter
  *
  * @param \Magento\Framework\Data\Collection        $collection The collection
  * @param \Magento\Backend\Block\Widget\Grid\Column $column     Columns to filter
  */
 protected function filterTermsCondition($collection, $column)
 {
     if (!($value = $column->getFilter()->getValue())) {
         return;
     }
     $collection->setTermFilter($value);
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:13,代码来源:Grid.php


示例5: addFilter

 /**
  * {@inheritdoc}
  */
 public function addFilter(Collection $collection, $field, $condition = null)
 {
     if (isset($condition['eq']) && $condition['eq']) {
         /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection  */
         $collection->addStoreFilter($this->storeManager->getStore($condition['eq']));
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:AddStoreFieldToCollection.php


示例6: addFilter

 /**
  * {@inheritdoc}
  */
 public function addFilter(Collection $collection, $field, $condition = null)
 {
     if (isset($condition['from'])) {
         $collection->getSelect()->where(AbstractCollection::ATTRIBUTE_TABLE_ALIAS_PREFIX . 'qty.qty >= ?', (double) $condition['from']);
     }
     if ($condition['to']) {
         $collection->getSelect()->where(AbstractCollection::ATTRIBUTE_TABLE_ALIAS_PREFIX . 'qty.qty <= ?', (double) $condition['to']);
     }
 }
开发者ID:nja78,项目名称:magento2,代码行数:12,代码来源:AddQuantityFilterToCollection.php


示例7: prepareIntervalsCollection

 /**
  * Add items to interval collection
  *
  * @param Collection $collection
  * @param string $from
  * @param string $to
  * @param string $periodType
  * @return void
  */
 public function prepareIntervalsCollection($collection, $from, $to, $periodType = self::REPORT_PERIOD_TYPE_DAY)
 {
     $intervals = $this->getIntervals($from, $to, $periodType);
     foreach ($intervals as $interval) {
         $item = $this->_itemFactory->create();
         $item->setPeriod($interval);
         $item->setIsEmpty();
         $collection->addItem($item);
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Data.php


示例8: apply

 /**
  * Apply fulltext filters
  *
  * @param Collection $collection
  * @param Filter $filter
  * @return void
  */
 public function apply(Collection $collection, Filter $filter)
 {
     if (!$collection instanceof AbstractDb) {
         throw new \InvalidArgumentException('Database collection required.');
     }
     /** @var SearchResult $collection */
     $mainTable = $collection->getMainTable();
     $columns = $this->getFulltextIndexColumns($collection, $mainTable);
     if (!$columns) {
         return;
     }
     $columns = $this->addTableAliasToColumns($columns, $collection, $mainTable);
     $collection->getSelect()->where('MATCH(' . implode(',', $columns) . ') AGAINST(?)', $filter->getValue());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:21,代码来源:FulltextFilter.php


示例9: testGenerate

 public function testGenerate()
 {
     $imageFile = 'image.jpg';
     $imageItem = $this->objectManager->getObject('Magento\\Framework\\Object', ['data' => ['file' => $imageFile]]);
     $this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
     $this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
     $this->config->expects($this->once())->method('getVars')->with('Magento_Catalog')->willReturn($this->getTestData());
     $this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => 'Magento\\theme'])->willReturn($this->config);
     $this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn(['Magento\\theme']);
     $this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'image', $imageFile, $this->imageHelper], [$this->product, 'small_image', $imageFile, $this->imageHelper], [$this->product, 'thumbnail', $imageFile, $this->imageHelper]]));
     $this->imageHelper->expects($this->exactly(3))->method('resize')->will($this->returnValueMap([[300, 300, $this->imageHelper], [200, 200, $this->imageHelper], [100, 100, $this->imageHelper]]));
     $this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
     $this->model->generate($this->product);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:14,代码来源:CacheTest.php


示例10: __construct

 /**
  * Constructor
  *
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Magento\Framework\Config\ThemeFactory $themeConfigFactory
  * @param ThemePackageList $themePackageList
  * @param ReadFactory $dirReadFactory
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Config\ThemeFactory $themeConfigFactory, ThemePackageList $themePackageList, ReadFactory $dirReadFactory)
 {
     parent::__construct($entityFactory);
     $this->themeConfigFactory = $themeConfigFactory;
     $this->themePackageList = $themePackageList;
     $this->dirReadFactory = $dirReadFactory;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Collection.php


示例11: __construct

 /**
  * Collection constructor
  *
  * @param EntityFactoryInterface $entityFactory
  * @param ScopeTreeProviderInterface $scopeTree
  * @param MetadataProviderInterface $metadataProvider
  * @param ScopeConfigInterface $appConfig
  * @param ValueProcessor $valueProcessor
  */
 public function __construct(EntityFactoryInterface $entityFactory, ScopeTreeProviderInterface $scopeTree, MetadataProviderInterface $metadataProvider, ScopeConfigInterface $appConfig, ValueProcessor $valueProcessor)
 {
     parent::__construct($entityFactory);
     $this->scopeTree = $scopeTree;
     $this->metadataProvider = $metadataProvider;
     $this->appConfig = $appConfig;
     $this->valueProcessor = $valueProcessor;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:17,代码来源:Collection.php


示例12: __construct

 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Framework\Config\ThemeFactory $themeConfigFactory
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Config\ThemeFactory $themeConfigFactory, \Magento\Framework\Module\ThemeDir $themeDirs)
 {
     parent::__construct($entityFactory);
     $this->_directory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
     $this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
     $this->themeConfigFactory = $themeConfigFactory;
     $this->themeDirs = $themeDirs;
 }
开发者ID:vrann,项目名称:magento2-from-vendor,代码行数:13,代码来源:Collection.php


示例13: testGenerate

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerate()
 {
     $imageFile = 'image.jpg';
     $imageItem = $this->objectManager->getObject('Magento\\Framework\\DataObject', ['data' => ['file' => $imageFile]]);
     $this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
     $this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
     $data = $this->getTestData();
     $this->config->expects($this->once())->method('getMediaEntities')->with('Magento_Catalog')->willReturn($data);
     $themeMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $themeMock->expects($this->exactly(3))->method('getCode')->willReturn('Magento\\theme');
     $this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn([$themeMock]);
     $this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => $themeMock])->willReturn($this->config);
     $this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'product_image', $this->getImageData('product_image'), $this->imageHelper], [$this->product, 'product_small_image', $this->getImageData('product_small_image'), $this->imageHelper], [$this->product, 'product_thumbnail', $this->getImageData('product_thumbnail'), $this->imageHelper]]));
     $this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with($imageFile)->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepAspectRatio')->with($data['product_image']['aspect_ratio'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepFrame')->with($data['product_image']['frame'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepTransparency')->with($data['product_image']['transparency'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('constrainOnly')->with($data['product_image']['constrain'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('backgroundColor')->with($data['product_image']['background'])->willReturnSelf();
     $this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
     $this->model->generate($this->product);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:25,代码来源:CacheTest.php


示例14: __construct

 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Reports\Model\ResourceModel\Report\Collection\Factory $collectionFactory
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Reports\Model\ResourceModel\Report\Collection\Factory $collectionFactory)
 {
     $this->_localeDate = $localeDate;
     $this->_collectionFactory = $collectionFactory;
     parent::__construct($entityFactory);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:Collection.php


示例15: __construct

 /**
  * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
  * @param \Magento\Framework\Mview\ConfigInterface $config
  * @param State\CollectionFactory $statesFactory
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Magento\Framework\Mview\ConfigInterface $config, \Magento\Framework\Mview\View\State\CollectionFactory $statesFactory)
 {
     $this->config = $config;
     $this->statesFactory = $statesFactory;
     parent::__construct($entityFactory);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:Collection.php


示例16: setCollection

 /**
  * Set collection for pagination
  *
  * @param  \Magento\Framework\Data\Collection $collection
  * @return $this
  */
 public function setCollection($collection)
 {
     $this->_collection = $collection->setCurPage($this->getCurrentPage());
     // If not int - then not limit
     if ((int) $this->getLimit()) {
         $this->_collection->setPageSize($this->getLimit());
     }
     $this->_setFrameInitialized(false);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:Pager.php


示例17: __construct

 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Reports\Model\FlagFactory $reportsFlagFactory
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Reports\Model\FlagFactory $reportsFlagFactory)
 {
     parent::__construct($entityFactory);
     $this->_localeDate = $localeDate;
     $this->_reportsFlagFactory = $reportsFlagFactory;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:Collection.php


示例18: __construct

 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList)
 {
     $this->_cacheTypeList = $cacheTypeList;
     parent::__construct($entityFactory);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:9,代码来源:Collection.php


示例19: addField

 /**
  * {@inheritdoc}
  */
 public function addField(Collection $collection, $field, $alias = null)
 {
     $collection->joinField('qty', 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left');
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:7,代码来源:AddQuantityFieldToCollection.php


示例20: filterAttributeCollection

 /**
  * Clean up attribute collection
  *
  * @param \Magento\Framework\Data\Collection $collection
  * @return \Magento\Framework\Data\Collection
  */
 public function filterAttributeCollection(\Magento\Framework\Data\Collection $collection)
 {
     /** @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
     foreach ($collection as $attribute) {
         if (in_array($attribute->getAttributeCode(), $this->_disabledAttributes)) {
             $collection->removeItemByKey($attribute->getId());
         }
     }
     return $collection;
 }
开发者ID:kid17,项目名称:magento2,代码行数:16,代码来源:AbstractEntity.php



注:本文中的Magento\Framework\Data\Collection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Data\Form类代码示例发布时间:2022-05-23
下一篇:
PHP Result\RawFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap