本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\ProductInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface类的具体用法?PHP ProductInterface怎么用?PHP ProductInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProductInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_hydrates_a_result_record(Builder $builder, Query $query, ProductInterface $product, Association $association, AssociationType $associationType, ProductInterface $associatedProduct1, ProductInterface $associatedProduct2, DocumentManager $documentManager, \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $metadata, Collection $collection, ArrayIterator $arrayIterator)
{
$options = ['locale_code' => 'en_US', 'scope_code' => 'print', 'current_group_id' => null, 'attributes_configuration' => [], 'association_type_id' => 1, 'current_product' => $product];
$builder->getQuery()->willReturn($query);
$builder->hydrate(false)->willReturn($builder);
$associatedProduct1->getId()->willReturn('550ae6b98ead0ed7778b46bb');
$associatedProduct2->getId()->willReturn('550ae6b98abd0ec8778b46bb');
$product->getAssociations()->willReturn([$association]);
$association->getAssociationType()->willReturn($associationType);
$associationType->getId()->willReturn(1);
$association->getProducts()->willReturn([$associatedProduct1, $associatedProduct2]);
$queryDefinition = ['type' => 1, 'sort' => ['normalizedData.is_associated' => -1, '_id' => 1], 'limit' => 10, 'skip' => 0, 'query' => ['_id' => ['$ne' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb'])]], 'newObj' => []];
$query->getQuery()->willReturn($queryDefinition);
$query->getDocumentManager()->willReturn($documentManager);
$documentManager->getDocumentCollection(Argument::any())->willReturn($collection);
$documentManager->getClassMetadata(Argument::any())->willReturn($metadata);
$metadata->getFieldNames()->willReturn(['id', 'created', 'updated', 'locale', 'scope', 'values', 'indexedValues', 'indexedValuesOutdated', 'family', 'familyId', 'categories', 'categoryIds', 'enabled', 'groups', 'groupIds', 'associations', 'completenesses', 'normalizedData']);
$pipeline = [['$match' => ['_id' => ['$ne' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb'])]]], ['$project' => ['id' => 1, 'created' => 1, 'updated' => 1, 'locale' => 1, 'scope' => 1, 'values' => 1, 'indexedValues' => 1, 'indexedValuesOutdated' => 1, 'family' => 1, 'familyId' => 1, 'categories' => 1, 'categoryIds' => 1, 'enabled' => 1, 'groups' => 1, 'groupIds' => 1, 'associations' => 1, 'completenesses' => 1, 'normalizedData' => 1, 'is_associated' => ['$cond' => [['$or' => [['$eq' => ['$_id', \MongoId::__set_state(['$id' => '550ae6b98ead0ed7778b46bb'])]], ['$eq' => ['$_id', \MongoId::__set_state(['$id' => '550ae6b98abd0ec8778b46bb'])]]]], 1, 0]]]], ['$sort' => ['is_associated' => -1]], ['$skip' => 0], ['$limit' => 10]];
$collection->aggregate($pipeline)->willReturn($arrayIterator);
$fixture = ['_id' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb']), 'normalizedData' => [], 'sku' => ['attribute' => ['code' => 'sku', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => null, 'scope' => null, 'value' => 'mysku'], 'name' => ['attribute' => ['code' => 'name', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => null], 'desc' => ['attribute' => ['code' => 'desc', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => 'print'], 'is_associated' => 1];
$arrayIterator->toArray()->willReturn([$fixture]);
$rows = $this->hydrate($builder, $options);
$rows->shouldHaveCount(1);
$firstResult = $rows[0];
$firstResult->shouldBeAnInstanceOf('\\Oro\\Bundle\\DataGridBundle\\Datasource\\ResultRecord');
}
示例2:
function it_adds_product_value(ProductInterface $product, AttributeInterface $size)
{
$size->isLocalizable()->willReturn(false);
$size->isScopable()->willReturn(false);
$product->addValue(Argument::any())->shouldBeCalled();
$this->addProductValue($product, $size);
}
示例3:
function it_converts_metric_values_given_the_configured_base_unit_in_the_channel($converter, ProductValueInterface $weightValue, ProductValueInterface $surfaceValue, ProductValueInterface $nameValue, AttributeInterface $weight, AttributeInterface $surface, AttributeInterface $name, MetricInterface $weightMetric, MetricInterface $surfaceMetric, ProductInterface $product, ChannelInterface $channel)
{
$weightValue->getAttribute()->willReturn($weight);
$weightValue->getData()->willReturn($weightMetric);
$weight->getCode()->willReturn('weight');
$weightMetric->getFamily()->willReturn('Weight');
$weightMetric->getUnit()->willReturn('KILOGRAM');
$weightMetric->getData()->willReturn(1);
$surfaceValue->getAttribute()->willReturn($surface);
$surfaceValue->getData()->willReturn($surfaceMetric);
$surface->getCode()->willReturn('surface');
$surfaceMetric->getFamily()->willReturn('Surface');
$surfaceMetric->getUnit()->willReturn('METER_SQUARE');
$surfaceMetric->getData()->willReturn(10);
$nameValue->getAttribute()->willReturn($name);
$nameValue->getData()->willReturn('foobar');
$product->getValues()->willReturn(array($weightValue, $surfaceValue, $nameValue));
$channel->getConversionUnits()->willReturn(array('weight' => 'GRAM'));
$converter->setFamily('Weight')->shouldBeCalled();
$converter->convert('KILOGRAM', 'GRAM', 1)->willReturn(0.001);
$converter->setFamily('Surface')->shouldNotBeCalled();
$weightMetric->setData(0.001)->shouldBeCalled();
$weightMetric->setUnit('GRAM')->shouldBeCalled();
$this->convert($product, $channel);
}
示例4:
function it_provide_product_completeness_if_family_is_not_defined(ProductInterface $product, ChannelInterface $mobile, LocaleInterface $en, FamilyInterface $shirt)
{
$product->getFamily()->willReturn(null);
$en->getCode()->willReturn('en_US');
$mobile->getCode()->willReturn('mobile');
$this->getProductCompleteness($product, [$mobile], [$en], 'en_US')->shouldReturn(['en_US' => ['channels' => ['mobile' => ['completeness' => null, 'missing' => []]], 'stats' => ['total' => 0, 'complete' => 0]]]);
}
示例5:
function it_massively_insert_new_products_and_update_existing_products($documentManager, $collection, $normalizer, $mongoFactory, $pendingPersister, $eventDispatcher, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4)
{
$mongoFactory->createMongoId()->willReturn('my_mongo_id');
$product1->getId()->willReturn("my_product_1");
$product2->getId()->willReturn(null);
$product3->getId()->willReturn("my_product_3");
$product4->getId()->willReturn(null);
$product1->setId(Argument::any())->shouldNotBeCalled();
$product2->setId('my_mongo_id')->shouldBeCalled();
$product3->setId(Argument::any())->shouldNotBeCalled();
$product4->setId('my_mongo_id')->shouldBeCalled();
$normalizer->normalize($product1, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_1', 'normalized_product_1']);
$normalizer->normalize($product2, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_2']);
$normalizer->normalize($product3, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_3', 'normalized_product_3']);
$normalizer->normalize($product4, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_4']);
$collection->batchInsert([['_id' => 'my_mongo_id', 'normalized_product_2'], ['_id' => 'my_mongo_id', 'normalized_product_4']])->shouldBeCalled();
$collection->update(['_id' => 'my_product_1'], ['_id' => 'my_product_1', 'normalized_product_1'])->shouldBeCalled();
$collection->update(['_id' => 'my_product_3'], ['_id' => 'my_product_3', 'normalized_product_3'])->shouldBeCalled();
$pendingPersister->persistPendingVersions([$product1, $product2, $product3, $product4])->shouldBeCalled();
$eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_insert', Argument::any())->shouldBeCalled();
$eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_update', Argument::any())->shouldBeCalled();
$eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_insert', Argument::any())->shouldBeCalled();
$eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_update', Argument::any())->shouldBeCalled();
$documentManager->clear()->shouldBeCalled();
$this->write([$product1, $product2, $product3, $product4]);
}
示例6:
function it_normalizes_an_existing_product_into_mongodb_document($mongoFactory, $serializer, ProductInterface $product, \MongoId $mongoId, \MongoDate $mongoDate, Association $assoc1, Association $assoc2, CategoryInterface $category1, CategoryInterface $category2, GroupInterface $group1, GroupInterface $group2, ProductValueInterface $value1, ProductValueInterface $value2, FamilyInterface $family)
{
$mongoFactory->createMongoId('product1')->willReturn($mongoId);
$mongoFactory->createMongoDate()->willReturn($mongoDate);
$family->getId()->willReturn(36);
$category1->getId()->willReturn(12);
$category2->getId()->willReturn(34);
$group1->getId()->willReturn(56);
$group2->getId()->willReturn(78);
$product->getId()->willReturn('product1');
$product->getCreated()->willReturn(null);
$product->getFamily()->willReturn($family);
$product->isEnabled()->willReturn(true);
$product->getGroups()->willReturn([$group1, $group2]);
$product->getCategories()->willReturn([$category1, $category2]);
$product->getAssociations()->willReturn([$assoc1, $assoc2]);
$product->getValues()->willReturn([$value1, $value2]);
$context = ['_id' => $mongoId];
$serializer->normalize($product, 'mongodb_json')->willReturn(['data' => 'data', 'completenesses' => 'completenesses']);
$serializer->normalize($value1, 'mongodb_document', $context)->willReturn('my_value_1');
$serializer->normalize($value2, 'mongodb_document', $context)->willReturn('my_value_2');
$serializer->normalize($assoc1, 'mongodb_document', $context)->willReturn('my_assoc_1');
$serializer->normalize($assoc2, 'mongodb_document', $context)->willReturn('my_assoc_2');
$this->normalize($product, 'mongodb_document')->shouldReturn(['_id' => $mongoId, 'created' => $mongoDate, 'updated' => $mongoDate, 'family' => 36, 'enabled' => true, 'groupIds' => [56, 78], 'categoryIds' => [12, 34], 'associations' => ['my_assoc_1', 'my_assoc_2'], 'values' => ['my_value_1', 'my_value_2'], 'normalizedData' => ['data' => 'data'], 'completenesses' => []]);
}
示例7:
function it_allows_setting_option_to_null(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
{
$attribute->getCode()->willReturn('choice');
$product->getValue('choice', null, null)->shouldBeCalled()->willReturn($value);
$value->setOption(null)->shouldBeCalled();
$this->setValue([$product], $attribute, null);
}
示例8: foreach
function it_copies_a_price_collection_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, ProductPriceInterface $price)
{
$fromLocale = 'fr_FR';
$toLocale = 'fr_FR';
$toScope = 'mobile';
$fromScope = 'mobile';
$fromAttribute->getCode()->willReturn('fromAttributeCode');
$toAttribute->getCode()->willReturn('toAttributeCode');
$attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled();
$attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled();
$fromProductValue->getData()->willReturn([$price]);
$price->getCurrency()->willReturn('USD');
$price->getData()->willReturn(123);
$product1->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product1->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$product2->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn(null);
$product2->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$product3->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product3->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null);
$product4->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product4->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue);
$builder->addPriceForCurrencyWithData($toProductValue, 'USD', 123)->shouldBeCalled();
$products = [$product1, $product2, $product3, $product4];
foreach ($products as $product) {
$this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]);
}
}
示例9:
function it_allows_setting_attribute_data_option_to_null(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
{
$attribute->getCode()->willReturn('choice');
$product->getValue('choice', 'fr_FR', 'mobile')->shouldBeCalled()->willReturn($value);
$value->setOption(null)->shouldBeCalled();
$this->setAttributeData($product, $attribute, null, ['locale' => 'fr_FR', 'scope' => 'mobile']);
}
示例10: getProductCountByTree
/**
* {@inheritdoc}
*/
public function getProductCountByTree(ProductInterface $product)
{
$categories = $product->getCategories();
$categoryIds = array();
foreach ($categories as $category) {
$categoryIds[] = $category->getId();
}
$categoryRepository = $this->entityManager->getRepository($this->categoryClass);
$categoryTable = $this->entityManager->getClassMetadata($this->categoryClass)->getTableName();
$categoryIds = implode(',', $categoryIds);
if (!empty($categoryIds)) {
$sql = "SELECT" . " tree.id AS tree_id," . " COUNT(category.id) AS product_count" . " FROM {$categoryTable} tree" . " LEFT JOIN {$categoryTable} category" . " ON category.root = tree.id" . " AND category.id IN ({$categoryIds})" . " WHERE tree.parent_id IS NULL" . " GROUP BY tree.id";
} else {
$sql = "SELECT" . " tree.id AS tree_id," . " '0' AS product_count" . " FROM {$categoryTable} tree" . " LEFT JOIN {$categoryTable} category" . " ON category.root = tree.id" . " WHERE tree.parent_id IS NULL" . " GROUP BY tree.id";
}
$stmt = $this->entityManager->getConnection()->prepare($sql);
$stmt->execute();
$productCounts = $stmt->fetchAll();
$trees = array();
foreach ($productCounts as $productCount) {
$tree = array();
$tree['productCount'] = $productCount['product_count'];
$tree['tree'] = $categoryRepository->find($productCount['tree_id']);
$trees[] = $tree;
}
return $trees;
}
示例11: foreach
function it_copies_multi_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, AttributeOptionInterface $attributeOption)
{
$fromLocale = 'fr_FR';
$toLocale = 'fr_FR';
$toScope = 'mobile';
$fromScope = 'mobile';
$fromAttribute->getCode()->willReturn('fromAttributeCode');
$toAttribute->getCode()->willReturn('toAttributeCode');
$attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled();
$attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled();
$fromProductValue->getOptions()->willReturn([$attributeOption])->shouldBeCalled(3);
$toProductValue->getOptions()->willReturn([$attributeOption]);
$toProductValue->removeOption($attributeOption)->shouldBeCalled();
$toProductValue->addOption($attributeOption)->shouldBeCalled();
$product1->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product1->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$product2->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn(null);
$product2->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$product3->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product3->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null);
$product4->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product4->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue);
$products = [$product1, $product2, $product3, $product4];
foreach ($products as $product) {
$this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]);
}
}
示例12: addValues
/**
* @param ProductManager $manager the product manager
* @param ProductInterface $product the entity
* @param array $attributes the attributes
*/
protected function addValues(ProductManager $manager, ProductInterface $product, $attributes)
{
foreach ($attributes as $attribute) {
$value = $manager->createProductValue();
$value->setAttribute($attribute);
$product->addValue($value);
}
}
示例13: setMedia
/**
* Set media in the product value
*
* @param ProductInterface $product
* @param AttributeInterface $attribute
* @param FileInfoInterface|null $fileInfo
* @param string|null $locale
* @param string|null $scope
*/
protected function setMedia(ProductInterface $product, AttributeInterface $attribute, FileInfoInterface $fileInfo = null, $locale = null, $scope = null)
{
$value = $product->getValue($attribute->getCode(), $locale, $scope);
if (null === $value) {
$value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
}
$value->setMedia($fileInfo);
}
示例14: setData
/**
* Set data into product value
*
* @param ProductInterface $product
* @param AttributeInterface $attribute
* @param mixed $data
* @param string $locale
* @param string $scope
*/
protected function setData(ProductInterface $product, AttributeInterface $attribute, $data, $locale, $scope)
{
$value = $product->getValue($attribute->getCode(), $locale, $scope);
if (null === $value) {
$value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
}
$value->setData($data);
}
示例15:
function it_fails_if_one_of_the_associated_group_does_not_exist($productBuilder, $groupRepository, ProductInterface $product, AssociationInterface $xsellAssociation)
{
$product->getAssociations()->willReturn([$xsellAssociation]);
$productBuilder->addMissingAssociations($product)->shouldBeCalled();
$product->getAssociationForTypeCode('xsell')->willReturn($xsellAssociation);
$groupRepository->findOneByIdentifier('not existing group')->willReturn(null);
$this->shouldThrow(InvalidArgumentException::expected('associations', 'existing group code', 'adder', 'association', 'not existing group'))->during('addFieldData', [$product, 'associations', ['xsell' => ['groups' => ['not existing group'], 'products' => []]]]);
}