本文整理汇总了PHP中Mage_Catalog_Model_Product::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::setData方法的具体用法?PHP Mage_Catalog_Model_Product::setData怎么用?PHP Mage_Catalog_Model_Product::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReset
public function testReset()
{
$model = $this->_model;
$testCase = $this;
$assertEmpty = function () use($model, $testCase) {
$testCase->assertEquals(array(), $model->getData());
$testCase->assertEquals(null, $model->getOrigData());
$testCase->assertEquals(array(), $model->getCustomOptions());
// impossible to test $_optionInstance
$testCase->assertEquals(array(), $model->getOptions());
$testCase->assertFalse($model->canAffectOptions());
// impossible to test $_errors
};
$assertEmpty();
$this->_model->setData('key', 'value');
$this->_model->reset();
$assertEmpty();
$this->_model->setOrigData('key', 'value');
$this->_model->reset();
$assertEmpty();
$this->_model->addCustomOption('key', 'value');
$this->_model->reset();
$assertEmpty();
$this->_model->addOption(new Mage_Catalog_Model_Product_Option());
$this->_model->reset();
$assertEmpty();
$this->_model->canAffectOptions(true);
$this->_model->reset();
$assertEmpty();
}
示例2: afterSave
/**
* After attribute is saved upload file to media
* folder and save it to its associated product.
*
* @param Mage_Catalog_Model_Product $object
* @return Jvs_FileAttribute_Model_Attribute_Backend_File
*/
public function afterSave($object)
{
$value = $object->getData($this->getAttribute()->getName());
if (is_array($value) && !empty($value['delete'])) {
$object->setData($this->getAttribute()->getName(), '');
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
return;
}
try {
$uploadedFile = new Varien_Object();
$uploadedFile->setData('name', $this->getAttribute()->getName());
$uploadedFile->setData('allowed_extensions', array('jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'mpg', 'mpeg', 'mp3', 'wav', 'pdf', 'txt'));
Mage::dispatchEvent('jvs_fileattribute_allowed_extensions', array('file' => $uploadedFile));
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowedExtensions($uploadedFile->getData('allowed_extensions'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$uploader->save(Mage::getBaseDir('media') . '/catalog/product');
} catch (Exception $e) {
return $this;
}
$fileName = $uploader->getUploadedFileName();
if ($fileName) {
$object->setData($this->getAttribute()->getName(), $fileName);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
}
return $this;
}
示例3: testGetObsoleteGetters
/**
* @covers Mage_Catalog_Model_Product::getCalculatedFinalPrice
* @covers Mage_Catalog_Model_Product::getMinimalPrice
* @covers Mage_Catalog_Model_Product::getSpecialPrice
* @covers Mage_Catalog_Model_Product::getSpecialFromDate
* @covers Mage_Catalog_Model_Product::getSpecialToDate
* @covers Mage_Catalog_Model_Product::getRequestPath
* @covers Mage_Catalog_Model_Product::getGiftMessageAvailable
* @covers Mage_Catalog_Model_Product::getRatingSummary
* @dataProvider getObsoleteGettersDataProvider
* @param string $key
* @param string $method
*/
public function testGetObsoleteGetters($key, $method)
{
$value = uniqid();
$this->assertEmpty($this->_model->{$method}());
$this->_model->setData($key, $value);
$this->assertEquals($value, $this->_model->{$method}());
}
示例4: getUrl
public function getUrl(Mage_Catalog_Model_Product $product, $params = array())
{
if (Mage::getVersion() >= 1.8) {
$product->setData('url', '');
}
return parent::getUrl($product, $params);
}
示例5: modifyProduct
protected function modifyProduct(\Mage_Catalog_Model_Product $product, \Zend_Config $settings)
{
foreach ($settings as $attribute => $value) {
$product->setData($attribute, $value);
Logger::log('* change attribute <comment>%s</comment> of product #%d: "%s"', array($attribute, $product->getId(), $value));
}
$product->save();
}
示例6: productMediaFixture
public static function productMediaFixture()
{
$product = new Mage_Catalog_Model_Product();
$product->load(1);
$product->setTierPrice(array());
$product->setData('media_gallery', array('images' => array(array('file' => '/m/a/magento_image.jpg'))));
$product->save();
}
示例7: getFullProductUrl
/**
* get the longest url for a product
* from http://magento.stackexchange.com/questions/52969/get-product-path-from-id-with-category-path-in-url
* @param Mage_Catalog_Model_Product|null $product [description]
* @return String full url of the product
*/
public static function getFullProductUrl(Mage_Catalog_Model_Product $product = null)
{
// Force display deepest child category as request path.
$categories = $product->getCategoryCollection();
$deepCatId = 0;
$path = '';
$productPath = false;
foreach ($categories as $category) {
// Look for the deepest path and save.
if (substr_count($category->getData('path'), '/') > substr_count($path, '/')) {
$path = $category->getData('path');
$deepCatId = $category->getId();
}
}
// Load category.
$category = Mage::getModel('catalog/category')->load($deepCatId);
// Remove .html from category url_path.
$categoryPath = str_replace('.html', '', $category->getData('url_path'));
// Get product url path if set.
$productUrlPath = $product->getData('url_path');
// Get product request path if set.
$productRequestPath = $product->getData('request_path');
// If URL path is not found, try using the URL key.
if ($productUrlPath === null && $productRequestPath === null) {
$productUrlPath = $product->getData('url_key');
}
// Now grab only the product path including suffix (if any).
if ($productUrlPath) {
$path = explode('/', $productUrlPath);
$productPath = array_pop($path);
} elseif ($productRequestPath) {
$path = explode('/', $productRequestPath);
$productPath = array_pop($path);
}
// Now set product request path to be our full product url including deepest category url path.
if ($productPath !== false) {
if ($categoryPath) {
// Only use the category path is one is found.
$product->setData('request_path', $categoryPath . '/' . $productPath);
} else {
$product->setData('request_path', $productPath);
}
}
return $product->getProductUrl();
}
示例8: beforeSave
/**
* Before attribute save prepare data
*
* @param Mage_Catalog_Model_Product $object
* @return Enterprise_TargetRule_Model_Catalog_Product_Attribute_Backend_Rule
*/
public function beforeSave($object)
{
$attributeName = $this->getAttribute()->getName();
$useDefault = $object->getData($attributeName . '_default');
if ($useDefault == 1) {
$object->setData($attributeName, null);
}
return $this;
}
示例9: validate
/**
* Implode data for validation
*
* @param Mage_Catalog_Model_Product $object
* @return bool
*/
public function validate($object)
{
$attributeCode = $this->getAttribute()->getAttributeCode();
$data = $object->getData($attributeCode);
if (is_array($data)) {
$object->setData($attributeCode, implode(',', array_filter($data)));
}
return parent::validate($object);
}
示例10: addCustomer
public function addCustomer($data)
{
$connection = Mage::getModel('core/resource')->getConnection('core_read');
$product = new Mage_Catalog_Model_Product();
$product->setAttributeSetId(Mage::getModel('eav/entity_attribute_set')->getCollection()->setEntityTypeFilter($this->typeId)->addFieldToFilter('attribute_set_name', $data['attribute_set_id'])->getFirstItem()->getAttributeSetId());
unset($data['attribute_set_id']);
$product->setWebsiteIDs(array(1));
//// assign product to the default website $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
$product->setStoreIDs(array(1));
foreach ($data as $key => $value) {
switch ($key) {
case 'store_id':
case 'website_id':
break;
case 'status':
switch ($value) {
case 'Enabled':
$val = 1;
break;
case 'Disabled':
$val = 2;
break;
default:
$val = '';
}
$product->setData($key, $val);
break;
default:
in_array($key, $this->attrsWithOpts) ? $product->setData($key, $this->optByCode($key, $value)) : $product->setData($key, $value);
}
}
//unset($value);
$product->setIsMassupdate(false);
$product->setExcludeUrlRewrite(true);
try {
$product->save();
//Mage::getResourceSingleton('catalog/product_indexer_price')->reindexProductIds(array($productId));
} catch (Exception $ex) {
mage::D($ex);
#mage::log($ex->getMessage(), null, 'prodsimp.log');
}
}
示例11: _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();
}
}
示例12: prepareShopgateCouponProduct
/**
* Sets missing product Attributes for virutal product
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_Model_Product
*/
public function prepareShopgateCouponProduct(Mage_Catalog_Model_Product $product)
{
$product->setData('weight', 0);
$product->setData('tax_class_id', $this->_getTaxClassId());
$product->setData('attribute_set_id', $this->_getAttributeSetId());
$product->setData('stock_data', $this->_getStockData());
$product->setData('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
$product->setData('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$product->setData('type_id', Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL);
return $product;
}
示例13: _attributes
/**
* @param Mage_Catalog_Model_Product $product
*/
protected function _attributes(Mage_Catalog_Model_Product &$product)
{
$_attributes = $product->getAttributes();
/** @var Mage_Eav_Model_Entity_Attribute $attribute */
foreach ($_attributes as $attribute) {
if ($attribute->getBackendType() == self::ATTRIBUTE_TYPE_TO_PREPARE) {
$attributeText = $product->getAttributeText($attribute->getAttributeCode());
//getting attribute value
$product->setData($attribute->getAttributeCode(), $attributeText);
//setting this to product (override existing integer value)
}
}
}
示例14: setData
function setData($key, $value = null)
{
if (is_array($key)) {
if (isset($key['id'])) {
$this->setId($key['id']);
}
if (isset($key['entity_id'])) {
$this->setId($key['entity_id']);
}
} elseif ('id' == $key || 'entity_id' == $key) {
$this->vf_product->setId($value);
}
return parent::setData($key, $value);
}
示例15: getProductSplashPage
/**
* Retrieve a splash page for the product / attribute code combination
*
* @param Mage_Catalog_Model_Product $product
* @param $attributeCode
* @return Fishpig_AttributeSplash_Model_Splash|null
*/
public function getProductSplashPage(Mage_Catalog_Model_Product $product, $attributeCode)
{
$key = $attributeCode . '_splash_page';
if (!$product->hasData($key)) {
$product->setData($key, false);
$collection = Mage::getResourceModel('attributeSplash/page_collection')->addStoreFilter(Mage::app()->getStore())->addAttributeCodeFilter($attributeCode)->addProductFilter($product)->setPageSize(1)->setCurPage(1)->load();
if (count($collection) > 0) {
$page = $collection->getFirstItem();
if ($page->getId()) {
$product->setData($key, $page);
}
}
}
return $product->getData($key);
}