当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Catalog_Model_Product::setId方法代码示例

本文整理汇总了PHP中Mage_Catalog_Model_Product::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::setId方法的具体用法?PHP Mage_Catalog_Model_Product::setId怎么用?PHP Mage_Catalog_Model_Product::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Catalog_Model_Product的用法示例。


在下文中一共展示了Mage_Catalog_Model_Product::setId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCleanCache

 public function testCleanCache()
 {
     Mage::app()->saveCache('test', 'catalog_product_999', array('catalog_product_999'));
     // potential bug: it cleans by cache tags, generated from its ID, which doesn't make much sense
     $this->_model->setId(999)->cleanCache();
     $this->assertEmpty(Mage::app()->loadCache('catalog_product_999'));
 }
开发者ID:nemphys,项目名称:magento2,代码行数:7,代码来源:ProductTest.php

示例2: testGetUrl

 public function testGetUrl()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     $this->assertStringEndsWith('simple-product.html', $this->_model->getUrl($product));
     $product = new Mage_Catalog_Model_Product();
     $product->setId(100);
     $this->assertStringEndsWith('catalog/product/view/id/100/', $this->_model->getUrl($product));
 }
开发者ID:NatashaOlut,项目名称:Mage_Test,代码行数:9,代码来源:Url.php

示例3: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->_catalogProductViewAjaxBlock = new Lesti_Fpc_Block_Catalog_Product_View_Ajax();
     // register a product
     $product = new Mage_Catalog_Model_Product();
     $product->setId(5);
     Mage::register('current_product', $product);
 }
开发者ID:AndreKlang,项目名称:Lesti_Fpc,代码行数:9,代码来源:Ajax.php

示例4: testGenerateUniqueSkuExistingProduct

 /**
  * @magentoDataFixture Mage/Catalog/_files/product_simple.php
  */
 public function testGenerateUniqueSkuExistingProduct()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     $product->setId(null);
     $this->assertEquals('simple', $product->getSku());
     $product->getResource()->getAttribute('sku')->getBackend()->beforeSave($product);
     $this->assertEquals('simple-1', $product->getSku());
 }
开发者ID:nayanchamp,项目名称:magento2,代码行数:12,代码来源:SkuTest.php

示例5: testCalaogProductSaveAfter

 /**
  * @test
  */
 public function testCalaogProductSaveAfter()
 {
     $this->_fpc->save('product1', 'product1_cache_id', array(sha1('product_1')));
     $this->_fpc->save('category1', 'category1_cache_id', array(sha1('category_1')));
     $this->_fpc->save('category2', 'category2_cache_id', array(sha1('category_2')));
     $product = new Mage_Catalog_Model_Product();
     $product->setOrigData(array());
     $product->setCategoryIds(array(1));
     $product->setId(1);
     Mage::dispatchEvent('catalog_product_save_after', array('product' => $product));
     $this->assertFalse($this->_fpc->load('product1_cache_id'));
     $this->assertFalse($this->_fpc->load('category1_cache_id'));
     $this->assertEquals('category2', $this->_fpc->load('category2_cache_id'));
 }
开发者ID:AndreKlang,项目名称:Lesti_Fpc,代码行数:17,代码来源:Save.php

示例6: testGetEmailToFriendUrl

 public function testGetEmailToFriendUrl()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->setId(100);
     $category = new Mage_Catalog_Model_Category();
     $category->setId(10);
     Mage::register('current_category', $category);
     try {
         $this->assertStringEndsWith('sendfriend/product/send/id/100/cat_id/10/', $this->_helper->getEmailToFriendUrl($product));
         Mage::unregister('current_category');
     } catch (Exception $e) {
         Mage::unregister('current_category');
         throw $e;
     }
 }
开发者ID:relue,项目名称:magento2,代码行数:15,代码来源:ProductTest.php

示例7: testCustomOptionsApi

 /**
  * @covers Mage_Catalog_Model_Product::addCustomOption
  * @covers Mage_Catalog_Model_Product::setCustomOptions
  * @covers Mage_Catalog_Model_Product::getCustomOptions
  * @covers Mage_Catalog_Model_Product::getCustomOption
  * @covers Mage_Catalog_Model_Product::hasCustomOptions
  */
 public function testCustomOptionsApi()
 {
     $this->assertEquals(array(), $this->_model->getCustomOptions());
     $this->assertFalse($this->_model->hasCustomOptions());
     $this->_model->setId(99);
     $this->_model->addCustomOption('one', 'value1');
     $option = $this->_model->getCustomOption('one');
     $this->assertInstanceOf('Varien_Object', $option);
     $this->assertEquals($this->_model->getId(), $option->getProductId());
     $this->assertSame($option->getProduct(), $this->_model);
     $this->assertEquals('one', $option->getCode());
     $this->assertEquals('value1', $option->getValue());
     $this->assertEquals(array('one' => $option), $this->_model->getCustomOptions());
     $this->assertTrue($this->_model->hasCustomOptions());
     $this->_model->setCustomOptions(array('test'));
     $this->assertTrue(is_array($this->_model->getCustomOptions()));
 }
开发者ID:relue,项目名称:magento2,代码行数:24,代码来源:ProductExternalTest.php

示例8: testAfterSaveEmpty

 /**
  * @depends testAfterSave
  */
 public function testAfterSaveEmpty()
 {
     Mage::app()->setCurrentStore(Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID));
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     $product->setOrigData();
     $product->setTierPrice(array());
     $this->_model->afterSave($product);
     $product = new Mage_Catalog_Model_Product();
     $product->setId(1);
     $this->_model->afterLoad($product);
     $this->assertEmpty($product->getTierPrice());
 }
开发者ID:relue,项目名称:magento2,代码行数:16,代码来源:TierpriceTest.php

示例9: _testGetProductUrl

 protected function _testGetProductUrl($method, $expectedFullAction)
 {
     $product = new Mage_Catalog_Model_Product();
     $product->setId(10);
     $url = $this->_helper->{$method}($product);
     $this->assertContains($expectedFullAction, $url);
     $this->assertContains('/product/10/', $url);
     $this->assertContains('/uenc/', $url);
 }
开发者ID:NatashaOlut,项目名称:Mage_Test,代码行数:9,代码来源:Compare.php

示例10: importProducts

 public function importProducts($products, $storeId, $store)
 {
     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
     if (!empty($products)) {
         foreach ($products as $_product) {
             $update = false;
             if ($_product["code"]) {
                 $sku = $_product["code"];
             } elseif ($_product["code2"]) {
                 $sku = $_product["code2"];
             } else {
                 $sku = $_product["code3"];
             }
             $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
             if (!$product) {
                 $product = Mage::getModel('catalog/product')->load($_product["productID"]);
                 if (!$product->getName()) {
                     $product = new Mage_Catalog_Model_Product();
                     $product->setId($_product["productID"]);
                     Mage::helper('Erply')->log("Creating new product: " . $_product["productID"]);
                 } else {
                     Mage::helper('Erply')->log("Editing old product: " . $_product["productID"]);
                     $update = true;
                 }
             } else {
                 $update = true;
             }
             if ($_product["displayedInWebshop"] == 0) {
                 if ($update) {
                     try {
                         $product->delete();
                         Mage::helper('Erply')->log("Delete existing product which should be in webshop id: " . $_product["productID"] . " - sku: " . $sku);
                     } catch (Exception $e) {
                         Mage::helper('Erply')->log("Failed to delete product with message: " . $e->getMessage());
                     }
                 }
                 continue;
             }
             $product->setStoreId($storeId);
             // product does not exist so we will be creating a new one.
             $product->setIsMassupdate(true);
             $product->setExcludeUrlRewrite(true);
             $product->setTypeId('simple');
             $product->setWeight(1.0);
             $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
             $product->setStatus(1);
             $product->setSku($sku);
             $product->setTaxClassId(0);
             // set the rest of the product information here that can be set on either new/update
             if (!$update) {
                 $product->setAttributeSetId((int) Mage::getStoreConfig('eepohs_erply/product/attribute_set', $storeId));
                 // the product attribute set to use
             }
             $product->setName($_product["name"]);
             $category = Mage::getModel('catalog/category')->load($_product["groupID"]);
             if ($category->getName()) {
                 $product->setCategoryIds(array($_product["groupID"]));
                 // array of categories it will relate to
             }
             if (Mage::app()->isSingleStoreMode()) {
                 $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsiteId()));
             } else {
                 $product->setWebsiteIds(array($store->getWebsiteId()));
             }
             $product->setBatchPrices(array());
             $product->setStockPriorities(array());
             //$product->setPrice($_product["price"]);
             // set the product images as such
             // $image is a full path to the image. I found it to only work when I put all the images I wanted to import into the {magento_path}/media/catalog/products - I just created my own folder called import and it read from those images on import.
             //        $image = '/path/to/magento/media/catalog/products/import/image.jpg';
             //
             //        $product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
             //        $product->addImageToMediaGallery ($image, array ('image'), false, false);
             //        $product->addImageToMediaGallery ($image, array ('small_image'), false, false);
             //        $product->addImageToMediaGallery ($image, array ('thumbnail'), false, false);
             // setting custom attributes. for example for a custom attribute called special_attribute
             // special_attribute will be used on all examples below for the various attribute types
             //$product->setSpecialAttribute('value here');
             // setting a Yes/No Attribute
             //        $product->setSpecialField(1);
             // setting a Selection Attribute
             //$product->setSpecialAttribute($idOfAttributeOption); //specify the ID of the attribute option, eg you creteated an option called Blue in special_attribute it was assigned an ID of some number. Use that number.
             // setting a Mutli-Selection Attribute
             //$data['special_attribute'] = '101 , 102 , 103'; // coma separated string of option IDs. As ID , ID (mind the spaces before and after coma, it worked for me like that)
             //        $product->setData($data);
             if (isset($_product["attributes"])) {
                 $erplyAttributes = $_product["attributes"];
                 $mapping = unserialize(Mage::getStoreConfig('eepohs_erply/product/attributes', $storeId));
                 if (!empty($erplyAttributes) && !empty($mapping)) {
                     $mappings = array();
                     foreach ($mapping as $map) {
                         $mappings[$map["erply_attribute"]] = $map["magento_attribute"];
                     }
                     foreach ($erplyAttributes as $attribute) {
                         if (in_array($attribute["attributeName"], array_keys($mappings))) {
                             if ($attribute["attributeValue"]) {
                                 $product->setData($mappings[$attribute["attributeName"]], $attribute["attributeValue"]);
                             }
                         }
                     }
//.........这里部分代码省略.........
开发者ID:vaimo,项目名称:Eepohs_Erply,代码行数:101,代码来源:Product.php

示例11:

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  Test
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$productOne = new Mage_Catalog_Model_Product();
$productOne->setId(1)->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setAttributeSetId(4)->setWebsiteIds(array(Mage::app()->getStore()->getWebsiteId()))->setSku('simple_product_1')->setName('Simple Product 1 Name')->setDescription('Simple Product 1 Full Description')->setShortDescription('Simple Product 1 Short Description')->setPrice(1234.56)->setTaxClassId(2)->setStockData(array('use_config_manage_stock' => 1, 'qty' => 99, 'is_in_stock' => 1))->setMetaTitle('Simple Product 1 Meta Title')->setMetaKeyword('Simple Product 1 Meta Keyword')->setMetaDescription('Simple Product 1 Meta Description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->addImageToMediaGallery(dirname(__FILE__) . '/product_image.png', null, false, false)->save();
$productTwo = new Mage_Catalog_Model_Product();
$productTwo->setId(2)->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)->setAttributeSetId(4)->setWebsiteIds(array(Mage::app()->getStore()->getWebsiteId()))->setSku('simple_product_2')->setName('Simple Product 2 Name')->setDescription('Simple Product 2 Full Description')->setShortDescription('Simple Product 2 Short Description')->setPrice(987.65)->setTaxClassId(2)->setStockData(array('use_config_manage_stock' => 1, 'qty' => 24, 'is_in_stock' => 1))->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->save();
开发者ID:NatashaOlut,项目名称:Mage_Test,代码行数:29,代码来源:products.php

示例12:

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Catalog
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$product = new Mage_Catalog_Model_Product();
$product->setTypeId('simple')->setId(1)->setAttributeSetId(4)->setName('Simple Product')->setSku('simple')->setPrice(10)->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->save();
$customDesignProduct = new Mage_Catalog_Model_Product($product->getData());
$customDesignProduct->setId(2)->setCustomDesign('default/default/blue')->save();
开发者ID:relue,项目名称:magento2,代码行数:29,代码来源:products.php

示例13: setId

 function setId($id)
 {
     $this->vf_product->setId($id);
     return parent::setId($id);
 }
开发者ID:xiaoguizhidao,项目名称:autotech_design,代码行数:5,代码来源:Product.php

示例14: testGetCacheTagsProductList

 /**
  * @test
  */
 public function testGetCacheTagsProductList()
 {
     $productOne = new Mage_Catalog_Model_Product();
     $productOne->setId(1);
     $productTwo = new Mage_Catalog_Model_Product();
     $productTwo->setId(2);
     $block = new Mage_Core_Block_Template();
     $block->setNameInLayout('product_list');
     $block->setLoadedProductCollection(array($productOne, $productTwo));
     $this->assertEquals(array('38a007151abe87cc01a5b6e9cc418e85286e2087', '65dd4967fe508e9ebad619a8c976beabf46588fe', '499ed21cb19c984d31e23b94a60730520afa8181'), $this->_blockHelper->getCacheTags($block));
 }
开发者ID:nessnik,项目名称:Lesti_Fpc,代码行数:14,代码来源:Block.php

示例15: importProducts

 public function importProducts()
 {
     $queue = Mage::getModel('Erply/Queue')->loadActive('erply_product_import');
     $params = array();
     if ($queue) {
         $runEvery = Mage::getStoreConfig('eepohs_erply/queue/run_every', $queue->getStoreId());
         $loops = $queue->getLoopsPerRun();
         $pageSize = $queue->getRecordsPerRun();
         $recordsLeft = $queue->getTotalRecords() - $pageSize * $queue->getLastPageNo();
         if ($queue->getChangedSince()) {
             $params = array('changedSince' => $queue->getChangedSince());
         }
         if ($loops * $pageSize > $recordsLeft) {
             $loops = ceil($recordsLeft / $pageSize);
             $queue->setStatus(0);
         } else {
             $thisRunTime = strtotime($queue->getScheduledAt());
             $newRunTime = strtotime('+' . $runEvery . 'minute', $thisRunTime);
             $scheduleDateTime = date('Y-m-d H:i:s', $newRunTime);
             Mage::getModel('Erply/Cron')->addCronJob('erply_product_import', $scheduleDateTime);
             $queue->setScheduledAt($scheduleDateTime);
         }
         $loops--;
         $firstPage = $queue->getLastPageNo() + 1;
         $queue->setLastPageNo($firstPage + $loops);
         $queue->setUpdatedAt(date('Y-m-d H:i:s', time()));
         $queue->save();
         $this->verifyUser($queue->getStoreId());
         $store = Mage::getModel('core/store')->load($queue->getStoreId());
         for ($i = $firstPage; $i <= $firstPage + $loops; $i++) {
             $parameters = array_merge(array('recordsOnPage' => $pageSize, 'pageNo' => $i), $params);
             Mage::helper('Erply')->log("Erply request: ");
             Mage::helper('Erply')->log($parameters);
             $result = $this->sendRequest('getProducts', $parameters);
             $return = "";
             Mage::helper('Erply')->log("Erply product import:");
             Mage::helper('Erply')->log($result);
             $output = json_decode($result, true);
             $start = time();
             foreach ($output["records"] as $_product) {
                 if ($_product["code2"]) {
                     $sku = $_product["code2"];
                 } elseif ($_product["code"]) {
                     $sku = $_product["code"];
                 } else {
                     $sku = $_product["code3"];
                 }
                 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
                 if (!$product) {
                     $product = Mage::getModel('catalog/product')->load($_product["productID"]);
                     if (!$product->getName()) {
                         $product = new Mage_Catalog_Model_Product();
                         $product->setId($_product["productID"]);
                         Mage::helper('Erply')->log("Creating new product: " . $_product["productID"]);
                     } else {
                         Mage::helper('Erply')->log("Editing old product: " . $_product["productID"]);
                     }
                 }
                 // product does not exist so we will be creating a new one.
                 $product->setIsMassupdate(true);
                 $product->setExcludeUrlRewrite(true);
                 $product->setTypeId('simple');
                 $product->setWeight(1.0);
                 $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
                 $product->setStatus(1);
                 $product->setSku($sku);
                 $product->setTaxClassId(0);
                 //                    if (Mage::app()->isSingleStoreMode()) {
                 //                        $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsiteId()));
                 //                    }
                 //                    else {
                 //                        $product->setWebsiteIds(array(Mage::getModel('core/store')->load($queue->getStoreId())->getWebsiteId()));
                 //                    }
                 //                    $product->setStoreIDs(array($queue->getStoreId()));  // your store ids
                 //                    $product->setStockData(array(
                 //                        'is_in_stock' => 1,
                 //                        'qty' => 99999,
                 //                        'manage_stock' => 0,
                 //                    ));
                 // set the rest of the product information here that can be set on either new/update
                 $product->setAttributeSetId(4);
                 // the product attribute set to use
                 $product->setName($_product["name"]);
                 $product->setCategoryIds(array($_product["groupID"]));
                 // array of categories it will relate to
                 if (Mage::app()->isSingleStoreMode()) {
                     $product->setWebsiteIds(array(Mage::app()->getStore($queue->getStoreId())->getWebsiteId()));
                 } else {
                     $product->setWebsiteIds(array($store->getWebsiteId()));
                 }
                 $product->setDescription($_product["longdesc"]);
                 $product->setShortDescription($_product["description"]);
                 $product->setPrice($_product["price"]);
                 // set the product images as such
                 // $image is a full path to the image. I found it to only work when I put all the images I wanted to import into the {magento_path}/media/catalog/products - I just created my own folder called import and it read from those images on import.
                 //        $image = '/path/to/magento/media/catalog/products/import/image.jpg';
                 //
                 //        $product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
                 //        $product->addImageToMediaGallery ($image, array ('image'), false, false);
                 //        $product->addImageToMediaGallery ($image, array ('small_image'), false, false);
//.........这里部分代码省略.........
开发者ID:vaimo,项目名称:Eepohs_Erply,代码行数:101,代码来源:Import.php


注:本文中的Mage_Catalog_Model_Product::setId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。