本文整理汇总了PHP中Mage_Catalog_Model_Product::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getId方法的具体用法?PHP Mage_Catalog_Model_Product::getId怎么用?PHP Mage_Catalog_Model_Product::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createIndexData
public function createIndexData(Mage_Catalog_Model_Product $object)
{
$searchEntityId = $object->getId();
$priceAttributeId = $this->getTierPriceAttribute()->getId();
if ($object->isGrouped()) {
$priceAttributeId = $this->getPriceAttribute()->getId();
$associated = $object->getTypeInstance()->getAssociatedProducts();
$searchEntityId = array();
foreach ($associated as $product) {
$searchEntityId[] = $product->getId();
}
}
if (!count($searchEntityId)) {
return false;
}
$result = array();
$data = array();
$data['store_id'] = $object->getStoreId();
$data['entity_id'] = $object->getId();
$search['store_id'] = $object->getStoreId();
$search['entity_id'] = $searchEntityId;
$search['attribute_id'] = $priceAttributeId;
foreach ($this->_customerGroups as $group) {
$search['customer_group_id'] = $group->getId();
$data['customer_group_id'] = $group->getId();
$value = $this->_getResource()->getMinimalValue($search);
if (is_null($value)) {
continue;
}
$data['value'] = $value;
$result[] = $data;
}
return $result;
}
示例2: purge
/**
* Purge product
*
* @param Mage_Catalog_Model_Product $product
* @param bool $purgeParentProducts
* @param bool $purgeCategories
* @return Phoenix_VarnishCache_Model_Control_Catalog_Product
*/
public function purge(Mage_Catalog_Model_Product $product, $purgeParentProducts = false, $purgeCategories = false)
{
if ($this->_canPurge()) {
$idsToPurge = array();
$categoryIdsToPurge = array();
$idsToPurge[] = $product->getId();
$this->_getSession()->addSuccess(Mage::helper('varnishcache')->__('Varnish cache for "%s" has been purged.', $product->getName()));
if ($purgeParentProducts) {
// purge parent products
$productRelationCollection = $this->_getProductRelationCollection()->filterByChildId($product->getId());
foreach ($productRelationCollection as $productRelation) {
$idsToPurge[] = $productRelation->getParentId();
}
// purge categories of parent products
if ($purgeCategories) {
$categoryProductCollection = $this->_getCategoryProductRelationCollection()->filterAllByProductIds($productRelationCollection->getAllIds());
foreach ($categoryProductCollection as $categoryProduct) {
$categoryIdsToPurge[] = $categoryProduct->getCategoryId();
}
}
}
$this->_purgeByIds($idsToPurge);
if ($purgeCategories) {
foreach ($product->getCategoryCollection() as $category) {
$categoryIdsToPurge[] = $category->getId();
}
$this->_getSession()->addSuccess(Mage::helper('varnishcache')->__('Varnish cache for the product\'s categories has been purged.'));
}
$this->_purgeCategoriesByIds($categoryIdsToPurge);
}
return $this;
}
示例3: saveProductLinks
/**
* Save Product Links process
*
* @param Mage_Catalog_Model_Product $product
* @param array $data
* @param int $typeId
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link
*/
public function saveProductLinks($product, $data, $typeId)
{
if (!is_array($data)) {
$data = array();
}
$attributes = $this->getAttributesByType($typeId);
$deleteCondition = $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()) . $this->_getWriteAdapter()->quoteInto(' AND link_type_id=?', $typeId);
$this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition);
foreach ($data as $linkedProductId => $linkInfo) {
$this->_getWriteAdapter()->insert($this->getMainTable(), array('product_id' => $product->getId(), 'linked_product_id' => $linkedProductId, 'link_type_id' => $typeId));
$linkId = $this->_getWriteAdapter()->lastInsertId();
foreach ($attributes as $attributeInfo) {
$attributeTable = $this->getAttributeTypeTable($attributeInfo['type']);
if ($attributeTable && isset($linkInfo[$attributeInfo['code']])) {
$this->_getWriteAdapter()->insert($attributeTable, array('product_link_attribute_id' => $attributeInfo['id'], 'link_id' => $linkId, 'value' => $linkInfo[$attributeInfo['code']]));
}
}
}
/**
* Grouped product relations should be added to relation table
*/
if ($typeId == Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED) {
}
return $this;
}
示例4: _calcConfigProductTierPricing
/**
* Get product final price via configurable product's tier pricing structure.
* Uses qty of parent item to determine price.
*
* @param Mage_Catalog_Model_Product $product
*
* @return float
*/
private function _calcConfigProductTierPricing($product)
{
$tierPrice = PHP_INT_MAX;
if ($items = $this->_getAllVisibleItems()) {
// map mapping the IDs of the parent products with the quantities of the corresponding simple products
$idQuantities = array();
// go through all products in the quote
foreach ($items as $item) {
/** @var Mage_Sales_Model_Quote_Item $item */
if ($item->getParentItem()) {
continue;
}
// this is the product ID of the parent!
$id = $item->getProductId();
// map the parent ID with the quantity of the simple product
$idQuantities[$id][] = $item->getQty();
}
// compute the total quantity of items of the configurable product
if (array_key_exists($product->getId(), $idQuantities)) {
$totalQty = array_sum($idQuantities[$product->getId()]);
$tierPrice = $product->getPriceModel()->getBasePrice($product, $totalQty);
}
}
return $tierPrice;
}
示例5: __construct
/**
* @param Mage_Catalog_Model_Product $product
*/
public function __construct($params)
{
$this->_product = $params['product'];
$this->_storeId = $params['store_id'];
$this->_productId = $this->_product->getId();
$product = $this->_product = Mage::getModel('catalog/product')->setStoreId($this->_storeId)->load($this->_product->getId());
$this->setData($this->_createOffer());
}
示例6: testGetProduct
public function testGetProduct()
{
$this->assertNotEmpty($this->_block->getProduct()->getId());
$this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId());
Mage::unregister('product');
$this->_block->setProductId(1);
$this->assertEquals($this->_product->getId(), $this->_block->getProduct()->getId());
}
示例7: productToXmlObject
/**
* Retrieve product attributes as xml object
*
* @param Mage_Catalog_Model_Product $product
* @param string $itemNodeName
* @return Mage_XmlConnect_Model_Simplexml_Element
*/
public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNodeName = 'item')
{
/** @var $item Mage_XmlConnect_Model_Simplexml_Element */
$item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>');
if ($product && $product->getId()) {
$item->addChild('entity_id', $product->getId());
$item->addChild('name', $item->escapeXml($product->getName()));
$item->addChild('entity_type', $product->getTypeId());
$item->addChild('short_description', $item->escapeXml($product->getShortDescription()));
$description = Mage::helper('xmlconnect')->htmlize($item->xmlentities($product->getDescription()));
$item->addChild('description', $description);
$item->addChild('link', $product->getProductUrl());
if ($itemNodeName == 'item') {
$imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small');
$propertyToResizeName = 'small_image';
} else {
$imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_big');
$propertyToResizeName = 'image';
}
$icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName)->resize($imageToResize);
$iconXml = $item->addChild('icon', $icon);
$file = Mage::helper('xmlconnect')->urlToPath($icon);
$iconXml->addAttribute('modification_time', filemtime($file));
$item->addChild('in_stock', (int) $product->getIsInStock());
$item->addChild('is_salable', (int) $product->isSalable());
/**
* By default all products has gallery (because of collection not load gallery attribute)
*/
$hasGallery = 1;
if ($product->getMediaGalleryImages()) {
$hasGallery = sizeof($product->getMediaGalleryImages()) > 0 ? 1 : 0;
}
$item->addChild('has_gallery', $hasGallery);
/**
* If product type is grouped than it has options as its grouped items
*/
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE || $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
$product->setHasOptions(true);
}
$item->addChild('has_options', (int) $product->getHasOptions());
if ($minSaleQty = $this->_getMinimalQty($product)) {
$item->addChild('min_sale_qty', (int) $minSaleQty);
}
if (!$product->getRatingSummary()) {
Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId());
}
$item->addChild('rating_summary', round((int) $product->getRatingSummary()->getRatingSummary() / 10));
$item->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount());
if ($this->getChild('product_price')) {
$this->getChild('product_price')->setProduct($product)->setProductXmlObj($item)->collectProductPrices();
}
if ($this->getChild('additional_info')) {
$this->getChild('additional_info')->addAdditionalData($product, $item);
}
}
return $item;
}
示例8: open
public function open($product_id)
{
$this->_product = Mage::getModel('catalog/product')->load($product_id);
if ($this->_product->getId()) {
$this->url($this->_product->getProductUrl());
return $this;
}
throw new Exception("product not found");
}
示例9: beforeProcess
public function beforeProcess()
{
$product = $this->getEvent()->getProduct();
if (!$product instanceof Mage_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');
}
示例10: getProductAttribute
/**
* Return Product attribute by attribute's ID
*
* @param Mage_Catalog_Model_Product $product
* @param int $attributeId
* @return null|Mage_Catalog_Model_Entity_Attribute Product's attribute
*/
public function getProductAttribute(Mage_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;
}
示例11: getChildrenAndParentIds
/**
* For a product get all the parent and children product ids when they are set
*
* @param Mage_Catalog_Model_Product $oProduct
* @return int[]
*/
protected function getChildrenAndParentIds(Mage_Catalog_Model_Product $oProduct)
{
$oProductType = $oProduct->getTypeInstance();
$aLinkedProductIds = $oProductType->getParentIdsByChild($oProduct->getId());
$aChildProductIdsByGroups = $oProductType->getChildrenIds($oProduct->getId());
foreach ($aChildProductIdsByGroups as $aChildProductIds) {
$aLinkedProductIds = array_unique(array_merge($aLinkedProductIds, $aChildProductIds));
}
return $aLinkedProductIds;
}
示例12: _updateProductSubscriptions
/**
* @param Mage_Catalog_Model_Product $product
* @param $productSubscriptionsData
* @param $storeId
* @throws Exception
*/
protected function _updateProductSubscriptions(Mage_Catalog_Model_Product $product, $productSubscriptionsData, $storeId)
{
if (!$productSubscriptionsData) {
if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) {
$product->setData('adyen_subscription_type', Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED);
Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('adyen_subscription')->__('Adyen Subscription Type is set back to \'Disabled\' because no subscriptions were defined'));
}
return;
}
/** @var array $productSubscriptionIds */
$productSubscriptionCollection = Mage::getModel('adyen_subscription/product_subscription')->getCollection()->addFieldToFilter('product_id', $product->getId());
$isGlobal = Mage::app()->isSingleStoreMode();
if (!$isGlobal && (int) $storeId) {
/** @var $website Mage_Core_Model_Website */
$website = Mage::app()->getStore($storeId)->getWebsite();
$productSubscriptionCollection->addFieldToFilter('website_id', $website->getId());
}
$productSubscriptionIds = $productSubscriptionCollection->getAllIds();
$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_write');
$i = 1;
// Save subscriptions
foreach ($productSubscriptionsData as $id => $subscriptionData) {
$subscription = Mage::getModel('adyen_subscription/product_subscription')->load($id);
if (!$subscription->getId()) {
$subscription->setProductId($product->getId());
}
if (!isset($subscriptionData['use_default']) && $storeId) {
// Save store label
$labelData = array('label' => $subscriptionData['label'], 'subscription_id' => $subscription->getId(), 'store_id' => $storeId);
$connection->insertOnDuplicate($resource->getTableName('adyen_subscription/product_subscription_label'), $labelData, array('label'));
unset($subscriptionData['label']);
}
if (isset($subscriptionData['use_default']) && $storeId) {
// Delete store label
$connection->delete($resource->getTableName('adyen_subscription/product_subscription_label'), array('subscription_id = ?' => $subscription->getId(), 'store_id = ?' => $storeId));
}
if ($subscriptionData['customer_group_id'] == '') {
$subscriptionData['customer_group_id'] = null;
}
$subscription->addData($subscriptionData);
$subscription->setSortOrder($i * 10);
if (in_array($id, $productSubscriptionIds)) {
$productSubscriptionIds = array_diff($productSubscriptionIds, array($id));
}
$subscription->save();
$i++;
}
// Delete subscriptions
foreach ($productSubscriptionIds as $subscriptionId) {
Mage::getModel('adyen_subscription/product_subscription')->setId($subscriptionId)->delete();
}
}
示例13: _collectTags
/**
* Should return list of tags to clean
*
* @param Mage_Catalog_Model_Product $object
* @return string[]|string
*/
protected function _collectTags($object)
{
// Clear category cache for new products
if ($this->_isForUpdate && !$object->getId()) {
$result = array();
foreach ($object->getCategoryIds() as $categoryId) {
$result[] = EcomDev_Varnish_Model_Processor_Category::TAG_PREFIX . $categoryId;
}
return $result;
}
return self::TAG_PREFIX . $object->getId();
}
示例14: getRelatedProductsCollection
/**
* get a collection of all related products
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_Model_Resource_Product_Collection|bool
*/
public function getRelatedProductsCollection(Mage_Catalog_Model_Product $product)
{
if (!$product->getId()) {
return false;
}
/** @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $productCollection */
$parentProductsCollection = Mage::getResourceModel('catalog/product_collection');
$parentProductsCollection->addAttributeToSelect('url_key');
$parentProductsCollection->joinField('relation', 'catalog/product_relation', 'parent_id', 'parent_id=entity_id', '{{table}}.child_id=' . $product->getId(), 'inner');
$parentProductsCollection->load();
$parentProductsCollection->addItem($product);
return $parentProductsCollection;
}
示例15: prepareStockItemObserver
private function prepareStockItemObserver(Mage_Catalog_Model_Product $product)
{
/** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->loadByProduct($product->getId())->setProductId($product->getId());
foreach ($product->getData('stock_item')->getData() as $key => $value) {
$stockItem->setOrigData($key, $value);
}
$observer = new Varien_Event_Observer();
$observer->setEvent(new Varien_Event());
$observer->setData('item', $stockItem);
return $observer;
}