本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductInterface::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::setId方法的具体用法?PHP ProductInterface::setId怎么用?PHP ProductInterface::setId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Model\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::setId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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]);
}
示例2:
function it_inserts_or_updates_several_products($versionSaver, $normalizer, $collection, ProductInterface $productA, ProductInterface $productB, ProductInterface $productC, ProductInterface $productD)
{
$products = [$productA, $productB, $productC, $productD];
$productA->getId()->willReturn('id_a');
$productB->getId()->willReturn('id_b');
$productC->getId()->willReturn(null);
$productD->getId()->willReturn(null);
$productA->setId(Argument::any())->shouldNotBeCalled();
$productB->setId(Argument::any())->shouldNotBeCalled();
$productC->setId(Argument::any())->shouldBeCalled();
$productD->setId(Argument::any())->shouldBeCalled();
$normalizer->normalize($productA, Argument::cetera())->willReturn(['_id' => 'id_a', 'key_a' => 'data_a']);
$normalizer->normalize($productB, Argument::cetera())->willReturn(['_id' => 'id_b', 'key_b' => 'data_b']);
$normalizer->normalize($productC, Argument::cetera())->willReturn(['_id' => 'id_c', 'key_c' => 'data_c']);
$normalizer->normalize($productD, Argument::cetera())->willReturn(['_id' => 'id_d', 'key_d' => 'data_d']);
$collection->batchInsert([['_id' => 'id_c', 'key_c' => 'data_c'], ['_id' => 'id_d', 'key_d' => 'data_d']])->shouldBeCalled();
$collection->update(['_id' => 'id_a'], ['_id' => 'id_a', 'key_a' => 'data_a'])->shouldBeCalled();
$collection->update(['_id' => 'id_b'], ['_id' => 'id_b', 'key_b' => 'data_b'])->shouldBeCalled();
$versionSaver->saveAll(Argument::any())->shouldBeCalled();
$this->saveAll($products);
}