本文整理汇总了PHP中Magento\Framework\Data\Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'));
}
示例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'));
}
示例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;
}
示例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);
}
示例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']));
}
}
示例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']);
}
}
示例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);
}
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}