本文整理汇总了PHP中Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface类的典型用法代码示例。如果您正苦于以下问题:PHP JoinProcessorInterface类的具体用法?PHP JoinProcessorInterface怎么用?PHP JoinProcessorInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JoinProcessorInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: populateWithArray
/**
* Populate data object using data in array format.
*
* @param mixed $dataObject
* @param array $data
* @param string $interfaceName
* @return $this
*/
public function populateWithArray($dataObject, array $data, $interfaceName)
{
if ($dataObject instanceof ExtensibleDataInterface) {
$data = $this->joinProcessor->extractExtensionAttributes(get_class($dataObject), $data);
}
$this->_setDataValues($dataObject, $data, $interfaceName);
return $this;
}
开发者ID:kid17,项目名称:magento2,代码行数:16,代码来源:DataObjectHelper.php
示例2: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
{
$quoteCollection = $this->quoteCollectionFactory->create();
$this->extensionAttributesJoinProcessor->process($quoteCollection);
$searchData = $this->searchResultsDataFactory->create();
$searchData->setSearchCriteria($searchCriteria);
$searchData->setItems($quoteCollection->getItems());
return $searchData;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:TestRepository.php
示例3: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
{
$this->quoteCollection = $this->getQuoteCollection();
/** @var \Magento\Quote\Api\Data\CartSearchResultsInterface $searchData */
$searchData = $this->searchResultsDataFactory->create();
$searchData->setSearchCriteria($searchCriteria);
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $this->quoteCollection);
}
$searchData->setTotalCount($this->quoteCollection->getSize());
$sortOrders = $searchCriteria->getSortOrders();
if ($sortOrders) {
/** @var SortOrder $sortOrder */
foreach ($sortOrders as $sortOrder) {
$this->quoteCollection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
}
}
$this->quoteCollection->setCurPage($searchCriteria->getCurrentPage());
$this->quoteCollection->setPageSize($searchCriteria->getPageSize());
$this->extensionAttributesJoinProcessor->process($this->quoteCollection);
foreach ($this->quoteCollection->getItems() as $quote) {
/** @var CartInterface $quote */
$this->getLoadHandler()->load($quote);
}
$searchData->setItems($this->quoteCollection->getItems());
return $searchData;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:30,代码来源:QuoteRepository.php
示例4: getItems
/**
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return \Magento\Bundle\Api\Data\OptionInterface[]
*/
public function getItems(\Magento\Catalog\Api\Data\ProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$this->extensionAttributesJoinProcessor->process($optionCollection);
$optionList = [];
/** @var \Magento\Bundle\Model\Option $option */
foreach ($optionCollection as $option) {
$productLinks = $this->linkList->getItems($product, $option->getOptionId());
/** @var \Magento\Bundle\Api\Data\OptionInterface $optionDataObject */
$optionDataObject = $this->optionFactory->create();
$this->dataObjectHelper->populateWithArray($optionDataObject, $option->getData(), '\\Magento\\Bundle\\Api\\Data\\OptionInterface');
$optionDataObject->setOptionId($option->getOptionId())->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())->setSku($product->getSku())->setProductLinks($productLinks);
$optionList[] = $optionDataObject;
}
return $optionList;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:OptionList.php
示例5: getList
/**
* Retrieve customers addresses matching the specified criteria.
*
* @param SearchCriteriaInterface $searchCriteria
* @return \Magento\Customer\Api\Data\AddressSearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria)
{
$searchResults = $this->addressSearchResultsFactory->create();
/** @var Collection $collection */
$collection = $this->addressCollectionFactory->create();
$this->extensionAttributesJoinProcessor->process($collection, 'Magento\\Customer\\Api\\Data\\AddressInterface');
// Add filters from root filter group to the collection
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
}
$searchResults->setTotalCount($collection->getSize());
/** @var SortOrder $sortOrder */
foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
$field = $sortOrder->getField();
$collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
/** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
$addresses = [];
/** @var \Magento\Customer\Model\Address $address */
foreach ($collection->getItems() as $address) {
$addresses[] = $this->getById($address->getId());
}
$searchResults->setItems($addresses);
$searchResults->setSearchCriteria($searchCriteria);
return $searchResults;
}
开发者ID:nja78,项目名称:magento2,代码行数:35,代码来源:AddressRepository.php
示例6: testGetListSuccess
/**
* @param int $direction
* @param string $expectedDirection
* @dataProvider getListSuccessDataProvider
*/
public function testGetListSuccess($direction, $expectedDirection)
{
$searchResult = $this->getMock('\\Magento\\Quote\\Api\\Data\\CartSearchResultsInterface', [], [], '', false);
$searchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
$cartMock = $this->getMock('Magento\\Payment\\Model\\Cart', [], [], '', false);
$filterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false);
$pageSize = 10;
$this->searchResultsDataFactory->expects($this->once())->method('create')->will($this->returnValue($searchResult));
$searchResult->expects($this->once())->method('setSearchCriteria');
$filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
$searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock]));
//addFilterGroupToCollection() checks
$filterGroupMock->expects($this->any())->method('getFilters')->will($this->returnValue([$filterMock]));
$filterMock->expects($this->once())->method('getField')->will($this->returnValue('store_id'));
$filterMock->expects($this->any())->method('getConditionType')->will($this->returnValue('eq'));
$filterMock->expects($this->once())->method('getValue')->will($this->returnValue('filter_value'));
//back in getList()
$this->quoteCollectionMock->expects($this->once())->method('getSize')->willReturn($pageSize);
$searchResult->expects($this->once())->method('setTotalCount')->with($pageSize);
$sortOrderMock = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->setMethods(['getField', 'getDirection'])->disableOriginalConstructor()->getMock();
//foreach cycle
$searchCriteriaMock->expects($this->once())->method('getSortOrders')->will($this->returnValue([$sortOrderMock]));
$sortOrderMock->expects($this->once())->method('getField')->will($this->returnValue('id'));
$sortOrderMock->expects($this->once())->method('getDirection')->will($this->returnValue($direction));
$this->quoteCollectionMock->expects($this->once())->method('addOrder')->with('id', $expectedDirection);
$searchCriteriaMock->expects($this->once())->method('getCurrentPage')->will($this->returnValue(1));
$searchCriteriaMock->expects($this->once())->method('getPageSize')->will($this->returnValue(10));
$this->quoteCollectionMock->expects($this->once())->method('setCurPage')->with(1);
$this->quoteCollectionMock->expects($this->once())->method('setPageSize')->with(10);
$this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('\\Magento\\Quote\\Model\\ResourceModel\\Quote\\Collection'));
$this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]);
$searchResult->expects($this->once())->method('setItems')->with([$cartMock]);
$this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock));
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:39,代码来源:QuoteRepositoryTest.php
示例7: getList
/**
* Retrieve coupon.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\SalesRule\Api\Data\CouponSearchResultInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
/** @var \Magento\SalesRule\Model\ResourceModel\Coupon\Collection $collection */
$collection = $this->collectionFactory->create();
$couponInterfaceName = 'Magento\\SalesRule\\Api\\Data\\CouponInterface';
$this->extensionAttributesJoinProcessor->process($collection, $couponInterfaceName);
//Add filters from root filter group to the collection
/** @var FilterGroup $group */
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
}
$sortOrders = $searchCriteria->getSortOrders();
if ($sortOrders === null) {
$sortOrders = [];
}
/** @var \Magento\Framework\Api\SortOrder $sortOrder */
foreach ($sortOrders as $sortOrder) {
$field = $sortOrder->getField();
$collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$coupons = [];
/** @var \Magento\SalesRule\Model\Coupon $couponModel */
foreach ($collection->getItems() as $couponModel) {
$coupons[] = $couponModel->getData();
}
$searchResults = $this->searchResultFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$searchResults->setItems($coupons);
$searchResults->setTotalCount($collection->getSize());
return $searchResults;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:40,代码来源:CouponRepository.php
示例8: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
{
$searchResults = $this->taxRuleSearchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$fields = [];
$collection = $this->collectionFactory->create();
$this->joinProcessor->process($collection);
//Add filters from root filter group to the collection
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
foreach ($group->getFilters() as $filter) {
$fields[] = $this->translateField($filter->getField());
}
}
if ($fields) {
if (in_array('cd.customer_tax_class_id', $fields) || in_array('cd.product_tax_class_id', $fields)) {
$collection->joinCalculationData('cd');
}
}
$searchResults->setTotalCount($collection->getSize());
$sortOrders = $searchCriteria->getSortOrders();
/** @var SortOrder $sortOrder */
if ($sortOrders) {
foreach ($sortOrders as $sortOrder) {
$collection->addOrder($this->translateField($sortOrder->getField()), $sortOrder->getDirection() == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
}
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$searchResults->setItems($collection->getItems());
return $searchResults;
}
开发者ID:nja78,项目名称:magento2,代码行数:35,代码来源:TaxRuleRepository.php
示例9: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
/** @var \Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection $collection */
$collection = $this->rateFactory->create()->getCollection();
$this->joinProcessor->process($collection);
$collection->joinRegionTable();
//Add filters from root filter group to the collection
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
}
$sortOrders = $searchCriteria->getSortOrders();
/** @var SortOrder $sortOrder */
if ($sortOrders) {
foreach ($sortOrders as $sortOrder) {
$collection->addOrder($this->translateField($sortOrder->getField()), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
}
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$taxRate = [];
/** @var \Magento\Tax\Model\Calculation\Rate $taxRateModel */
foreach ($collection as $taxRateModel) {
$taxRate[] = $taxRateModel;
}
return $this->taxRateSearchResultsFactory->create()->setItems($taxRate)->setTotalCount($collection->getSize())->setSearchCriteria($searchCriteria);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:29,代码来源:RateRepository.php
示例10: getSamples
/**
* Get downloadable product samples
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Downloadable\Model\Resource\Sample\Collection
*/
public function getSamples($product)
{
if ($product->getDownloadableSamples() === null) {
$sampleCollection = $this->_samplesFactory->create()->addProductToFilter($product->getId())->addTitleToResult($product->getStoreId());
$this->extensionAttributesJoinProcessor->process($sampleCollection);
$product->setDownloadableSamples($sampleCollection);
}
return $product->getDownloadableSamples();
}
开发者ID:nja78,项目名称:magento2,代码行数:15,代码来源:Type.php
示例11: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
/** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection */
$collection = $this->collectionFactory->create();
$this->joinProcessor->process($collection);
/** The only possible/meaningful search criteria for attribute set is entity type code */
$entityTypeCode = $this->getEntityTypeCode($searchCriteria);
if ($entityTypeCode !== null) {
$collection->setEntityTypeFilter($this->eavConfig->getEntityType($entityTypeCode)->getId());
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$searchResults->setItems($collection->getItems());
$searchResults->setTotalCount($collection->getSize());
return $searchResults;
}
开发者ID:tingyeeh,项目名称:magento2,代码行数:21,代码来源:AttributeSetRepository.php
示例12: _fetchAll
/**
* Fetch collection data
*
* @param Select $select
* @return array
*/
protected function _fetchAll(Select $select)
{
$data = $this->_fetchStrategy->fetchAll($select, $this->_bindParams);
if ($this->extensionAttributesJoinProcessor) {
foreach ($data as $key => $dataItem) {
$data[$key] = $this->extensionAttributesJoinProcessor->extractExtensionAttributes($this->_itemObjectClass, $dataItem);
}
}
return $data;
}
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:16,代码来源:AbstractDb.php
示例13: getProductOptions
/**
* @param int $productId
* @param int $storeId
* @param bool $requiredOnly
* @return \Magento\Catalog\Api\Data\ProductCustomOptionInterface[]
*/
public function getProductOptions($productId, $storeId, $requiredOnly = false)
{
$collection = $this->addFieldToFilter('cpe.entity_id', $productId)->addTitleToResult($storeId)->addPriceToResult($storeId)->setOrder('sort_order', 'asc')->setOrder('title', 'asc');
if ($requiredOnly) {
$collection->addRequiredFilter();
}
$collection->addValuesToResult($storeId);
$this->joinProcessor->process($collection);
return $collection->getItems();
}
开发者ID:koliaGI,项目名称:magento2,代码行数:16,代码来源:Collection.php
示例14: getList
/**
* {@inheritdoc}
*/
public function getList($entityTypeCode, \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
if (!$entityTypeCode) {
throw InputException::requiredField('entity_type_code');
}
/** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection */
$attributeCollection = $this->attributeCollectionFactory->create();
$this->joinProcessor->process($attributeCollection);
$attributeCollection->addFieldToFilter('entity_type_code', ['eq' => $entityTypeCode]);
$attributeCollection->join(['entity_type' => $attributeCollection->getTable('eav_entity_type')], 'main_table.entity_type_id = entity_type.entity_type_id', []);
$attributeCollection->joinLeft(['eav_entity_attribute' => $attributeCollection->getTable('eav_entity_attribute')], 'main_table.attribute_id = eav_entity_attribute.attribute_id', []);
$entityType = $this->eavConfig->getEntityType($entityTypeCode);
$additionalTable = $entityType->getAdditionalAttributeTable();
if ($additionalTable) {
$attributeCollection->join(['additional_table' => $attributeCollection->getTable($additionalTable)], 'main_table.attribute_id = additional_table.attribute_id', []);
}
//Add filters from root filter group to the collection
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $attributeCollection);
}
/** @var SortOrder $sortOrder */
foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
$attributeCollection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
}
$totalCount = $attributeCollection->getSize();
// Group attributes by id to prevent duplicates with different attribute sets
$attributeCollection->addAttributeGrouping();
$attributeCollection->setCurPage($searchCriteria->getCurrentPage());
$attributeCollection->setPageSize($searchCriteria->getPageSize());
$attributes = [];
/** @var \Magento\Eav\Api\Data\AttributeInterface $attribute */
foreach ($attributeCollection as $attribute) {
$attributes[] = $this->get($entityTypeCode, $attribute->getAttributeCode());
}
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$searchResults->setItems($attributes);
$searchResults->setTotalCount($totalCount);
return $searchResults;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:43,代码来源:AttributeRepository.php
示例15: load
/**
* @param ProductInterface $product
* @return OptionInterface[]
*/
public function load(ProductInterface $product)
{
$options = [];
/** @var Configurable $typeInstance */
$typeInstance = $product->getTypeInstance();
$attributeCollection = $typeInstance->getConfigurableAttributeCollection($product);
$this->extensionAttributesJoinProcessor->process($attributeCollection);
foreach ($attributeCollection as $attribute) {
$values = [];
$attributeOptions = $attribute->getOptions();
if (is_array($attributeOptions)) {
foreach ($attributeOptions as $option) {
/** @var \Magento\ConfigurableProduct\Api\Data\OptionValueInterface $value */
$value = $this->optionValueFactory->create();
$value->setValueIndex($option['value_index']);
$values[] = $value;
}
}
$attribute->setValues($values);
$options[] = $attribute;
}
return $options;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:27,代码来源:Loader.php
示例16: getList
/**
* Find entities by criteria
*
* @param \Magento\Framework\Api\SearchCriteria $searchCriteria
* @return \Magento\Sales\Api\Data\ShipmentItemInterface[]
*/
public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
{
$collection = $this->shipmentItemInterfaceSearchResultFactory->create();
$this->extensionAttributesJoinProcessor->process($collection);
foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
foreach ($filterGroup->getFilters() as $filter) {
$condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
$collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
}
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
return $collection;
}
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:20,代码来源:Repository.php
示例17: getList
/**
* {@inheritdoc}
*
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface[] Array of checkout agreement data objects.
*/
public function getList()
{
if (!$this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) {
return [];
}
$storeId = $this->storeManager->getStore()->getId();
/** @var $agreementCollection AgreementCollection */
$agreementCollection = $this->collectionFactory->create();
$this->extensionAttributesJoinProcessor->process($agreementCollection);
$agreementCollection->addStoreFilter($storeId);
$agreementCollection->addFieldToFilter('is_active', 1);
$agreementDataObjects = [];
foreach ($agreementCollection as $agreement) {
$agreementDataObjects[] = $agreement;
}
return $agreementDataObjects;
}
开发者ID:nja78,项目名称:magento2,代码行数:22,代码来源:CheckoutAgreementsRepository.php
示例18: testGetList
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetList()
{
$sortOrder = $this->getMock('Magento\\Framework\\Api\\SortOrder', [], [], '', false);
$filterGroup = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
$filter = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
$collection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection', [], [], '', false);
$searchResults = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressSearchResultsInterface', [], '', false);
$searchCriteria = $this->getMockForAbstractClass('Magento\\Framework\\Api\\SearchCriteriaInterface', [], '', false);
$customerModel = $this->getMock('Magento\\Customer\\Model\\Customer', ['getId', 'setId', 'setStoreId', 'getStoreId', 'getAttributeSetId', 'setAttributeSetId', 'setRpToken', 'setRpTokenCreatedAt', 'getDataModel', 'setPasswordHash', 'getCollection'], [], 'customerModel', false);
$metadata = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface', [], '', false);
$this->searchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults);
$searchResults->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
$this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel);
$customerModel->expects($this->once())->method('getCollection')->willReturn($collection);
$this->extensionAttributesJoinProcessor->expects($this->once())->method('process')->with($collection, 'Magento\\Customer\\Api\\Data\\CustomerInterface');
$this->customerMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([$metadata]);
$metadata->expects($this->once())->method('getAttributeCode')->willReturn('attribute-code');
$collection->expects($this->once())->method('addAttributeToSelect')->with('attribute-code');
$collection->expects($this->once())->method('addNameToSelect');
$collection->expects($this->at(2))->method('joinAttribute')->with('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')->willReturnSelf();
$collection->expects($this->at(3))->method('joinAttribute')->with('billing_city', 'customer_address/city', 'default_billing', null, 'left')->willReturnSelf();
$collection->expects($this->at(4))->method('joinAttribute')->with('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')->willReturnSelf();
$collection->expects($this->at(5))->method('joinAttribute')->with('billing_region', 'customer_address/region', 'default_billing', null, 'left')->willReturnSelf();
$collection->expects($this->at(6))->method('joinAttribute')->with('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')->willReturnSelf();
$collection->expects($this->at(7))->method('joinAttribute')->with('company', 'customer_address/company', 'default_billing', null, 'left')->willReturnSelf();
$searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
$collection->expects($this->once())->method('addFieldToFilter')->with([['attribute' => 'Field', 'eq' => 'Value']], []);
$filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
$filter->expects($this->once())->method('getConditionType')->willReturn(false);
$filter->expects($this->once())->method('getField')->willReturn('Field');
$filter->expects($this->atLeastOnce())->method('getValue')->willReturn('Value');
$collection->expects($this->once())->method('addOrder')->with('Field', 'ASC');
$searchCriteria->expects($this->atLeastOnce())->method('getSortOrders')->willReturn([$sortOrder]);
$sortOrder->expects($this->once())->method('getField')->willReturn('Field');
$sortOrder->expects($this->once())->method('getDirection')->willReturn(\Magento\Framework\Api\SortOrder::SORT_ASC);
$searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn(1);
$collection->expects($this->once())->method('setCurPage')->with(1);
$searchCriteria->expects($this->once())->method('getPageSize')->willReturn(10);
$collection->expects($this->once())->method('setPageSize')->with(10);
$collection->expects($this->once())->method('getSize')->willReturn(23);
$searchResults->expects($this->once())->method('setTotalCount')->with(23);
$collection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$customerModel]));
$customerModel->expects($this->atLeastOnce())->method('getDataModel')->willReturn($this->customer);
$searchResults->expects($this->once())->method('setItems')->with([$this->customer]);
$this->assertSame($searchResults, $this->model->getList($searchCriteria));
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:49,代码来源:CustomerRepositoryTest.php
示例19: getList
/**
* {@inheritdoc}
*/
public function getList(SearchCriteriaInterface $searchCriteria)
{
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
/** @var \Magento\Customer\Model\Resource\Group\Collection $collection */
$collection = $this->groupFactory->create()->getCollection();
$groupInterfaceName = 'Magento\\Customer\\Api\\Data\\GroupInterface';
$this->extensionAttributesJoinProcessor->process($collection, $groupInterfaceName);
$collection->addTaxClass();
//Add filters from root filter group to the collection
/** @var FilterGroup $group */
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
}
$sortOrders = $searchCriteria->getSortOrders();
/** @var \Magento\Framework\Api\SortOrder $sortOrder */
if ($sortOrders) {
foreach ($searchCriteria->getSortOrders() as $sortOrder) {
$field = $this->translateField($sortOrder->getField());
$collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
}
} else {
// set a default sorting order since this method is used constantly in many
// different blocks
$field = $this->translateField('id');
$collection->addOrder($field, 'ASC');
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
/** @var \Magento\Customer\Api\Data\GroupInterface[] $groups */
$groups = [];
/** @var \Magento\Customer\Model\Group $group */
foreach ($collection as $group) {
/** @var \Magento\Customer\Api\Data\GroupInterface $groupDataObject */
$groupDataObject = $this->groupDataFactory->create()->setId($group->getId())->setCode($group->getCode())->setTaxClassId($group->getTaxClassId())->setTaxClassName($group->getTaxClassName());
$data = $group->getData();
$data = $this->extensionAttributesJoinProcessor->extractExtensionAttributes($groupInterfaceName, $data);
if (isset($data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]) && $data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY] instanceof GroupExtensionInterface) {
$groupDataObject->setExtensionAttributes($data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
}
$groups[] = $groupDataObject;
}
$searchResults->setTotalCount($collection->getSize());
return $searchResults->setItems($groups);
}
开发者ID:nja78,项目名称:magento2,代码行数:48,代码来源:GroupRepository.php
示例20: testGetListWithoutSortOrder
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetListWithoutSortOrder()
{
$groupId = 86;
$groupExtension = $this->getMock('Magento\\Customer\\Api\\Data\\GroupExtensionInterface', [], [], '', false);
$filterGroup = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
$filter = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
$collection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Group\\Collection', [], [], '', false);
$searchCriteria = $this->getMockForAbstractClass('Magento\\Framework\\Api\\SearchCriteriaInterface', [], '', false);
$searchResults = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressSearchResultsInterface', [], '', false);
$this->searchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults);
$searchResults->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
$this->groupFactory->expects($this->once())->method('create')->willReturn($this->groupModel);
$this->groupModel->expects($this->once())->method('getCollection')->willReturn($collection);
$this->extensionAttributesJoinProcessor->expects($this->once())->method('process')->with($collection, 'Magento\\Customer\\Api\\Data\\GroupInterface');
$collection->expects($this->once())->method('addTaxClass');
$searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
$filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
$filter->expects($this->once())->method('getConditionType')->willReturn(false);
$filter->expects($this->once())->method('getField')->willReturn('Field');
$filter->expects($this->atLeastOnce())->method('getValue')->willReturn('Value');
$collection->expects($this->once())->method('addFieldToFilter')->with(['Field'], [['eq' => 'Value']]);
$searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn(1);
$collection->expects($this->once())->method('setCurPage')->with(1);
$searchCriteria->expects($this->once())->method('getPageSize')->willReturn(10);
$collection->expects($this->once())->method('setPageSize')->with(10);
$collection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$this->groupModel]));
$this->groupDataFactory->expects($this->once())->method('create')->willReturn($this->group);
$this->group->expects($this->once())->method('setId')->with($groupId)->willReturnSelf();
$this->group->expects($this->once())->method('setCode')->with('Code')->willReturnSelf();
$this->group->expects($this->once())->method('setTaxClassId')->with(234)->willReturnSelf();
$this->group->expects($this->once())->method('setTaxClassName')->with('Tax class name')->willReturnSelf();
$this->groupModel->expects($this->atLeastOnce())->method('getId')->willReturn($groupId);
$this->groupModel->expects($this->atLeastOnce())->method('getCode')->willReturn('Code');
$this->groupModel->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(234);
$this->groupModel->expects($this->atLeastOnce())->method('getTaxClassName')->willReturn('Tax class name');
$this->groupModel->expects($this->once())->method('getData')->willReturn([]);
$this->extensionAttributesJoinProcessor->expects($this->once())->method('extractExtensionAttributes')->with('Magento\\Customer\\Api\\Data\\GroupInterface', [])->willReturn(['extension_attributes' => $groupExtension]);
$this->group->expects($this->once())->method('setExtensionAttributes')->with($groupExtension);
$collection->expects($this->once())->method('getSize')->willReturn(9);
$searchResults->expects($this->once())->method('setTotalCount')->with(9);
$searchResults->expects($this->once())->method('setItems')->with([$this->group])->willReturnSelf();
$collection->expects($this->once())->method('addOrder')->with('customer_group_id', 'ASC');
$this->assertSame($searchResults, $this->model->getList($searchCriteria));
}
开发者ID:Doability,项目名称:magento2dev,代码行数:47,代码来源:GroupRepositoryTest.php
注:本文中的Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论