本文整理汇总了PHP中Mage_Catalog_Model_Product::addData方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::addData方法的具体用法?PHP Mage_Catalog_Model_Product::addData怎么用?PHP Mage_Catalog_Model_Product::addData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::addData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->_block = new Mage_Catalog_Block_Product_AbstractTestAbstract();
$this->_product = new Mage_Catalog_Model_Product();
$this->_product->load(1);
$this->_product->addData(array('image' => '/m/a/magento_image.jpg', 'small_image' => '/m/a/magento_image.jpg', 'thumbnail' => '/m/a/magento_image.jpg'));
$this->_block->setProduct($this->_product);
}
示例2: setUp
protected function setUp()
{
if (!self::$_isStubClass) {
$this->getMockForAbstractClass('Mage_Catalog_Block_Product_Abstract', array(), self::STUB_CLASS, false);
self::$_isStubClass = true;
}
$this->_block = Mage::app()->getLayout()->createBlock(self::STUB_CLASS);
$this->_product = Mage::getModel('Mage_Catalog_Model_Product');
$this->_product->load(1);
$this->_product->addData(array('image' => '/m/a/magento_image.jpg', 'small_image' => '/m/a/magento_image.jpg', 'thumbnail' => '/m/a/magento_image.jpg'));
$this->_block->setProduct($this->_product);
}
示例3: setUpBeforeClass
public static function setUpBeforeClass()
{
// image fixtures
self::$_fixtureMediaDir = Mage::getSingleton('Mage_Catalog_Model_Product_Media_Config')->getBaseMediaPath();
mkdir(self::$_fixtureMediaDir . '/m/a', 0777, true);
$fixtureDir = dirname(dirname(__FILE__)) . '/_files';
copy("{$fixtureDir}/magento_image.jpg", self::$_fixtureMediaDir . '/m/a/magento_image.jpg');
copy("{$fixtureDir}/magento_small_image.jpg", self::$_fixtureMediaDir . '/m/a/magento_small_image.jpg');
copy("{$fixtureDir}/magento_thumbnail.jpg", self::$_fixtureMediaDir . '/m/a/magento_thumbnail.jpg');
// watermark fixture
mkdir(self::$_fixtureMediaDir . '/watermark/stores/' . Mage::app()->getStore()->getId(), 0777, true);
copy("{$fixtureDir}/watermark.jpg", self::$_fixtureMediaDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . '/watermark.jpg');
// sample product with images
self::$_product = new Mage_Catalog_Model_Product();
self::$_product->addData(array('image' => '/m/a/magento_image.jpg', 'small_image' => '/m/a/magento_small_image.jpg', 'thumbnail' => '/m/a/magento_thumbnail.jpg'));
// sample image cached URL
$helper = new Mage_Catalog_Helper_Image();
self::$_sampleCachedUrl = (string) $helper->init(self::$_product, 'image');
}
示例4: extractGiftcardTenderValue
/**
* extract the giftcard tender code from the DOMNOdeList object
* then get a configuration array of eb2c key tender type map to Magento giftcard type
* check if the extracted giftcard tender code is a key the array of configuration of tender type map
* then proceed to add lifetime, is redeemable, email template flag to true in the given product object
* and then return the value from get giftcard type call
* if the key is not found in the map simply return null
* @param DOMNodeList $nodes
* @param Mage_Catalog_Model_Product $product
* @return int|null integer value a valid tender type was extracted null tender type is not configure
*/
public function extractGiftcardTenderValue(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
{
$value = Mage::helper('eb2ccore')->extractNodeVal($nodes);
$mapData = $this->_getGiftCardMap();
if (isset($mapData[$value])) {
$product->addData(array('use_config_lifetime' => true, 'use_config_is_redeemable' => true, 'use_config_email_template' => true));
return $this->_getGiftCardType($mapData[$value]);
}
return null;
}
示例5: createProduct
//.........这里部分代码省略.........
$i = 1;
$model = Mage::getModel('catalog/resource_eav_attribute');
foreach ($attributeValues->attribute as $attr) {
$loadedattr = $model->loadByCode('catalog_product', (string) $attr->id);
$attr_type = $loadedattr->getFrontendInput();
if (array_key_exists((string) $attr->id, $attributeOcuurance)) {
$multiple_values[(string) $attr->id][] = (string) $attr->valueDefId;
$attributeOcuurance[(string) $attr->id] = (int) $attributeOcuurance[(string) $attr->id] + 1;
if ($attr_type == 'text' || $attr_type == 'textarea') {
$multiple_values[(string) $attr->id][] = (string) $attr->value;
}
} else {
$multiple_values[(string) $attr->id][] = (string) $attr->valueDefId;
$attributeOcuurance[(string) $attr->id] = $i;
if ($attr_type == 'text' || $attr_type == 'textarea') {
$multiple_values[(string) $attr->id][] = (string) $attr->value;
}
}
}
foreach ($multiple_values as $attribute_code => $attribute_values) {
$loadedattr = $model->loadByCode('catalog_product', $attribute_code);
$attr_id = $loadedattr->getAttributeId();
// attribute id of magento
if (!$attr_id) {
$this->customHelper->reportError($this->customHelper->__('Attribute %s is not available in magento. Hence skipping product # %s', $attribute_code, $item->id));
return;
} else {
$attr_type = $loadedattr->getFrontendInput();
if ($attr_type == 'select' && count($attribute_values) == 1) {
$mapObj = Mage::getModel('customimport/customimport');
$option_id = $mapObj->isOptionExistsInAttribute($attribute_values[0], $attr_id);
if ($option_id) {
$product->setData($attribute_code, $option_id);
} else {
$this->customHelper->reportError($this->customHelper->__('Attribute %s has an undefined option value %s. Hence skipping product # %s', $attribute_code, $attribute_values[0], $item->id));
return;
}
} elseif ($attr_type == 'select' && count($attribute_values) > 1) {
//multiple values for attribute which is not multiselect
$this->customHelper->reportError($this->customHelper->__('Attribute %s can not have multiple values. Hence skipping product # %s', $attribute_code, $item->id));
return;
} elseif ($attr_type == 'multiselect') {
$multivalues = array();
foreach ($attribute_values as $value) {
$mapObj = Mage::getModel('customimport/customimport');
$option_id = $mapObj->isOptionExistsInAttribute($value, $attr_id);
if ($option_id) {
$multivalues[] = $option_id;
} else {
$this->customHelper->reportError($this->customHelper->__('Attribute %s has an undefined option value %s. Hence skipping product id %s', $attribute_code, $value, $item->id));
return;
}
}
$product->addData(array($attribute_code => $multivalues));
} elseif ($attr_type == 'text' || $attr_type == 'textarea') {
$product->setData($attribute_code, $attribute_values[1]);
} elseif ($attr_type == 'boolean') {
$optVal = Mage::getSingleton('customimport/customimport')->getOptVal($attribute_values[0]);
if (strtolower($optVal->getValue()) == 'y' || strtolower($optVal->getValue()) == 'yes') {
$attOptVal = 1;
} else {
$attOptVal = 0;
}
$product->setData($attribute_code, $attOptVal);
}
}
}
try {
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$productId = $product->save()->getId();
if ($manageItem == 'N' || $manageItem == 'n') {
$product->setStockData(array('use_config_backorders' => 0, 'is_in_stock' => 1, 'manage_stock' => 0));
//code for instock while update product
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->assignProduct($product);
$stockItem->setData('use_config_manage_stock', 0);
$stockItem->setData('manage_stock', 0);
$stockItem->save();
$stockStatus = Mage::getModel('cataloginventory/stock_status');
$stockStatus->assignProduct($product);
$stockStatus->saveProductStatus($product->getId(), 1);
}
if ($productId) {
$this->_created_num++;
unset($product);
unset($multiple_values);
unset($attributeOcuurance);
return $productId;
} else {
$this->customHelper->reportError($this->customHelper->__('Skipped product due to some error while saving # %s', $item->id));
}
} catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
$this->customHelper->reportError($e->getMessage());
$this->customHelper->reportError($e->getAttributeCode());
$this->customHelper->sendLogEmail($this->logPath);
}
} else {
$this->customHelper->reportError($this->customHelper->__('Attribute set ID # %s is missing. Hence skipped product # %s', $asid, $item->id));
}
}
示例6: addIndexToProduct
/**
* Add permission index to product model
*
* @param Mage_Catalog_Model_Product $product
* @param int $customerGroupId
* @return Enterprise_CatalogPermissions_Model_Resource_Permission_Index
*/
public function addIndexToProduct($product, $customerGroupId)
{
$adapter = $this->_getReadAdapter();
$select = $adapter->select()->from(array('cat_index' => $this->getTable('catalog/category_product_index')), array())->joinLeft(array('perm' => $this->getTable('permission_index')), 'perm.category_id=cat_index.category_id
AND perm.customer_group_id=:customer_group_id
AND perm.website_id=:website_id', $this->_getPermColumns())->where('product_id = :product_id')->where('customer_group_id = :customer_group_id OR customer_group_id IS NULL')->where('store_id = :store_id')->where('cat_index.is_parent=1')->group('cat_index.product_id');
$bind = array(':product_id' => $product->getId(), ':customer_group_id' => $customerGroupId, ':store_id' => $product->getStoreId(), ':website_id' => Mage::app()->getStore($product->getStoreId())->getWebsiteId());
if ($product->getCategory()) {
$select->where('perm.category_id = :category_id');
$bind[':category_id'] = $product->getCategory()->getId();
}
$permission = $adapter->fetchRow($select, $bind);
if ($permission) {
$product->addData($permission);
}
return $this;
}
示例7: applyDummyData
/**
* Fill a product model with dummy data so that it can be saved and edited later.
* @see http://www.magentocommerce.com/boards/viewthread/289906/
* @param Mage_Catalog_Model_Product $prod product model to be autofilled
* @param string $sku the new product's sku
* @param array $additionalData optional
* @return Mage_Catalog_Model_Product
*/
protected function applyDummyData(Mage_Catalog_Model_Product $prod, $sku, array $additionalData = [])
{
$prodData = array_merge($this->getProdTplt(), $additionalData);
$name = isset($prodData['name']) ? $prodData['name'] : null;
$prodData['name'] = $name ?: "Incomplete Product: {$sku}";
$prodData['sku'] = $prodData['url_key'] = $sku;
return $prod->addData($prodData);
}
示例8: addIndexToProduct
/**
* Add permission index to product model
*
* @param Mage_Catalog_Model_Product $product
* @param int $customerGroupId
* @return Enterprise_CatalogPermissions_Model_Mysql4_Permission_Index
*/
public function addIndexToProduct($product, $customerGroupId)
{
$select = $this->_getReadAdapter()->select()->from($this->getTable('permission_index_product'), array('grant_catalog_category_view', 'grant_catalog_product_price', 'grant_checkout_items'))->where('product_id = ?', $product->getId())->where('customer_group_id = ?', $customerGroupId)->where('store_id = ?', $product->getStoreId());
if ($product->getCategory()) {
$select->where('category_id = ?', $product->getCategory()->getId());
} else {
$select->where('category_id IS NULL');
}
$permission = $this->_getReadAdapter()->fetchRow($select);
if ($permission) {
$product->addData($permission);
}
return $this;
}
示例9: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
$product->addData($productData);
if (isset($productData['website_ids']) && is_array($productData['website_ids'])) {
$product->setWebsiteIds($productData['website_ids']);
}
if (isset($productData['websites']) && is_array($productData['websites'])) {
foreach ($productData['websites'] as &$website) {
if (is_string($website)) {
try {
$website = Mage::app()->getWebsite($website)->getId();
} catch (Exception $e) {
}
}
}
$product->setWebsiteIds($productData['websites']);
}
if (Mage::app()->isSingleStoreMode()) {
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
}
if (isset($productData['stock_data']) && is_array($productData['stock_data'])) {
$product->setStockData($productData['stock_data']);
}
if (isset($productData['tier_price']) && is_array($productData['tier_price'])) {
$tierPrices = Mage::getModel('catalog/product_attribute_tierprice_api')->prepareTierPrices($product, $productData['tier_price']);
$product->setData(Mage_Catalog_Model_Product_Attribute_Tierprice_Api::ATTRIBUTE_CODE, $tierPrices);
}
}