Пример #1
0
 /**
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 protected function _createProduct(Mage_Catalog_Model_Product $product)
 {
     $brand = null;
     if ($product->hasData('brand')) {
         $brand = $product->getAttributeText('brand');
     }
     $manufacturer = null;
     if ($product->hasData('manufacturer')) {
         $manufacturer = $product->getAttributeText('manufacturer');
     }
     $data = array('id' => $product->getEntityId(), 'productTypeId' => $this->_getProductTypeId($product), 'name' => array($this->_createLocalizedValue($product->getName())), 'shortDescription' => array($this->_createLocalizedValue($product->getShortDescription())), 'description' => array($this->_createLocalizedValue($product->getDescription())), 'GTIN' => $product->hasData('gtin') ? $product->getAttributeText('gtin') : null, 'brand' => !empty($brand) ? array($this->_createLocalizedValue($brand)) : null, 'manufacturer' => !empty($manufacturer) ? array($this->_createLocalizedValue($manufacturer)) : null, 'MPN' => $product->hasData('mpn') ? $product->getAttributeText('mpn') : null, 'MSRP' => $this->_getMsrp($product), 'MAP' => $product->hasData('map') ? $this->_getCurrencyAmount($product->getAttributeText('map')) : null, 'images' => $this->_createImageUrls($product), 'attributes' => $this->_createAttributes($product), 'variationFactors' => $this->_createVariationFactors($product), 'skuList' => $this->_createSkus($product));
     return $data;
 }
Пример #2
0
 /**
  * Check if product has links
  *
  * @param Mage_Catalog_Model_Product $product
  * @return boolean
  */
 public function hasLinks($product)
 {
     if ($product->hasData('links_exist')) {
         return $product->getData('links_exist');
     }
     return count($this->getLinks($product)) > 0;
 }
Пример #3
0
 public function getAdjustmentAmount(Mage_Catalog_Model_Product $product, $default = 0.0)
 {
     $default = round($default, 2);
     if ($product->hasData('lokey_pisa_amount')) {
         $adjustment = round($product->getData('lokey_pisa_amount'), 2);
     } else {
         $adjustment = $default;
     }
     return max($adjustment, 0.0);
 }
Пример #4
0
 /**
  * @param Mage_Catalog_Model_Product $product
  * @return bool
  * @todo
  */
 public function isBundleProductSimple(Mage_Catalog_Model_Product $product)
 {
     if (!$product->hasData('is_bundle_simple')) {
         /** @var Ho_SimpleBundle_Model_Bundle_Product_Type $typeInstance */
         $typeInstance = $product->getTypeInstance(true);
         $optionsCollection = $typeInstance->getOptionsCollection($product);
         $optionsCollection->addFieldToFilter('type', array('neq' => 'fixed'));
         $select = $optionsCollection->getSelect();
         $select->reset('columns');
         $select->columns('type');
         $result = $optionsCollection->getConnection()->fetchCol($select);
         $product->setData('is_bundle_simple', !count($result));
     }
     return $product->getData('is_bundle_simple');
 }
 /**
  * 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);
 }
Пример #6
0
 /**
  * @param Mage_Catalog_Model_Product $product
  *
  * @return $this
  */
 public function loadProductSubscriptionData(Mage_Catalog_Model_Product $product)
 {
     if ($product->hasData('adyen_subscription_data')) {
         return $this;
     }
     /** @var Mage_Catalog_Model_Product $product */
     if ($product->getData('adyen_subscription_type') > 0) {
         $subscriptionCollection = Mage::getResourceModel('adyen_subscription/product_subscription_collection')->addProductFilter($product);
         if (!$product->getStore()->isAdmin()) {
             $subscriptionCollection->addStoreFilter($product->getStore());
         }
         $subscriptionCollection->setOrder('sort_order', 'ASC');
         $product->setData('adyen_subscription_data', $subscriptionCollection);
     } else {
         $product->setData('adyen_subscription_data', null);
     }
     return $this;
 }
Пример #7
0
 /**
  * Resize specified type of image on the product for use in the fallback and returns the image URL
  * or returns the image URL for the specified image path if present
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string $type
  * @param bool $keepFrame
  * @param string $image
  * @param bool $placeholder
  * @return string|bool
  */
 protected function _resizeProductImage($product, $type, $keepFrame, $image = null, $placeholder = false)
 {
     $hasTypeData = $product->hasData($type) && $product->getData($type) != 'no_selection';
     if ($image == 'no_selection') {
         $image = null;
     }
     if ($hasTypeData || $placeholder || $image) {
         $helper = Mage::helper('catalog/image')->init($product, $type, $image)->keepFrame($hasTypeData || $image ? $keepFrame : false);
         $size = Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_BASE_IMAGE_WIDTH);
         if ($type == 'small_image') {
             $size = Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_SMALL_IMAGE_WIDTH);
         }
         if (is_numeric($size)) {
             if ($type == "small_image") {
                 $helper->constrainOnly(true)->resize(500, 500);
             } else {
                 $helper->constrainOnly(true)->resize($size);
             }
         }
         return (string) $helper;
     }
     return false;
 }
Пример #8
0
 /**
  * Retrieve Product Attribute Value
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return string
  */
 public function getProductAttributeValue($product, $attribute)
 {
     if (!$product->hasData($attribute->getAttributeCode())) {
         return ' ';
     }
     if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select', 'boolean', 'multiselect'))) {
         //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
         $value = $attribute->getFrontend()->getValue($product);
     } else {
         $value = $product->getData($attribute->getAttributeCode());
     }
     return $value ? $value : ' ';
 }
Пример #9
0
 /**
  * Retrive bundle selections collection based on used options
  *
  * @param array $optionIds
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_Bundle_Model_Resource_Selection_Collection
  */
 public function getSelectionsCollection($optionIds, $product)
 {
     $keyOptionIds = is_array($optionIds) ? implode('_', $optionIds) : '';
     $key = $this->_keySelectionsCollection . $keyOptionIds;
     if (!$product->hasData($key)) {
         $storeId = $product->getStoreId();
         $selectionsCollection = Mage::getResourceModel('Mage_Bundle_Model_Resource_Selection_Collection')->addAttributeToSelect(Mage::getSingleton('Mage_Catalog_Model_Config')->getProductAttributes())->addAttributeToSelect('tax_class_id')->setFlag('require_stock_items', true)->setFlag('product_children', true)->setPositionOrder()->addStoreFilter($this->getStoreFilter($product))->setStoreId($storeId)->addFilterByRequiredOptions()->setOptionIdsFilter($optionIds);
         if (!Mage::helper('Mage_Catalog_Helper_Data')->isPriceGlobal() && $storeId) {
             $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
             $selectionsCollection->joinPrices($websiteId);
         }
         $product->setData($key, $selectionsCollection);
     }
     return $product->getData($key);
 }
Пример #10
0
 /**
  * Retrieve related products identifiers
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getAssociatedProductIds($product)
 {
     if (!$product->hasData($this->_keyAssociatedProductIds)) {
         $associatedProductIds = array();
         foreach ($this->getAssociatedProducts($product) as $item) {
             $associatedProductIds[] = $item->getId();
         }
         $product->setData($this->_keyAssociatedProductIds, $associatedProductIds);
     }
     return $product->getData($this->_keyAssociatedProductIds);
 }
Пример #11
0
 /**
  * Get product url
  *
  * @param  Mage_Catalog_Model_Product $product
  * @param  bool $useSid
  * @return string
  */
 public function getProductUrl($product, $useSid = null)
 {
     if ($useSid === null) {
         $useSid = Mage::app()->getUseSessionInUrl();
     }
     $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : 0;
     $cacheUrlKey = sprintf('url_%d_%d', $categoryId, $useSid);
     $url = $product->getData($cacheUrlKey);
     if (is_null($url)) {
         if ($product->getStoreId()) {
             $this->getUrlInstance()->setStore($product->getStoreId());
         }
         // auto add SID to URL
         $originalSid = $this->getUrlInstance()->getUseSession();
         if ($originalSid != $useSid) {
             $this->getUrlInstance()->setUseSession($useSid);
         }
         if ($product->hasData('request_path') && $product->getRequestPath() != '') {
             $this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($product->getRequestPath()));
             $this->getUrlInstance()->setUseSession($originalSid);
             return $this->getData($cacheUrlKey);
         }
         Varien_Profiler::start('REWRITE: ' . __METHOD__);
         $rewrite = $this->getUrlRewrite();
         if ($product->getStoreId()) {
             $rewrite->setStoreId($product->getStoreId());
         } else {
             $rewrite->setStoreId(Mage::app()->getStore()->getId());
         }
         $idPath = 'product/' . $product->getId();
         if ($product->getCategoryId() && !$product->getDoNotUseCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
             $idPath .= '/' . $product->getCategoryId();
         }
         $rewrite->loadByIdPath($idPath);
         //echo $this->getUrlInstance()->getBaseUrl();
         if ($rewrite->getId()) {
             $this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($rewrite->getRequestPath()));
             Varien_Profiler::stop('REWRITE: ' . __METHOD__);
             $this->getUrlInstance()->setUseSession($originalSid);
             return $this->getData($cacheUrlKey);
         }
         Varien_Profiler::stop('REWRITE: ' . __METHOD__);
         Varien_Profiler::start('REGULAR: ' . __METHOD__);
         $url = $this->getUrlInstance()->getUrl('catalog/product/view', array('id' => $product->getId(), 's' => $product->getUrlKey(), 'category' => $product->getCategoryId()));
         $this->getUrlInstance()->setUseSession($originalSid);
         Varien_Profiler::stop('REGULAR: ' . __METHOD__);
     }
     return $url;
 }
Пример #12
0
 /**
  * Load matched product rules to the product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return $this
  */
 public function loadProductRules(Mage_Catalog_Model_Product $product)
 {
     if (!$product->hasData('matched_rules')) {
         $product->setMatchedRules($this->getResource()->getProductRuleIds($product->getId()));
     }
     return $this;
 }
Пример #13
0
 protected function _writeOrderProductAttribute(Mage_Catalog_Model_Product $product, XMLWriter $xml, $storeId = null)
 {
     // custom attributes are specified in Admin > Configuration > Sales > Auctane Shipstation API
     // static because attributes can be cached, they do not change during a request
     static $attrs = null;
     if (is_null($attrs)) {
         $attrs = Mage::getResourceModel('eav/entity_attribute_collection');
         $attrIds = explode(',', Mage::getStoreConfig('sales/auctaneapi/customattributes', $storeId));
         $attrs->addFieldToFilter('attribute_id', $attrIds);
     }
     /* @var $attr Mage_Eav_Model_Entity_Attribute */
     foreach ($attrs as $attr) {
         if ($product->hasData($attr->getName())) {
             // if an attribute has options/labels
             if (in_array($attr->getFrontendInput(), array('select', 'multiselect'))) {
                 $value = $product->getAttributeText($attr->getName());
                 if (is_array($value)) {
                     $value = implode(',', $value);
                 }
             } else {
                 $value = $product->getDataUsingMethod($attr->getName());
             }
             // fake an item option
             $option = array('value' => $value, 'label' => $attr->getFrontendLabel());
             $this->_writeOrderItemOption($option, $xml, $storeId);
         }
     }
 }
Пример #14
0
 /**
  * Resize specified type of image on the product for use in the fallback and returns the image URL
  * or returns the image URL for the specified image path if present
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string $type
  * @param bool $keepFrame
  * @param string $image
  * @param bool $placeholder
  * @return string|bool
  */
 protected function _resizeProductImage($product, $type, $keepFrame, $image = null, $placeholder = false, $imgWidth = null, $imgHeight = null)
 {
     $hasTypeData = $product->hasData($type) && $product->getData($type) != 'no_selection';
     if ($image == 'no_selection') {
         $image = null;
     }
     if ($hasTypeData || $placeholder || $image) {
         $helper = Mage::helper('catalog/image')->init($product, $type, $image)->keepFrame($hasTypeData || $image ? $keepFrame : false);
         if ($keepFrame) {
             $helper->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($imgWidth);
         } else {
             if ($imgHeight != null) {
                 $helper->constrainOnly(true)->resize($imgWidth, $imgHeight);
             } else {
                 $helper->constrainOnly(true)->resize($imgWidth);
             }
         }
         return (string) $helper;
     }
     return false;
 }
Пример #15
0
 /**
  * Retrieve array of "subproducts"
  *
  * @param  Mage_Catalog_Model_Product $product
  * @param  array $requiredAttributeIds
  * @return array
  */
 public function getUsedProducts($product, $requiredAttributeIds = null)
 {
     Magento_Profiler::start('CONFIGURABLE:' . __METHOD__);
     if (!$product->hasData($this->_usedProducts)) {
         if (is_null($requiredAttributeIds) and is_null($product->getData($this->_configurableAttributes))) {
             // If used products load before attributes, we will load attributes.
             $this->getConfigurableAttributes($product);
             // After attributes loading products loaded too.
             Magento_Profiler::stop('CONFIGURABLE:' . __METHOD__);
             return $product->getData($this->_usedProducts);
         }
         $usedProducts = array();
         $collection = $this->getUsedProductCollection($product)->addAttributeToSelect('*')->addFilterByRequiredOptions();
         if (is_array($requiredAttributeIds)) {
             foreach ($requiredAttributeIds as $attributeId) {
                 $attribute = $this->getAttributeById($attributeId, $product);
                 if (!is_null($attribute)) {
                     $collection->addAttributeToFilter($attribute->getAttributeCode(), array('notnull' => 1));
                 }
             }
         }
         foreach ($collection as $item) {
             $usedProducts[] = $item;
         }
         $product->setData($this->_usedProducts, $usedProducts);
     }
     Magento_Profiler::stop('CONFIGURABLE:' . __METHOD__);
     return $product->getData($this->_usedProducts);
 }
Пример #16
0
 /**
  * Retrieve media gallery images, depending on config settings
  * - with the possibility not to ignore the excluded ones
  * - with the possibility to ignore the small ones
  *
  * @see Mage_Catalog_Model_Product::getMediaGalleryImages()
  *
  * @param Mage_Catalog_Model_Product $product
  *
  * @return mixed
  */
 protected function _getAllImages($product)
 {
     $images = new Varien_Data_Collection();
     if (!$product->hasData('media_gallery_images') && is_array($product->getMediaGallery('images'))) {
         foreach ($product->getMediaGallery('images') as $image) {
             // ignore disabled images
             if (!Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_EXCLUDED_IMAGES)) {
                 if ($image['disabled']) {
                     continue;
                 }
             }
             $image['url'] = $product->getMediaConfig()->getMediaUrl($image['file']);
             $image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
             $image['path'] = $product->getMediaConfig()->getMediaPath($image['file']);
             // ignore small images
             if (!Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_LOWRES_IMAGES)) {
                 if (file_exists($image['path'])) {
                     list($width, $height) = getimagesize($image['path']);
                     if ($width < self::IMAGE_EXPORT_MINRESOLUTION || $height < self::IMAGE_EXPORT_MINRESOLUTION) {
                         continue;
                     }
                 }
             }
             $images->addItem(new Varien_Object($image));
         }
     }
     return $images;
 }
 /**
  * Resize specified type of image on the product for use in the fallback and returns the image URL
  * or returns the image URL for the specified image path if present
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string $type
  * @param bool $keepFrame
  * @param string $image
  * @param bool $placeholder
  * @return string|bool
  */
 protected function _resizeProductImage($product, $type, $keepFrame, $image = null, $placeholder = false, $width = 900)
 {
     $hasTypeData = $product->hasData($type) && $product->getData($type) != 'no_selection';
     if ($image == 'no_selection') {
         $image = null;
     }
     if ($hasTypeData || $placeholder || $image) {
         return Mage::helper('thememanager/images')->setProductImage($product, $width, $type)->getImageSrc();
     }
     return false;
 }
Пример #18
0
 /**
  * Resize specified type of image on the product for use in the fallback and returns the image URL
  * or returns the image URL for the specified image path if present
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string $type
  * @param bool $keepFrame
  * @param string $image
  * @param bool $placeholder
  * @return string|bool
  */
 protected function _resizeProductImage($product, $type, $keepFrame, $image = null, $placeholder = false, $w = 900)
 {
     $hasTypeData = $product->hasData($type) && $product->getData($type) != 'no_selection';
     if ($image == 'no_selection') {
         $image = null;
     }
     if ($hasTypeData || $placeholder || $image) {
         $helper = Mage::helper('catalog/image')->init($product, $type, $image);
         $config = Mage::getStoreConfig('meigee_harbour_general/productimages');
         if ($config['customAspectRatio'] == 0 && $config['reallyCustomAspectRatio'] !== '') {
             $customAspectRatio = $config['reallyCustomAspectRatio'];
         } else {
             $customAspectRatio = $config['customAspectRatio'];
         }
         if ($customAspectRatio == 999) {
             $helper->keepAspectRatio(TRUE);
             $helper->keepFrame(FALSE);
             $height = NULL;
         } elseif ($customAspectRatio == 333) {
             $helper->keepAspectRatio(TRUE);
             $helper->keepFrame(TRUE);
             $height = NULL;
         } else {
             $helper->keepAspectRatio(FALSE);
             $helper->keepFrame(FALSE);
             $height = $w * $customAspectRatio;
         }
         $size = Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_BASE_IMAGE_WIDTH);
         if ($type == 'small_image') {
             $size = Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_SMALL_IMAGE_WIDTH);
         }
         if (is_numeric($size)) {
             $helper->constrainOnly(true)->resize($w, $height);
         }
         return (string) $helper;
     }
     return false;
 }
Пример #19
0
 /**
  * Retrieve Product Attribute Value
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return string
  */
 public function getProductAttributeValue($product, $attribute)
 {
     if (!$product->hasData($attribute->getAttributeCode())) {
         return Mage::helper('Mage_Catalog_Helper_Data')->__('N/A');
     }
     if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select', 'boolean', 'multiselect'))) {
         //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
         $value = $attribute->getFrontend()->getValue($product);
     } else {
         $value = $product->getData($attribute->getAttributeCode());
     }
     return (string) $value == '' ? Mage::helper('Mage_Catalog_Helper_Data')->__('No') : $value;
 }
Пример #20
0
 /**
  * Check is product available for sale
  *
  * @param Mage_Catalog_Model_Product $product
  * @return bool
  */
 public function isSalable($product)
 {
     $salable = $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
     if ($salable && $product->hasData('is_salable')) {
         $salable = $product->getData('is_salable');
     }
     return (bool) (int) $salable;
 }