本文整理汇总了PHP中Mage_Catalog_Model_Product::getVisibility方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getVisibility方法的具体用法?PHP Mage_Catalog_Model_Product::getVisibility怎么用?PHP Mage_Catalog_Model_Product::getVisibility使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getVisibility方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extractVisibilityValue
/**
* extracts visibility from node list, returning an expected integer or translating an expected string
* into an expected integer, returning null for unexpected values
* @param DOMNodeList $nodes
* @return int|null
*/
public function extractVisibilityValue(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
{
$visibilityValues = ['Not Visible Individually' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE, 'Catalog' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, 'Search' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH, 'Catalog, Search' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH];
$visibility = Mage::helper('eb2ccore')->extractNodeVal($nodes);
if (in_array($visibility, $visibilityValues)) {
// If the value is an expected integer value, return that value
return $visibility;
} elseif (isset($visibilityValues[$visibility])) {
// If the value is an expected string value, return the associated integer
return $visibilityValues[$visibility];
} else {
// If the value is unexpected, return the current value
return $product->getVisibility();
}
}
示例2: testSaveProductsVisibility
/**
* Test if visibility properly saved after import
*
* @magentoDataFixture Mage/Catalog/_files/multiple_products.php
*/
public function testSaveProductsVisibility()
{
$existingProductIds = array(10, 11, 12);
$productsBeforeImport = array();
foreach ($existingProductIds as $productId) {
$product = new Mage_Catalog_Model_Product();
$product->load($productId);
$productsBeforeImport[] = $product;
}
$source = new Mage_ImportExport_Model_Import_Adapter_Csv(__DIR__ . '/_files/products_to_import.csv');
$this->_model->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_REPLACE, 'entity' => 'catalog_product'))->setSource($source)->isDataValid();
$this->_model->importData();
/** @var $productBeforeImport Mage_Catalog_Model_Product */
foreach ($productsBeforeImport as $productBeforeImport) {
/** @var $productAfterImport Mage_Catalog_Model_Product */
$productAfterImport = new Mage_Catalog_Model_Product();
$productAfterImport->load($productBeforeImport->getId());
$this->assertEquals($productBeforeImport->getVisibility(), $productAfterImport->getVisibility());
unset($productAfterImport);
}
unset($productsBeforeImport, $product);
}
示例3: setVisibility
/**
* set visibility
*/
public function setVisibility()
{
$level = null;
$visibility = new Shopgate_Model_Catalog_Visibility();
switch ($this->item->getVisibility()) {
case Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH:
$level = Shopgate_Model_Catalog_Visibility::DEFAULT_VISIBILITY_CATALOG_AND_SEARCH;
break;
case Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG:
$level = Shopgate_Model_Catalog_Visibility::DEFAULT_VISIBILITY_CATALOG;
break;
case Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH:
$level = Shopgate_Model_Catalog_Visibility::DEFAULT_VISIBILITY_SEARCH;
break;
case Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE:
$level = Shopgate_Model_Catalog_Visibility::DEFAULT_VISIBILITY_NOT_VISIBLE;
break;
}
$visibility->setLevel($level);
$visibility->setMarketplace(true);
parent::setVisibility($visibility);
}
示例4: _isObjectIndexable
protected function _isObjectIndexable(Mage_Catalog_Model_Product $object)
{
if ($object->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
return false;
}
if ($object->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG && $object->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) {
return false;
}
return true;
}
示例5: getObject
public function getObject(Mage_Catalog_Model_Product $product)
{
$type = $this->config->getMappedProductType($product->getTypeId());
$this->logger->start('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($product->storeId));
$this->logger->log('Product type (' . $product->getTypeId() . ', mapped to: ' . $type . ')');
$defaultData = array();
$transport = new Varien_Object($defaultData);
Mage::dispatchEvent('algolia_product_index_before', array('product' => $product, 'custom_data' => $transport));
$defaultData = $transport->getData();
$defaultData = is_array($defaultData) ? $defaultData : explode('|', $defaultData);
$visibility = (int) $product->getVisibility();
/** @var Mage_Catalog_Model_Product_Visibility $catalogProductVisibility */
$catalogProductVisibility = Mage::getSingleton('catalog/product_visibility');
$visibleInCatalog = $catalogProductVisibility->getVisibleInCatalogIds();
$visibleInSearch = $catalogProductVisibility->getVisibleInSearchIds();
$customData = array('objectID' => $product->getId(), 'name' => $product->getName(), 'url' => $product->getProductUrl(), 'visibility_search' => (int) in_array($visibility, $visibleInSearch), 'visibility_catalog' => (int) in_array($visibility, $visibleInCatalog));
$additionalAttributes = $this->config->getProductAdditionalAttributes($product->getStoreId());
$groups = null;
if ($this->isAttributeEnabled($additionalAttributes, 'description')) {
$customData['description'] = $product->getDescription();
}
$categories = array();
$categories_with_path = array();
$_categoryIds = $product->getCategoryIds();
if (is_array($_categoryIds) && count($_categoryIds) > 0) {
$categoryCollection = Mage::getResourceModel('catalog/category_collection')->addAttributeToSelect('name')->addAttributeToFilter('entity_id', $_categoryIds)->addFieldToFilter('level', array('gt' => 1))->addIsActiveFilter();
if ($this->config->showCatsNotIncludedInNavigation($product->getStoreId()) == false) {
$categoryCollection->addAttributeToFilter('include_in_menu', '1');
}
$rootCat = Mage::app()->getStore($product->getStoreId())->getRootCategoryId();
/** @var Mage_Catalog_Model_Category $category */
foreach ($categoryCollection as $category) {
// Check and skip all categories that is not
// in the path of the current store.
$path = $category->getPath();
$path_parts = explode('/', $path);
if (isset($path_parts[1]) && $path_parts[1] != $rootCat) {
continue;
}
$categoryName = $category->getName();
if ($categoryName) {
$categories[] = $categoryName;
}
$category->getUrlInstance()->setStore($product->getStoreId());
$path = array();
foreach ($category->getPathIds() as $treeCategoryId) {
$name = $this->getCategoryName($treeCategoryId, $product->getStoreId());
if ($name) {
$path[] = $name;
}
}
$categories_with_path[] = $path;
}
}
if ($this->config->indexWholeCategoryTree($product->getStoreId())) {
foreach ($categories_with_path as $result) {
for ($i = count($result) - 1; $i > 0; $i--) {
$categories_with_path[] = array_slice($result, 0, $i);
}
}
}
$categories_with_path = array_intersect_key($categories_with_path, array_unique(array_map('serialize', $categories_with_path)));
$categories_hierarchical = array();
$mainCategories = array();
$level_name = 'level';
/** @var array $category */
foreach ($categories_with_path as $category) {
$categoriesCount = count($category);
for ($i = 0; $i < $categoriesCount; $i++) {
if (isset($categories_hierarchical[$level_name . $i]) === false) {
$categories_hierarchical[$level_name . $i] = array();
}
$mainCategories[$level_name . $i][] = $category[$i];
if ($this->config->indexWholeCategoryTree($product->getStoreId())) {
$categories_hierarchical[$level_name . $i][] = implode(' /// ', array_slice($category, 0, $i + 1));
} else {
if ($i === $categoriesCount - 1) {
$categories_hierarchical[$level_name . $i][] = implode(' /// ', $category);
}
}
}
}
foreach ($categories_hierarchical as &$level) {
$level = array_values(array_unique($level));
}
foreach ($mainCategories as &$level) {
$level = array_values(array_unique($level));
}
foreach ($categories_with_path as &$category) {
$category = implode(' /// ', $category);
}
$customData['categories'] = $categories_hierarchical;
$customData['categories_without_path'] = $categories;
if ($this->isAttributeEnabled($additionalAttributes, 'main_categories')) {
$customData['main_categories'] = $mainCategories;
}
/** @var Algolia_Algoliasearch_Helper_Image $imageHelper */
$imageHelper = Mage::helper('algoliasearch/image');
if (false === isset($defaultData['thumbnail_url'])) {
/** @var Algolia_Algoliasearch_Helper_Image $thumb */
//.........这里部分代码省略.........
示例6: _getIdToUse
/**
* Get the product ID to use based on Item visibility
*
* @param Mage_Sales_Model_Order_Item $item
* @param Mage_Catalog_Model_Product $itemProduct
* @param boolean $checkVisible
*
* @return int
*/
protected function _getIdToUse(Mage_Sales_Model_Order_Item $item, Mage_Catalog_Model_Product $itemProduct, $checkVisible = true)
{
if ($checkVisible && in_array($itemProduct->getVisibility(), array('2', '4'))) {
return $item->getProductId();
} else {
$superProductConfig = $this->_getSuperProductConfig($item);
if ($superProductConfig && array_key_exists('product_id', $superProductConfig)) {
return $superProductConfig['product_id'];
} elseif (method_exists($item, 'getParentItemId')) {
return $item->getParentItemId();
} else {
return $item->getProductId();
}
}
}
示例7: isProductVisibleInCategories
/**
* @param Mage_Catalog_Model_Product $product
*
* @return bool
*/
public function isProductVisibleInCategories($product)
{
if ($product->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && $product->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH) {
return true;
}
if (Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_IS_EXPORT_STORES)) {
$storesToExport = Mage::helper('shopgate')->getConfig()->getExportStores(true);
foreach ($storesToExport as $storeId) {
$value = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product->getId(), 'visibility', $storeId);
if (in_array($value, array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG))) {
return true;
}
}
}
return false;
}
示例8: __construct
public function __construct(Mage_Catalog_Model_Product $product)
{
$this->id = $product->getId();
$this->sku = $product->getSku();
$this->name = $product->getName();
$statuses = Mage::getModel('catalog/product_status')->getOptionArray();
$this->status = $statuses[$product->getStatus()];
$options = Mage::getModel('catalog/product_visibility')->getOptionArray();
$this->visibility = $options[$product->getVisibility()];
$this->price = (double) number_format($product->getPrice(), 2, '.', '');
$this->specialPrice = (double) number_format($product->getSpecialPrice(), 2, '.', '');
$this->url = $product->getProductUrl();
$this->imagePath = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getSmallImage());
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
$this->stock = (double) number_format($stock->getQty(), 2, '.', '');
$short_description = $product->getShortDescription();
//limit short description
if (strlen($short_description) > 250) {
$short_description = substr($short_description, 0, 250);
}
$this->short_description = $short_description;
//category data
$count = 0;
$categoryCollection = $product->getCategoryCollection()->addNameToResult();
foreach ($categoryCollection as $cat) {
$this->categories[$count]['Id'] = $cat->getId();
$this->categories[$count]['Name'] = $cat->getName();
$count++;
}
//website data
$count = 0;
$websiteIds = $product->getWebsiteIds();
foreach ($websiteIds as $websiteId) {
$website = Mage::app()->getWebsite($websiteId);
$this->websites[$count]['Id'] = $website->getId();
$this->websites[$count]['Name'] = $website->getName();
$count++;
}
//bundle product options
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
$optionCollection = $product->getTypeInstance()->getOptionsCollection();
$selectionCollection = $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
$options = $optionCollection->appendSelections($selectionCollection);
foreach ($options as $option) {
$count = 0;
$title = str_replace(' ', '', $option->getDefaultTitle());
$selections = $option->getSelections();
$sOptions = array();
foreach ($selections as $selection) {
$sOptions[$count]['name'] = $selection->getName();
$sOptions[$count]['sku'] = $selection->getSku();
$sOptions[$count]['id'] = $selection->getProductId();
$sOptions[$count]['price'] = (double) number_format($selection->getPrice(), 2, '.', '');
$count++;
}
$this->{$title} = $sOptions;
}
}
//configurable product options
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
foreach ($productAttributeOptions as $productAttribute) {
$count = 0;
$label = strtolower(str_replace(' ', '', $productAttribute['label']));
$options = array();
foreach ($productAttribute['values'] as $attribute) {
$options[$count]['option'] = $attribute['default_label'];
$options[$count]['price'] = (double) number_format($attribute['pricing_value'], 2, '.', '');
$count++;
}
$this->{$label} = $options;
}
}
}
示例9: isVisibleInidividually
/**
* Is this product visible individually?
*
* @param Mage_Catalog_Model_Product $product
* @return boolean
*/
public function isVisibleInidividually($product)
{
return $product->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
}
示例10: _canRedirect
/**
* Checks that the configurable product exists and can be show to the
* customer
*
* @return bool
*/
protected function _canRedirect()
{
return $this->_product && $this->_product->getId() && $this->_product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_DISABLED && $this->_product->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
}