当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Catalog_Model_Product_Option::getProductOptionCollection方法代码示例

本文整理汇总了PHP中Mage_Catalog_Model_Product_Option::getProductOptionCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product_Option::getProductOptionCollection方法的具体用法?PHP Mage_Catalog_Model_Product_Option::getProductOptionCollection怎么用?PHP Mage_Catalog_Model_Product_Option::getProductOptionCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Catalog_Model_Product_Option的用法示例。


在下文中一共展示了Mage_Catalog_Model_Product_Option::getProductOptionCollection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getProductOptionCollection

 public function getProductOptionCollection(Mage_Catalog_Model_Product $product)
 {
     $action = Mage::app()->getFrontController()->getAction()->getFullActionName();
     if ($action == "catalog_category_view") {
         return parent::getProductOptionCollection($product);
     }
     $helper = Mage::helper('mageworx_customoptions');
     $collection = $this->getCollection()->addFieldToFilter('product_id', $product->getId())->addTitleToResult($product->getStoreId())->addPriceToResult($product->getStoreId())->addViewModeToResult($product->getStoreId())->addDescriptionToResult($product->getStoreId())->addDefaultTextToResult($product->getStoreId())->setOrder('sort_order', 'asc')->setOrder('title', 'asc');
     $isProductEditPage = Mage::app()->getStore()->isAdmin() && Mage::app()->getRequest()->getControllerName() == 'catalog_product';
     if ($isProductEditPage) {
         $collection->addTemplateTitleToResult();
     }
     $collection->addValuesToResult($product->getStoreId());
     if (!$isProductEditPage) {
         // filter by view_mode
         $isRequire = false;
         foreach ($collection as $key => $item) {
             // 0-Disable, 1-Visible, 2-Hidden, 3-Backend, 4-Admin Only
             if ($item->getViewMode() == 0 && !is_null($item->getViewMode())) {
                 $collection->removeItemByKey($key);
             } elseif (!Mage::app()->getStore()->isAdmin() && ($item->getViewMode() == 3 || $item->getViewMode() == 4)) {
                 $collection->removeItemByKey($key);
             } elseif ($item->getIsRequire(true)) {
                 $isRequire = true;
             }
         }
         if (!$isRequire) {
             $product->setRequiredOptions(0);
         }
         if (count($collection) == 0) {
             $product->setHasOptions(0);
         }
         $customerGroupId = $helper->getCustomerGroupId();
         // filter by CustomerGroups
         if ($helper->isCustomerGroupsEnabled()) {
             $isRequire = false;
             foreach ($collection as $key => $item) {
                 $groups = $item->getCustomerGroups();
                 if ($groups !== '' && !in_array($customerGroupId, explode(',', $groups))) {
                     $collection->removeItemByKey($key);
                 } elseif ($item->getIsRequire(true)) {
                     $isRequire = true;
                 }
             }
             if (!$isRequire) {
                 $product->setRequiredOptions(0);
             }
             if (count($collection) == 0) {
                 $product->setHasOptions(0);
             }
         }
         $storeViewId = Mage::app()->getStore()->getId();
         // filter by StoreViews
         if ($helper->isStoreViewsEnabled()) {
             $isRequire = false;
             foreach ($collection as $key => $item) {
                 $storeViews = $item->getStoreViews();
                 if ($storeViews !== '' && !in_array($storeViewId, explode(',', $storeViews))) {
                     $collection->removeItemByKey($key);
                 } elseif ($item->getIsRequire(true)) {
                     $isRequire = true;
                 }
             }
             if (!$isRequire) {
                 $product->setRequiredOptions(0);
             }
             if (count($collection) == 0) {
                 $product->setHasOptions(0);
             }
         }
         // recheck inventory
         if ($product->getRequiredOptions()) {
             if ($helper->isInventoryEnabled() && ($helper->getOutOfStockOptions() == 1 || $helper->isSetProductOutOfStock())) {
                 $isDependentEnabled = $helper->isDependentEnabled();
                 // checkDependentInventory for parent -> set parent option "Out of stock"
                 if ($isDependentEnabled) {
                     foreach ($collection as $option) {
                         if ($this->getGroupByType($option->getType()) != self::OPTION_GROUP_SELECT || count($option->getValues()) == 0) {
                             continue;
                         }
                         foreach ($option->getValues() as $value) {
                             if (!$value->getDependentIds()) {
                                 continue;
                             }
                             $customoptionsQty = $helper->getCustomoptionsQty($value->getCustomoptionsQty(), $value->getSku(), $product->getId(), $value->getExtra(), $value);
                             if ($customoptionsQty !== 0 && !$this->checkDependentInventory($collection, $value, $product)) {
                                 $value->setCustomoptionsQty(0);
                             }
                         }
                     }
                 }
                 // if all required options "Out of stock" -> set product "Out of stock"
                 foreach ($collection as $option) {
                     if (!$option->getIsRequire(true) || $isDependentEnabled && $option->getIsDependent() || $this->getGroupByType($option->getType()) != self::OPTION_GROUP_SELECT || count($option->getValues()) == 0) {
                         continue;
                     }
                     $outOfStockFlag = true;
                     foreach ($option->getValues() as $value) {
                         $customoptionsQty = $helper->getCustomoptionsQty($value->getCustomoptionsQty(), $value->getSku(), $product->getId(), $value->getExtra(), $value);
                         if (is_numeric($customoptionsQty) && $customoptionsQty != 0) {
//.........这里部分代码省略.........
开发者ID:Eximagen,项目名称:pfizer,代码行数:101,代码来源:Option.php


注:本文中的Mage_Catalog_Model_Product_Option::getProductOptionCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。