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')); }
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)); }
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); }
/** * @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()); }
/** * @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')); }
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; } }
/** * @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())); }
/** * @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()); }
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); }
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"]); } } } } } $product->save(); Mage::helper('Erply')->log("Added: " . $product->getSku()); } } }
/** * 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();
/** * 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();
function setId($id) { $this->vf_product->setId($id); return parent::setId($id); }
/** * @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)); }
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); // $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); $product->save(); Mage::helper('Erply')->log("Added: " . $product->getSku()); } unset($output); } } }
public function testAddImage() { $product = new Mage_Catalog_Model_Product(); $product->setId(1); $file = $this->_model->addImage($product, self::$_mediaTmpDir . '/magento_small_image.jpg'); $this->assertStringMatchesFormat('/m/a/magento_small_image%sjpg', $file); }