本文整理汇总了PHP中Magento\Catalog\Model\Product::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getId方法的具体用法?PHP Product::getId怎么用?PHP Product::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetJsonConfig
public function testGetJsonConfig()
{
$config = (array) json_decode($this->_block->getJsonConfig());
$this->assertNotEmpty($config);
$this->assertArrayHasKey('productId', $config);
$this->assertEquals($this->_product->getId(), $config['productId']);
}
示例2: testReindexFull
/**
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/CatalogRule/_files/attribute.php
* @magentoDataFixture Magento/CatalogRule/_files/rule_by_attribute.php
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testReindexFull()
{
$this->prepareProducts();
$this->indexerBuilder->reindexFull();
$this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->product->getId()));
$this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productSecond->getId()));
$this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productThird->getId()));
}
示例3: testGetAddToWishlistParams
public function testGetAddToWishlistParams()
{
$json = $this->block->getAddToWishlistParams($this->product);
$params = (array) json_decode($json);
$data = (array) $params['data'];
$this->assertEquals($this->product->getId(), $data['product']);
$this->assertArrayHasKey('uenc', $data);
$this->assertStringEndsWith('wishlist/index/add/', $params['action']);
}
示例4: getUrl
/**
* The only rewritten line in this method is the return statement
*/
public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
{
$routePath = '';
$routeParams = $params;
$storeId = $product->getStoreId();
$categoryId = null;
if (!isset($params['_ignore_category']) && $product->getCategoryId() && !$product->getDoNotUseCategoryId()) {
$categoryId = $product->getCategoryId();
}
if ($product->hasUrlDataObject()) {
$requestPath = $product->getUrlDataObject()->getUrlRewrite();
$routeParams['_scope'] = $product->getUrlDataObject()->getStoreId();
} else {
$requestPath = $product->getRequestPath();
if (empty($requestPath) && $requestPath !== false) {
$filterData = [UrlRewrite::ENTITY_ID => $product->getId(), UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE, UrlRewrite::STORE_ID => $storeId];
if ($categoryId) {
$filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;
}
$rewrite = $this->urlFinder->findOneByData($filterData);
if ($rewrite) {
$requestPath = $rewrite->getRequestPath();
$product->setRequestPath($requestPath);
} else {
$product->setRequestPath(false);
}
}
}
if (isset($routeParams['_scope'])) {
$storeId = $this->storeManager->getStore($routeParams['_scope'])->getId();
}
if ($storeId != $this->storeManager->getStore()->getId()) {
$routeParams['_scope_to_url'] = true;
}
if (!empty($requestPath)) {
$routeParams['_direct'] = $requestPath;
} else {
$routePath = 'catalog/product/view';
$routeParams['id'] = $product->getId();
$routeParams['s'] = $product->getUrlKey();
if ($categoryId) {
$routeParams['category'] = $categoryId;
}
}
// reset cached URL instance GET query params
if (!isset($routeParams['_query'])) {
$routeParams['_query'] = [];
}
/*
* This is the only line changed from the default method.
* For reference, the original line: $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
* getUrlInstance() is a private method, so a new method has been written that will create a frontend Url object if
* the store scope is not the admin scope.
*/
return $this->getStoreScopeUrlInstance($storeId)->getUrl($routePath, $routeParams);
}
示例5: beforeProcess
public function beforeProcess()
{
$product = $this->getEvent()->getProduct();
if (!$product instanceof \Magento\Catalog\Model\Product) {
throw new \Ess\M2ePro\Model\Exception('Product event doesn\'t have correct Product instance.');
}
$this->product = $product;
$this->productId = (int) $this->product->getId();
$this->storeId = (int) $this->product->getData('store_id');
}
示例6: getProductAttribute
/**
* Return Product attribute by attribute's ID
*
* @param \Magento\Catalog\Model\Product $product
* @param int $attributeId
* @return null|\Magento\Catalog\Model\Entity\Attribute Product's attribute
*/
public function getProductAttribute(\Magento\Catalog\Model\Product $product, $attributeId)
{
if (!isset($this->_productAttributes[$product->getId()])) {
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
$this->_productAttributes[$product->getId()][$attribute->getAttributeId()] = $attribute;
}
}
return isset($this->_productAttributes[$product->getId()][$attributeId]) ? $this->_productAttributes[$product->getId()][$attributeId] : null;
}
示例7: testGetProduct
public function testGetProduct()
{
$this->assertNotEmpty($this->_block->getProduct()->getId());
$this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId());
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get('Magento\\Framework\\Registry')->unregister('product');
$this->_block->setProductId(1);
$this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId());
}
示例8: testGenerateSimpleProductsWithPartialData
/**
* @param array $productsData
* @dataProvider generateSimpleProductsWithPartialDataDataProvider
* @magentoDbIsolation enabled
*/
public function testGenerateSimpleProductsWithPartialData($productsData)
{
$this->_product->setNewVariationsAttributeSetId(4);
$generatedProducts = $this->_model->generateSimpleProducts($this->_product, $productsData);
$parentStockItem = $this->stockRegistry->getStockItem($this->_product->getId());
foreach ($generatedProducts as $productId) {
$stockItem = $this->stockRegistry->getStockItem($productId);
$this->assertEquals($parentStockItem->getManageStock(), $stockItem->getManageStock());
$this->assertEquals('1', $stockItem->getIsInStock());
}
}
示例9: testReindexRowAfterDelete
/**
* @depends testReindexRowAfterMassAction
* @magentoAppArea adminhtml
*/
public function testReindexRowAfterDelete()
{
$this->productSecond->delete();
$products = $this->search('Simple Product Common');
$this->assertCount(1, $products);
$this->assertEquals($this->productFirst->getId(), $products[0]->getId());
}
示例10: loadProductGalleryByAttributeId
/**
* @param Product $product
* @param int $attributeId
* @return array
*/
public function loadProductGalleryByAttributeId($product, $attributeId)
{
$select = $this->createBaseLoadSelect($product->getId(), $product->getStoreId(), $attributeId);
$result = $this->getConnection()->fetchAll($select);
$this->_removeDuplicates($result);
return $result;
}
示例11: copy
/**
* Create product duplicate
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
*/
public function copy(\Magento\Catalog\Model\Product $product)
{
$product->getWebsiteIds();
$product->getCategoryIds();
$duplicate = $this->productFactory->create();
$duplicate->setData($product->getData());
$duplicate->setIsDuplicate(true);
$duplicate->setOriginalId($product->getId());
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
$duplicate->setCreatedAt(null);
$duplicate->setUpdatedAt(null);
$duplicate->setId(null);
$duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
$this->copyConstructor->build($product, $duplicate);
$isDuplicateSaved = false;
do {
$urlKey = $duplicate->getUrlKey();
$urlKey = preg_match('/(.*)-(\\d+)$/', $urlKey, $matches) ? $matches[1] . '-' . ($matches[2] + 1) : $urlKey . '-1';
$duplicate->setUrlKey($urlKey);
try {
$duplicate->save();
$isDuplicateSaved = true;
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
}
} while (!$isDuplicateSaved);
$product->getOptionInstance()->duplicate($product->getId(), $duplicate->getId());
$product->getResource()->duplicate($product->getId(), $duplicate->getId());
return $duplicate;
}
示例12: afterGetIdentities
/**
* @param CatalogProduct $product
* @param array $identities
* @return string[]
*/
public function afterGetIdentities(CatalogProduct $product, array $identities)
{
foreach ($this->type->getParentIdsByChild($product->getId()) as $parentId) {
$identities[] = CatalogProduct::CACHE_TAG . '_' . $parentId;
}
return $identities;
}
示例13: setProduct
/**
* @param \Magento\Catalog\Model\Product $productModel
* @return \Ess\M2ePro\Model\Magento\Product
*/
public function setProduct(\Magento\Catalog\Model\Product $productModel)
{
$this->_productModel = $productModel;
$this->setProductId($this->_productModel->getId());
$this->setStoreId($this->_productModel->getStoreId());
return $this;
}
示例14: deleteProduct
public function deleteProduct(\Magento\Catalog\Model\Product $product, $deletingMode)
{
if ($deletingMode == \Ess\M2ePro\Model\Listing::DELETING_MODE_NONE) {
return;
}
$listingsProducts = $this->getListing()->getProducts(true, array('product_id' => (int) $product->getId()));
if (count($listingsProducts) <= 0) {
return;
}
foreach ($listingsProducts as $listingProduct) {
if (!$listingProduct instanceof \Ess\M2ePro\Model\Listing\Product) {
return;
}
try {
if ($deletingMode == \Ess\M2ePro\Model\Listing::DELETING_MODE_STOP) {
$listingProduct->isStoppable() && $this->activeRecordFactory->getObject('StopQueue')->add($listingProduct);
}
if ($deletingMode == \Ess\M2ePro\Model\Listing::DELETING_MODE_STOP_REMOVE) {
$listingProduct->isStoppable() && $this->activeRecordFactory->getObject('StopQueue')->add($listingProduct);
$listingProduct->addData(array('status' => \Ess\M2ePro\Model\Listing\Product::STATUS_STOPPED))->save();
$listingProduct->delete();
}
} catch (\Exception $exception) {
}
}
}
示例15: afterSave
/**
* Apply catalog rules after product save
*
* @param Product $subject
* @param Product $result
* @return Product
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(Product $subject, Product $result)
{
if (!$result->getIsMassupdate()) {
$this->productRuleProcessor->reindexRow($result->getId());
}
return $result;
}