本文整理汇总了PHP中Mage_Catalog_Model_Product::setWebsiteIds方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::setWebsiteIds方法的具体用法?PHP Mage_Catalog_Model_Product::setWebsiteIds怎么用?PHP Mage_Catalog_Model_Product::setWebsiteIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::setWebsiteIds方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (isset($productData['categories']) && is_array($productData['categories'])) {
$product->setCategoryIds($productData['categories']);
}
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']);
} else {
$product->setStockData(array('use_config_manage_stock' => 0));
}
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);
}
/*
* Check if configurable product data array passed
*/
if (isset($productData['configurable_products_data']) && is_array($productData['configurable_products_data'])) {
$product->setConfigurableProductsData($productData['configurable_products_data']);
}
if (isset($productData['configurable_attributes_data']) && is_array($productData['configurable_attributes_data'])) {
foreach ($productData['configurable_attributes_data'] as $key => $data) {
//Check to see if these values exist, otherwise try and populate from existing values
$data['label'] = !empty($data['label']) ? $data['label'] : $product->getResource()->getAttribute($data['attribute_code'])->getStoreLabel();
$data['frontend_label'] = !empty($data['frontend_label']) ? $data['frontend_label'] : $product->getResource()->getAttribute($data['attribute_code'])->getFrontendLabel();
$productData['configurable_attributes_data'][$key] = $data;
}
$product->setConfigurableAttributesData($productData['configurable_attributes_data']);
$product->setCanSaveConfigurableAttributes(true);
}
/*
* Check if bundle product data, options and bundle items arrays passed
*/
if (isset($productData['bundle_items_data']) && isset($productData['options_data']) && is_array($productData['bundle_items_data']) && is_array($productData['options_data'])) {
$product->setBundleOptionsData($productData['options_data']);
$product->setBundleSelectionsData($productData['bundle_items_data']);
$product->setCanSaveBundleSelections(true);
$product->setAffectBundleProductSelections(true);
Mage::register('product', $product);
// product must be registred in order to get the store_id, see _beforeSave() in Mage/Bundle/Model/Selection.php
}
}
示例2: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (isset($productData['categories']) && is_array($productData['categories'])) {
$product->setCategoryIds($productData['categories']);
}
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 (isset($productData['stock_data']) && is_array($productData['stock_data'])) {
$product->setStockData($productData['stock_data']);
}
}
示例3: createBundleProduct
public function createBundleProduct(&$item, $asid)
{
$attributeSetModel = Mage::getModel('eav/entity_attribute_set');
$attributeSetModel->load($asid);
if (count($attributeSetModel) > 0) {
$p_status = (string) $item->isActive == 'Y' ? 1 : 2;
$p_taxclass = (string) $item->isTaxable == 'Y' ? 2 : 0;
$product = new Mage_Catalog_Model_Product();
$product->setTypeId('bundle');
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
//New and created data code start
$format = 'Y-m-d H:i:s';
$catalogNewproductDays = Mage::getStoreConfig('catalog/newproduct/days', Mage::app()->getStore());
if (!empty($catalogNewproductDays) && $catalogNewproductDays >= 0) {
$currenDateTime = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
$new_from_date = date($format, strtotime('1 days' . $currenDateTime));
$new_to_date = date($format, strtotime($catalogNewproductDays . ' days' . $new_from_date));
$product->setNewsFromDate($new_from_date);
$product->setNewsToDate($new_to_date);
}
if ($product->getCreatedTime == NULL || $product->getUpdateTime() == NULL) {
$product->setCreatedTime($currenDateTime)->setUpdateTime($currenDateTime);
}
//New and created data code end
$product->setSku((string) $item->id);
//Product custom id
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
$product->setStoreIDs(array($this->_store_id));
// Default store id .
$product->setAttributeSetId($asid);
$product->setData('name', (string) $item->name);
$product->setPrice((double) $item->price);
$splAmt = (array) $item->specialPrice->amount;
if (isset($item->specialPrice->amount) && $item->specialPrice->amount != NULL) {
if (!empty($splAmt)) {
$product->setSpecialPrice((double) $item->specialPrice->amount);
}
//special price in form 11.22
}
$fromDate = (array) $item->specialPrice->fromDateTime;
if (isset($item->specialPrice->fromDateTime) && $item->specialPrice->fromDateTime != NULL) {
if (!empty($fromDate)) {
$product->setSpecialFromDate(Mage::helper('customimport')->getCurrentLocaleDateTime($item->specialPrice->fromDateTime));
}
//special price from (MM-DD-YYYY)
}
$toDate = (array) $item->specialPrice->toDateTime;
if (isset($item->specialPrice->toDateTime) && $item->specialPrice->toDateTime != NULL) {
if (!empty($toDate)) {
$product->setSpecialToDate(Mage::helper('customimport')->getCurrentLocaleDateTime($item->specialPrice->toDateTime));
}
//special price to (MM-DD-YYYY)
}
$product->setWeight((double) $item->weight);
$product->setStatus($p_status);
$product->setTaxClassId($p_taxclass);
$product->setDescription((string) $item->longDescription);
$product->setShortDescription((string) $item->shortDescription);
$product->setMetaTitle((string) $item->pageTitle);
$product->setMetaKeyword((string) $item->metaKeywords);
$product->setMetaDescription((string) $item->metaDescription);
$product->setExternalImage((string) $item->originalImageUrl);
$product->setExternalSmallImage((string) $item->largeImageUrl);
$product->setExternalThumbnail((string) $item->smallImageUrl);
$product->setShipmentType(0);
//shipment type (0 - together, 1 - separately
try {
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product->save();
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->assignProduct($product);
$stockItem->setData('stock_id', (int) 1);
$stockItem->setData('use_config_manage_stock', (int) 1);
$stockItem->setData('min_qty', (int) 0);
$stockItem->setData('is_decimal_divided', (int) 0);
$stockItem->setData('qty', (int) 0);
$stockItem->setData('use_config_min_qty', 1);
$stockItem->setData('use_config_backorders', 1);
$stockItem->setData('min_sale_qty', 1);
$stockItem->setData('use_config_min_sale_qty', 1);
$stockItem->setData('use_config_max_sale_qty', 1);
$stockItem->setData('is_in_stock', 1);
$stockItem->setData('use_config_notify_stock_qty', 1);
// Added Manage Stock Functionality
// Manage Stock
$inventory = $item->inventory;
$manageItem = (string) strtoupper($inventory->manageStock);
if ($manageItem == 'N') {
$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);
} catch (Exception $e) {
$this->customHelper->reportError($e->getMessage());
$this->customHelper->sendLogEmail($this->logPath);
}
} else {
//.........这里部分代码省略.........
示例4: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (!is_object($productData)) {
$this->_fault('data_invalid');
}
if (property_exists($productData, 'website_ids') && is_array($productData->website_ids)) {
$product->setWebsiteIds($productData->website_ids);
}
if (property_exists($productData, 'additional_attributes')) {
if (property_exists($productData->additional_attributes, 'single_data')) {
foreach ($productData->additional_attributes->single_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->{$_attrCode} = $_attribute->value;
}
}
if (property_exists($productData->additional_attributes, 'multi_data')) {
foreach ($productData->additional_attributes->multi_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->{$_attrCode} = $_attribute->value;
}
}
unset($productData->additional_attributes);
}
foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
$_attrCode = $attribute->getAttributeCode();
//Unset data if object attribute has no value in current store
if (Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID !== (int) $product->getStoreId() && !$product->getExistsStoreValueFlag($_attrCode) && !$attribute->isScopeGlobal()) {
$product->setData($_attrCode, false);
}
if ($this->_isAllowedAttribute($attribute) && isset($productData->{$_attrCode})) {
$product->setData($_attrCode, $productData->{$_attrCode});
}
}
if (property_exists($productData, 'categories') && is_array($productData->categories)) {
$product->setCategoryIds($productData->categories);
}
if (property_exists($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 (property_exists($productData, 'stock_data')) {
$_stockData = array();
foreach ($productData->stock_data as $key => $value) {
$_stockData[$key] = $value;
}
$product->setStockData($_stockData);
}
if (property_exists($productData, 'tier_price')) {
$tierPrices = Mage::getModel('catalog/product_attribute_tierprice_api_V2')->prepareTierPrices($product, $productData->tier_price);
$product->setData(Mage_Catalog_Model_Product_Attribute_Tierprice_Api_V2::ATTRIBUTE_CODE, $tierPrices);
}
}
示例5: 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"]);
}
}
}
//.........这里部分代码省略.........
示例6: _prepareDataForSave
/**
* Set additional data before product save
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
*/
protected function _prepareDataForSave($product, $productData)
{
if (isset($productData['stock_data'])) {
if (!$product->isObjectNew() && !isset($productData['stock_data']['manage_stock'])) {
$productData['stock_data']['manage_stock'] = $product->getStockItem()->getManageStock();
}
$this->_filterStockData($productData['stock_data']);
} else {
$productData['stock_data'] = array('use_config_manage_stock' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1);
}
$product->setStockData($productData['stock_data']);
// save gift options
$this->_filterConfigValueUsed($productData, array('gift_message_available', 'gift_wrapping_available'));
if (isset($productData['use_config_gift_message_available'])) {
$product->setData('use_config_gift_message_available', $productData['use_config_gift_message_available']);
if (!$productData['use_config_gift_message_available'] && $product->getData('gift_message_available') === null) {
$product->setData('gift_message_available', (int) Mage::getStoreConfig(Mage_GiftMessage_Helper_Message::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, $product->getStoreId()));
}
}
if (isset($productData['use_config_gift_wrapping_available'])) {
$product->setData('use_config_gift_wrapping_available', $productData['use_config_gift_wrapping_available']);
if (!$productData['use_config_gift_wrapping_available'] && $product->getData('gift_wrapping_available') === null) {
$xmlPathGiftWrappingAvailable = 'sales/gift_options/wrapping_allow_items';
$product->setData('gift_wrapping_available', (int) Mage::getStoreConfig($xmlPathGiftWrappingAvailable, $product->getStoreId()));
}
}
if (isset($productData['website_ids']) && is_array($productData['website_ids'])) {
$product->setWebsiteIds($productData['website_ids']);
}
// Create Permanent Redirect for old URL key
if (!$product->isObjectNew() && isset($productData['url_key']) && isset($productData['url_key_create_redirect'])) {
$product->setData('save_rewrites_history', (bool) $productData['url_key_create_redirect']);
}
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
//Unset data if object attribute has no value in current store
if (Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID !== (int) $product->getStoreId() && !$product->getExistsStoreValueFlag($attribute->getAttributeCode()) && !$attribute->isScopeGlobal()) {
$product->setData($attribute->getAttributeCode(), false);
}
if ($this->_isAllowedAttribute($attribute)) {
if (isset($productData[$attribute->getAttributeCode()])) {
$product->setData($attribute->getAttributeCode(), $productData[$attribute->getAttributeCode()]);
}
}
}
}
示例7: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (property_exists($productData, 'categories') && is_array($productData->categories)) {
$product->setCategoryIds($productData->categories);
}
if (property_exists($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 (property_exists($productData, 'stock_data')) {
$_stockData = array();
foreach ($productData->stock_data as $key => $value) {
$_stockData[$key] = $value;
}
} else {
$_stockData = array('use_config_manage_stock' => 0);
}
$product->setStockData($_stockData);
if (property_exists($productData, 'tier_price')) {
$tierPrices = Mage::getModel('catalog/product_attribute_tierprice_api_V2')->prepareTierPrices($product, $productData->tier_price);
$product->setData(Mage_Catalog_Model_Product_Attribute_Tierprice_Api_V2::ATTRIBUTE_CODE, $tierPrices);
}
}
示例8: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (isset($productData['website_ids']) && is_array($productData['website_ids'])) {
$product->setWebsiteIds($productData['website_ids']);
}
foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
//Unset data if object attribute has no value in current store
if (Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID !== (int) $product->getStoreId() && !$product->getExistsStoreValueFlag($attribute->getAttributeCode()) && !$attribute->isScopeGlobal()) {
$product->setData($attribute->getAttributeCode(), false);
}
if ($this->_isAllowedAttribute($attribute)) {
if (isset($productData[$attribute->getAttributeCode()])) {
$product->setData($attribute->getAttributeCode(), $productData[$attribute->getAttributeCode()]);
} elseif (isset($productData['additional_attributes']['single_data'][$attribute->getAttributeCode()])) {
$product->setData($attribute->getAttributeCode(), $productData['additional_attributes']['single_data'][$attribute->getAttributeCode()]);
} elseif (isset($productData['additional_attributes']['multi_data'][$attribute->getAttributeCode()])) {
$product->setData($attribute->getAttributeCode(), $productData['additional_attributes']['multi_data'][$attribute->getAttributeCode()]);
}
}
}
if (isset($productData['categories']) && is_array($productData['categories'])) {
$product->setCategoryIds($productData['categories']);
}
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);
}
}
示例9: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (property_exists($productData, 'website_ids') && is_array($productData->website_ids)) {
$product->setWebsiteIds($productData->website_ids);
}
if (property_exists($productData, 'additional_attributes')) {
if (property_exists($productData->additional_attributes, 'single_data')) {
foreach ($productData->additional_attributes->single_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->{$_attrCode} = $_attribute->value;
}
}
if (property_exists($productData->additional_attributes, 'multi_data')) {
foreach ($productData->additional_attributes->multi_data as $_attribute) {
$_attrCode = $_attribute->key;
$productData->{$_attrCode} = $_attribute->value;
}
}
unset($productData->additional_attributes);
}
foreach ($product->getTypeInstance()->getEditableAttributes($product) as $attribute) {
$_attrCode = $attribute->getAttributeCode();
if ($this->_isAllowedAttribute($attribute) && isset($productData->{$_attrCode})) {
$product->setData($attribute->getAttributeCode(), $productData->{$_attrCode});
}
}
if (property_exists($productData, 'categories') && is_array($productData->categories)) {
$product->setCategoryIds($productData->categories);
}
if (property_exists($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 (property_exists($productData, 'stock_data')) {
$_stockData = array();
foreach ($productData->stock_data as $key => $value) {
$_stockData[$key] = $value;
}
} else {
$_stockData = array('use_config_manage_stock' => 0);
}
$product->setStockData($_stockData);
if (property_exists($productData, 'tier_price')) {
$tierPrices = Mage::getModel('Mage_Catalog_Model_Product_Attribute_Tierprice_Api_V2')->prepareTierPrices($product, $productData->tier_price);
$product->setData(Mage_Catalog_Model_Product_Attribute_Tierprice_Api_V2::ATTRIBUTE_CODE, $tierPrices);
}
}
示例10: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (isset($productData['categories']) && is_array($productData['categories'])) {
$product->setCategoryIds($productData['categories']);
}
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);
}
}
示例11: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (property_exists($productData, 'categories') && is_array($productData->categories)) {
$product->setCategoryIds($productData->categories);
}
if (property_exists($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 (property_exists($productData, 'stock_data') && is_array($productData->stock_data)) {
$product->setStockData($productData->stock_data);
}
}
示例12: 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);
//.........这里部分代码省略.........
示例13: _prepareDataForSave
/**
* Set additional data before product saved
*
* @param Mage_Catalog_Model_Product $product
* @param array $productData
* @return object
*/
protected function _prepareDataForSave($product, $productData)
{
if (property_exists($productData, 'categories') && is_array($productData->categories)) {
$product->setCategoryIds($productData->categories);
}
if (property_exists($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 (property_exists($productData, 'stock_data')) {
$_stockData = array();
foreach ($productData->stock_data as $key => $value) {
$_stockData[$key] = $value;
}
$product->setStockData($_stockData);
}
}