本文整理汇总了PHP中Mage_Catalog_Model_Product::getWebsiteIds方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getWebsiteIds方法的具体用法?PHP Mage_Catalog_Model_Product::getWebsiteIds怎么用?PHP Mage_Catalog_Model_Product::getWebsiteIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getWebsiteIds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareTierPrices
/**
* Prepare tier prices for save
*
* @param Mage_Catalog_Model_Product $product
* @param array $tierPrices
* @return array
*/
public function prepareTierPrices($product, $tierPrices = null)
{
if (!is_array($tierPrices)) {
return null;
}
$updateValue = array();
foreach ($tierPrices as $tierPrice) {
if (!is_object($tierPrice) || !isset($tierPrice->qty) || !isset($tierPrice->price)) {
$this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid Tier Prices'));
}
if (!isset($tierPrice->website) || $tierPrice->website == 'all') {
$tierPrice->website = 0;
} else {
try {
$tierPrice->website = Mage::app()->getWebsite($tierPrice->website)->getId();
} catch (Mage_Core_Exception $e) {
$tierPrice->website = 0;
}
}
if (intval($tierPrice->website) > 0 && !in_array($tierPrice->website, $product->getWebsiteIds())) {
$this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid tier prices. The product is not associated to the requested website.'));
}
if (!isset($tierPrice->customer_group_id)) {
$tierPrice->customer_group_id = 'all';
}
if ($tierPrice->customer_group_id == 'all') {
$tierPrice->customer_group_id = Mage_Customer_Model_Group::CUST_GROUP_ALL;
}
$updateValue[] = array('website_id' => $tierPrice->website, 'cust_group' => $tierPrice->customer_group_id, 'price_qty' => $tierPrice->qty, 'price' => $tierPrice->price);
}
return $updateValue;
}
示例2: testGetWebsiteIds
public function testGetWebsiteIds()
{
// set
/** @var $model Mage_Catalog_Model_Product */
$model = Mage::getModel('Mage_Catalog_Model_Product', array('data' => array('website_ids' => array(1, 2))));
$this->assertEquals(array(1, 2), $model->getWebsiteIds());
// fixture
$this->_model->setId(1);
$this->assertEquals(array(1), $this->_model->getWebsiteIds());
}
示例3: tryToPerformWebsiteProductActions
public function tryToPerformWebsiteProductActions(Mage_Catalog_Model_Product $productNew, $isJustAddedProduct, $websiteIdsOld)
{
$websiteIdsNew = $productNew->getWebsiteIds();
if ($isJustAddedProduct) {
$websiteIdsNew[] = 0;
}
$addedWebsiteIds = array_diff($websiteIdsNew, $websiteIdsOld);
foreach ($addedWebsiteIds as $websiteId) {
$this->synchProductWithAddedWebsiteId($productNew, $websiteId);
}
$deletedWebsiteIds = array_diff($websiteIdsOld, $websiteIdsNew);
foreach ($deletedWebsiteIds as $websiteId) {
$this->synchProductWithDeletedWebsiteId($productNew, $websiteId);
}
}
示例4: processCategoriesActions
private function processCategoriesActions(Mage_Catalog_Model_Product $product)
{
$productCategories = $product->getCategoryIds();
$categoriesByWebsite = array(0 => $productCategories);
foreach ($product->getWebsiteIds() as $websiteId) {
$categoriesByWebsite[$websiteId] = $productCategories;
}
/** @var Ess_M2ePro_Model_Listing_Auto_Actions_Mode_Category $autoActionsCategory */
$autoActionsCategory = Mage::getModel('M2ePro/Listing_Auto_Actions_Mode_Category');
$autoActionsCategory->setProduct($product);
foreach ($categoriesByWebsite as $websiteId => $categoryIds) {
foreach ($categoryIds as $categoryId) {
$autoActionsCategory->synchWithAddedCategoryId($categoryId, $websiteId);
}
}
}
示例5: processCategoriesActions
private function processCategoriesActions(Mage_Catalog_Model_Product $magentoProduct)
{
$productCategories = $magentoProduct->getCategoryIds();
$categoriesByWebsite = array(0 => $productCategories);
foreach ($magentoProduct->getWebsiteIds() as $websiteId) {
$categoriesByWebsite[$websiteId] = $productCategories;
}
/** @var Ess_M2ePro_Model_Observer_Category $categoryObserverModel */
$categoryObserverModel = Mage::getModel('M2ePro/Observer_Category');
/** @var Ess_M2ePro_Model_Observer_Ebay_Category $ebayCategoryObserver */
$ebayCategoryObserver = Mage::getModel('M2ePro/Observer_Ebay_Category');
foreach ($categoriesByWebsite as $websiteId => $categoriesIds) {
foreach ($categoriesIds as $categoryId) {
$categoryObserverModel->synchProductWithAddedCategoryId($magentoProduct, $categoryId, $websiteId);
$ebayCategoryObserver->synchProductWithAddedCategoryId($magentoProduct, $categoryId, $websiteId);
}
}
}
示例6: getProductData
/**
* Create Product array from Mage_Catalog_Model_Product
*
* @param Mage_Catalog_Model_Product $product
* @return array
*/
public function getProductData(Mage_Catalog_Model_Product $product)
{
try {
$data = array('url' => $product->getProductUrl(), 'title' => htmlspecialchars($product->getName()), 'spider' => 1, 'price' => $product->getPrice(), 'description' => urlencode($product->getDescription()), 'tags' => htmlspecialchars($product->getMetaKeyword()), 'images' => array(), 'vars' => array('sku' => $product->getSku(), 'storeId' => '', 'typeId' => $product->getTypeId(), 'status' => $product->getStatus(), 'categoryId' => $product->getCategoryId(), 'categoryIds' => $product->getCategoryIds(), 'websiteIds' => $product->getWebsiteIds(), 'storeIds' => $product->getStoreIds(), 'groupPrice' => $product->getGroupPrice(), 'formatedPrice' => $product->getFormatedPrice(), 'calculatedFinalPrice' => $product->getCalculatedFinalPrice(), 'minimalPrice' => $product->getMinimalPrice(), 'specialPrice' => $product->getSpecialPrice(), 'specialFromDate' => $product->getSpecialFromDate(), 'specialToDate' => $product->getSpecialToDate(), 'relatedProductIds' => $product->getRelatedProductIds(), 'upSellProductIds' => $product->getUpSellProductIds(), 'getCrossSellProductIds' => $product->getCrossSellProductIds(), 'isSuperGroup' => $product->isSuperGroup(), 'isGrouped' => $product->isGrouped(), 'isConfigurable' => $product->isConfigurable(), 'isSuper' => $product->isSuper(), 'isSalable' => $product->isSalable(), 'isAvailable' => $product->isAvailable(), 'isVirtual' => $product->isVirtual(), 'isRecurring' => $product->isRecurring(), 'isInStock' => $product->isInStock(), 'weight' => $product->getSku()));
// Add product images
if (self::validateProductImage($product->getImage())) {
$data['images']['full'] = array("url" => $product->getImageUrl());
}
if (self::validateProductImage($product->getSmallImage())) {
$data['images']['smallImage'] = array("url" => $product->getSmallImageUrl($width = 88, $height = 77));
}
if (self::validateProductImage($product->getThumbnail())) {
$data['images']['thumb'] = array("url" => $product->getThumbnailUrl($width = 75, $height = 75));
}
return $data;
return $data;
} catch (Exception $e) {
Mage::logException($e);
}
}
示例7: _saveWebsiteIds
/**
* Save product website relations
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product
*/
protected function _saveWebsiteIds($product)
{
$websiteIds = $product->getWebsiteIds();
$oldWebsiteIds = array();
$product->setIsChangedWebsites(false);
$select = $this->_getWriteAdapter()->select()->from($this->_productWebsiteTable)->where('product_id=?', $product->getId());
$query = $this->_getWriteAdapter()->query($select);
while ($row = $query->fetch()) {
$oldWebsiteIds[] = $row['website_id'];
}
$insert = array_diff($websiteIds, $oldWebsiteIds);
$delete = array_diff($oldWebsiteIds, $websiteIds);
if (!empty($insert)) {
foreach ($insert as $websiteId) {
$this->_getWriteAdapter()->insert($this->_productWebsiteTable, array('product_id' => $product->getId(), 'website_id' => $websiteId));
}
}
if (!empty($delete)) {
foreach ($delete as $websiteId) {
$this->_getWriteAdapter()->delete($this->_productWebsiteTable, array($this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()), $this->_getWriteAdapter()->quoteInto('website_id=?', $websiteId)));
}
}
if (!empty($insert) || !empty($delete)) {
$product->setIsChangedWebsites(true);
}
return $this;
}
示例8: refreshIndex
/**
* Refresh Product Enabled Index
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_Model_Resource_Product
*/
public function refreshIndex($product)
{
$writeAdapter = $this->_getWriteAdapter();
/**
* Ids of all categories where product is assigned (not related with store)
*/
$categoryIds = $product->getCategoryIds();
/**
* Clear previous index data related with product
*/
$condition = array('product_id = ?' => (int) $product->getId());
$writeAdapter->delete($this->getTable('catalog/category_product_index'), $condition);
/** @var $categoryObject Mage_Catalog_Model_Resource_Category */
$categoryObject = Mage::getResourceSingleton('catalog/category');
if (!empty($categoryIds)) {
$categoriesSelect = $writeAdapter->select()->from($this->getTable('catalog/category'))->where('entity_id IN (?)', $categoryIds);
$categoriesInfo = $writeAdapter->fetchAll($categoriesSelect);
$indexCategoryIds = array();
foreach ($categoriesInfo as $categoryInfo) {
$ids = explode('/', $categoryInfo['path']);
$ids[] = $categoryInfo['entity_id'];
$indexCategoryIds = array_merge($indexCategoryIds, $ids);
}
$indexCategoryIds = array_unique($indexCategoryIds);
$indexProductIds = array($product->getId());
$categoryObject->refreshProductIndex($indexCategoryIds, $indexProductIds);
} else {
$websites = $product->getWebsiteIds();
if ($websites) {
$storeIds = array();
foreach ($websites as $websiteId) {
$website = Mage::app()->getWebsite($websiteId);
$storeIds = array_merge($storeIds, $website->getStoreIds());
}
$categoryObject->refreshProductIndex(array(), array($product->getId()), $storeIds);
}
}
/**
* Refresh enabled products index (visibility state)
*/
$this->refreshEnabledIndex(null, $product);
return $this;
}
示例9: isWebsiteAssignedToProduct
/**
* Validate is valid association for website unassignment from product.
* If fails validation, then this method returns false, and
* getErrors() will return an array of errors that explain why the
* validation failed.
*
* @param Mage_Core_Model_Website $website
* @param Mage_Catalog_Model_Product $product
* @return bool
*/
public function isWebsiteAssignedToProduct(Mage_Core_Model_Website $website, Mage_Catalog_Model_Product $product)
{
if (false === array_search($website->getId(), $product->getWebsiteIds())) {
$this->_addError(sprintf('Product #%d isn\'t assigned to website #%d', $product->getId(), $website->getId()));
}
return !count($this->getErrors());
}
示例10: testGetWebsiteIds
public function testGetWebsiteIds()
{
// set
$model = new Mage_Catalog_Model_Product(array('website_ids' => array(1, 2)));
$this->assertEquals(array(1, 2), $model->getWebsiteIds());
// fixture
$this->_model->setId(1);
$this->assertEquals(array(1), $this->_model->getWebsiteIds());
}
示例11: _fillSimpleProductData
/**
* Fill simple product data during generation
*
* @param Mage_Catalog_Model_Product $product
* @param Mage_Catalog_Model_Product $parentProduct
* @param array $postData
*/
protected function _fillSimpleProductData(Mage_Catalog_Model_Product $product, Mage_Catalog_Model_Product $parentProduct, $postData)
{
$product->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)->setTypeId($postData['weight'] ? Mage_Catalog_Model_Product_Type::TYPE_SIMPLE : Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL)->setAttributeSetId($parentProduct->getNewVariationsAttributeSetId());
foreach ($product->getTypeInstance()->getEditableAttributes($product) as $attribute) {
if ($attribute->getIsUnique() || $attribute->getAttributeCode() == 'url_key' || $attribute->getFrontend()->getInputType() == 'gallery' || $attribute->getFrontend()->getInputType() == 'media_image' || !$attribute->getIsVisible()) {
continue;
}
$product->setData($attribute->getAttributeCode(), $parentProduct->getData($attribute->getAttributeCode()));
}
if (!isset($postData['stock_data']['use_config_manage_stock'])) {
$postData['stock_data']['use_config_manage_stock'] = 0;
}
$product->addData($postData)->setWebsiteIds($parentProduct->getWebsiteIds())->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
}
示例12: getWebClassesFromProduct
/**
* getWebClassesFromProduct
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getWebClassesFromProduct($product)
{
$websites = $product->getWebsiteIds();
$websiteClasses = '';
foreach ($websites as $websiteId) {
$websiteClasses .= "website-" . $websiteId . " ";
}
return $websiteClasses;
}
示例13: catalogProductDeleteBefore
/**
* Catalog product validate before delete
*
* @param Mage_Catalog_Model_Product $model
*/
public function catalogProductDeleteBefore($model)
{
// deleting only in exclusive mode
if (!$this->_role->hasExclusiveAccess($model->getWebsiteIds())) {
$this->_throwDelete();
}
}
示例14: _validateProductWebsite
/**
* Check product availability for current website
*
* @param Mage_Catalog_Model_Product $product
* @return bool|string
*/
protected function _validateProductWebsite($product)
{
if (in_array($this->getCurrentStore()->getWebsiteId(), $product->getWebsiteIds())) {
return true;
}
return Mage::app()->getStore()->isAdmin() ? Enterprise_Checkout_Helper_Data::ADD_ITEM_STATUS_FAILED_WEBSITE : Enterprise_Checkout_Helper_Data::ADD_ITEM_STATUS_FAILED_SKU;
}
示例15: _saveWebsiteIds
/**
* Save product website relations
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product
*/
protected function _saveWebsiteIds($product)
{
$ids = $product->getWebsiteIds();
$this->_getWriteAdapter()->delete($this->_productWebsiteTable, $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()));
foreach ($ids as $websiteId) {
$this->_getWriteAdapter()->insert($this->_productWebsiteTable, array('product_id' => $product->getId(), 'website_id' => $websiteId));
}
return $this;
}