public function isPriceSpecial(Mage_Catalog_Model_Product $product) { /* * Check if sale price is activated and if so if sale price is LESS than normal price * I.E., customer might be a Member, so the member price might be less than sale price */ $originalPrice = $product->getPrice(); $finalPrice = $product->getFinalPrice(); if ($finalPrice < $originalPrice) { return self::SPECIAL_PRICE; } /* * check if product is new */ $current_date = time(); // compare date $from_date = $product->getData('news_from_date'); // begin date $to_date = $product->getData('news_to_date'); // end date if ($this->isDateBetween($current_date, $from_date, $to_date)) { return self::NEW_PRODUCT; } return false; }
/** * @param Mage_Catalog_Model_Product $product * @return mixed */ public function getValueByProductInstance(Mage_Catalog_Model_Product $product) { $status = $product->getData('amazon_status'); $variationChildStatuses = $product->getData('variation_child_statuses'); if ($product->getData('is_variation_parent') && !empty($variationChildStatuses)) { $status = json_decode($variationChildStatuses, true); } return $status; }
/** * @param Mage_Catalog_Model_Product $product * @return array|mixed */ public function getValueByProductInstance(Mage_Catalog_Model_Product $product) { $minPrice = $product->getData('min_online_price'); $maxPrice = $product->getData('max_online_price'); if (!empty($minPrice) && !empty($maxPrice) && $minPrice != $maxPrice) { return array($product->getData('min_online_price'), $product->getData('max_online_price')); } return $product->getData('min_online_price'); }
protected function _getObject($field) { $obj = $this->_product; if (isset($field['obj'])) { $obj = $this->_product->getData($field['obj']); // for example, stock_item } return $obj; }
public function beforeProcess() { $product = $this->getEvent()->getProduct(); if (!$product instanceof Mage_Catalog_Model_Product) { throw new Ess_M2ePro_Model_Exception('Product event doesn\'t have correct Product instance.'); } $this->product = $product; $this->productId = (int) $this->product->getId(); $this->storeId = (int) $this->product->getData('store_id'); }
/** * ReIndex UpSells for the product * * @param Mage_Catalog_Model_Product $product */ protected function refreshUpSells(Mage_Catalog_Model_Product $product) { $upSellCollection = $product->getUpSellProductCollection(); if ($upSellCollection->count() > 0) { /** @var \Mage_Index_Model_Indexer $indexer */ $indexer = Mage::getSingleton('index/indexer'); foreach ($upSellCollection as $product) { $indexer->processEntityAction(new Varien_Object(array('id' => $product->getId(), 'store_id' => $product->getStoreId(), 'rule' => $product->getData('rule'), 'from_date' => $product->getData('from_date'), 'to_date' => $product->getData('to_date'))), Enterprise_TargetRule_Model_Index::ENTITY_PRODUCT, Enterprise_TargetRule_Model_Index::EVENT_TYPE_REINDEX_PRODUCTS); } } }
public function getValueByProductInstance(Mage_Catalog_Model_Product $product) { $generalId = $product->getData('general_id'); if (!empty($generalId)) { return Ess_M2ePro_Model_Amazon_Listing_Product::GENERAL_ID_STATE_SET; } if ($product->getData('is_general_id_owner') == 1) { return Ess_M2ePro_Model_Amazon_Listing_Product::GENERAL_ID_STATE_READY_FOR_NEW_ASIN; } $searchStatusActionRequired = Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_ACTION_REQUIRED; $searchStatusNotFound = Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND; if ($product->getData('search_settings_status') == $searchStatusActionRequired || $product->getData('search_settings_status') == $searchStatusNotFound) { return Ess_M2ePro_Model_Amazon_Listing_Product::GENERAL_ID_STATE_ACTION_REQUIRED; } return Ess_M2ePro_Model_Amazon_Listing_Product::GENERAL_ID_STATE_NOT_SET; }
/** * 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; }
public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null) { $data = array(); $data['store_id'] = $attribute->getStoreId(); $data['entity_id'] = $object->getId(); $data['attribute_id'] = $attribute->getId(); $result = array(); $values = $object->getData($attribute->getAttributeCode()); if (!is_array($values)) { return $result; } foreach ($values as $row) { if (isset($row['delete']) && $row['delete']) { continue; } $data['qty'] = $row['price_qty']; $data['value'] = $row['price']; if ($row['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL) { foreach ($this->_customerGroups as $group) { $data['customer_group_id'] = $group->getId(); $result[] = $data; } } else { $data['customer_group_id'] = $row['cust_group']; $result[] = $data; } } return $result; }
/** * After attribute is saved upload file to media * folder and save it to its associated product. * * @param Mage_Catalog_Model_Product $object * @return Jvs_FileAttribute_Model_Attribute_Backend_File */ public function afterSave($object) { $value = $object->getData($this->getAttribute()->getName()); if (is_array($value) && !empty($value['delete'])) { $object->setData($this->getAttribute()->getName(), ''); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); return; } try { $uploadedFile = new Varien_Object(); $uploadedFile->setData('name', $this->getAttribute()->getName()); $uploadedFile->setData('allowed_extensions', array('jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'mpg', 'mpeg', 'mp3', 'wav', 'pdf', 'txt')); Mage::dispatchEvent('jvs_fileattribute_allowed_extensions', array('file' => $uploadedFile)); $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName()); $uploader->setAllowedExtensions($uploadedFile->getData('allowed_extensions')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); $uploader->save(Mage::getBaseDir('media') . '/catalog/product'); } catch (Exception $e) { return $this; } $fileName = $uploader->getUploadedFileName(); if ($fileName) { $object->setData($this->getAttribute()->getName(), $fileName); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } return $this; }
/** * After Save Attribute manipulation * * @param Mage_Catalog_Model_Product $object * @return Mage_Catalog_Model_Product_Attribute_Backend_Price */ public function afterSave($object) { $value = $object->getData($this->getAttribute()->getAttributeCode()); /** * Orig value is only for existing objects */ $oridData = $object->getOrigData(); $origValueExist = $oridData && array_key_exists($this->getAttribute()->getAttributeCode(), $oridData); if ($object->getStoreId() != 0 || !$value || $origValueExist) { return $this; } if ($this->getAttribute()->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE) { $baseCurrency = Mage::app()->getBaseCurrencyCode(); $storeIds = $object->getStoreIds(); if (is_array($storeIds)) { foreach ($storeIds as $storeId) { $storeCurrency = Mage::app()->getStore($storeId)->getBaseCurrencyCode(); if ($storeCurrency == $baseCurrency) { continue; } $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($storeCurrency); if (!$rate) { $rate = 1; } $newValue = $value * $rate; $object->addAttributeUpdate($this->getAttribute()->getAttributeCode(), $newValue, $storeId); } } } return $this; }
/** * get the longest url for a product * from http://magento.stackexchange.com/questions/52969/get-product-path-from-id-with-category-path-in-url * @param Mage_Catalog_Model_Product|null $product [description] * @return String full url of the product */ public static function getFullProductUrl(Mage_Catalog_Model_Product $product = null) { // Force display deepest child category as request path. $categories = $product->getCategoryCollection(); $deepCatId = 0; $path = ''; $productPath = false; foreach ($categories as $category) { // Look for the deepest path and save. if (substr_count($category->getData('path'), '/') > substr_count($path, '/')) { $path = $category->getData('path'); $deepCatId = $category->getId(); } } // Load category. $category = Mage::getModel('catalog/category')->load($deepCatId); // Remove .html from category url_path. $categoryPath = str_replace('.html', '', $category->getData('url_path')); // Get product url path if set. $productUrlPath = $product->getData('url_path'); // Get product request path if set. $productRequestPath = $product->getData('request_path'); // If URL path is not found, try using the URL key. if ($productUrlPath === null && $productRequestPath === null) { $productUrlPath = $product->getData('url_key'); } // Now grab only the product path including suffix (if any). if ($productUrlPath) { $path = explode('/', $productUrlPath); $productPath = array_pop($path); } elseif ($productRequestPath) { $path = explode('/', $productRequestPath); $productPath = array_pop($path); } // Now set product request path to be our full product url including deepest category url path. if ($productPath !== false) { if ($categoryPath) { // Only use the category path is one is found. $product->setData('request_path', $categoryPath . '/' . $productPath); } else { $product->setData('request_path', $productPath); } } return $product->getProductUrl(); }
/** * Implode data for validation * * @param Mage_Catalog_Model_Product $object * @return bool */ public function validate($object) { $attributeCode = $this->getAttribute()->getAttributeCode(); $data = $object->getData($attributeCode); if (is_array($data)) { $object->setData($attributeCode, implode(',', array_filter($data))); } return parent::validate($object); }
/** * Retrieve url for adding product to conpare list * * @param Mage_Catalog_Model_Product $product * @return string */ public function getAddUrl($product) { $config = Mage::getStoreConfig('advancedcompare/general'); if ($config['removecompare'] || $config['removelink'] && (bool) $product->getData('remove_compare_link')) { return false; } else { return parent::getAddUrl($product); } }
/** * @param Mage_Catalog_Model_Product $product * @return bool */ protected function matchProduct($product) { foreach ($this->requestConfigurableMap as $code => $values) { if (!in_array($product->getData($code), $values)) { return false; } } return true; }
private static function getProductTaxRate(Mage_Catalog_Model_Product $product) { /** @var Mage_Tax_Model_Calculation $taxCalculation */ $taxCalculation = Mage::getSingleton('tax/calculation'); $store = Mage::app()->getStore(); $request = $taxCalculation->getRateRequest(null, null, null, $store); $taxClassId = $product->getData('tax_class_id'); return $taxCalculation->getRate($request->setProductClassId($taxClassId)); }
/** * Check if product is configurable * * @param Mage_Catalog_Model_Product $product * @return bool */ public function canConfigure($product = null) { if (isset($product->getAttributes()['adyen_subscription_type'])) { if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) { return true; } } return false; }
/** * Before attribute save prepare data * * @param Mage_Catalog_Model_Product $object * @return Enterprise_TargetRule_Model_Catalog_Product_Attribute_Backend_Rule */ public function beforeSave($object) { $attributeName = $this->getAttribute()->getName(); $useDefault = $object->getData($attributeName . '_default'); if ($useDefault == 1) { $object->setData($attributeName, null); } return $this; }
public function getValueByProductInstance(Mage_Catalog_Model_Product $product) { $endDate = $product->getData('end_date'); if (empty($endDate)) { return null; } $endDate = new DateTime($endDate); return strtotime($endDate->format('Y-m-d')); }
/** * Add image to media gallery and return new filename * * @param Mage_Catalog_Model_Product $product * @param string $file file path of image in file system * @param string|array $mediaAttribute code of attribute with type 'media_image', * leave blank if image should be only in gallery * @param boolean $move if true, it will move source file * @param boolean $exclude mark image as disabled in product page view * @return string */ public function addImage(Mage_Catalog_Model_Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true) { if (!Mage::helper('uaudio_storage')->isEnabled()) { return parent::addImage(product, $file, $mediaAttribute, $move, $exclude); } $file = realpath($file); if (!$file || !file_exists($file)) { Mage::throwException(Mage::helper('catalog')->__('Image does not exist.')); } Mage::dispatchEvent('catalog_product_media_add_image', array('product' => $product, 'image' => $file)); $pathinfo = pathinfo($file); $imgExtensions = array('jpg', 'jpeg', 'gif', 'png'); if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), $imgExtensions)) { Mage::throwException(Mage::helper('catalog')->__('Invalid image file type.')); } $fileName = Mage_Core_Model_File_Uploader::getCorrectFileName($pathinfo['basename']); $dispretionPath = Mage_Core_Model_File_Uploader::getDispretionPath($fileName); $fileName = $dispretionPath . DS . $fileName; $dest = $this->_getConfig()->getTmpMediaPath($fileName); $storageModel = Mage::getSingleton('core/file_storage')->getStorageModel(); $storageModel->setAllowRenameFiles(true); try { if ($move) { $uploadDestination = $storageModel->moveFile($file, $dest); } else { $uploadDestination = $storageModel->moveUploadFile($file, $dest); } if (!$uploadDestination) { throw new Exception(); } $fileName = basename($uploadDestination); $dispretionPath = Mage_Core_Model_File_Uploader::getDispretionPath($fileName); $fileName = $dispretionPath . DS . $fileName; } catch (Exception $e) { Mage::throwException(Mage::helper('catalog')->__('Failed to move file: %s', $e->getMessage())); } $fileName = str_replace(DS, '/', $fileName); $attrCode = $this->getAttribute()->getAttributeCode(); $mediaGalleryData = $product->getData($attrCode); $position = 0; if (!is_array($mediaGalleryData)) { $mediaGalleryData = array('images' => array()); } foreach ($mediaGalleryData['images'] as &$image) { if (isset($image['position']) && $image['position'] > $position) { $position = $image['position']; } } $position++; $mediaGalleryData['images'][] = array('file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude); $product->setData($attrCode, $mediaGalleryData); if (!is_null($mediaAttribute)) { $this->setMediaAttribute($product, $mediaAttribute, $fileName); } return $fileName; }
/** * Converts image to api array data * * @param array $image * @param Mage_Catalog_Model_Product $product * @return array */ protected function _imageToArray(&$image, $product) { $result = array('file' => $image['file'], 'label' => $image['label'], 'position' => $image['position'], 'exclude' => $image['disabled'], 'cgimage' => $image['cgimage'], 'url' => $this->_getMediaConfig()->getMediaUrl($image['file']), 'types' => array()); foreach ($product->getMediaAttributes() as $attribute) { if ($product->getData($attribute->getAttributeCode()) == $image['file']) { $result['types'][] = $attribute->getAttributeCode(); } } return $result; }
/** * @param Mage_Catalog_Model_Product $product * @return Adyen_Subscription_Model_Subscription_Item|false */ public function getSubscriptionItem($product) { if ($subscriptionItemId = $product->getData('is_created_from_subscription_item')) { $subscriptionItem = Mage::getModel('adyen_subscription/subscription_item')->load($subscriptionItemId); if ($subscriptionItem->getId()) { return $subscriptionItem; } } return false; }
public function testSetUsedProductAttributeIds() { $testConfigurable = $this->_getAttributeByCode('test_configurable'); $this->assertEmpty($this->_product->getData('_cache_instance_configurable_attributes')); $this->_model->setUsedProductAttributeIds(array($testConfigurable->getId()), $this->_product); $attributes = $this->_product->getData('_cache_instance_configurable_attributes'); $this->assertArrayHasKey(0, $attributes); $this->assertInstanceOf('Mage_Catalog_Model_Product_Type_Configurable_Attribute', $attributes[0]); $this->assertSame($testConfigurable, $attributes[0]->getProductAttribute()); }
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); }
/** * Returns url to product image * * @param Mage_Catalog_Model_Product $product * @return string|false */ public function getUrl($product) { $image = $product->getData($this->getAttribute()->getAttributeCode()); if ($image) { $url = Mage::app()->getStore($product->getStore())->getBaseUrl('media') . 'catalog/product/' . $image; } else { $url = false; } return $url; }
/** * return a boolean value based off the product's is_retired attribute * * @var Mage_Catalog_Model_Product $product * @return bool * @author Josh Johnson (August Ash, Inc.) */ protected function _isRetired(Mage_Catalog_Model_Product $product) { $retired = false; try { $retired = $product->getData('is_retired'); } catch (Exception $e) { Mage::log('FROM CLASS ' . __CLASS__ . ' IN FILE ' . __FILE__ . ' AT LINE ' . __LINE__); Mage::log($e->getMessage()); } return $retired; }
/** * Prepare inventory data from custom attribute * * @param Mage_Catalog_Model_Product $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract|void */ public function beforeSave($object) { $stockData = $object->getData($this->getAttribute()->getAttributeCode()); if (isset($stockData['qty']) && $stockData['qty'] === '') { $stockData['qty'] = null; } if ($object->getStockData() !== null || $stockData !== null) { $object->setStockData(array_replace((array) $object->getStockData(), (array) $stockData)); } $object->unsetData($this->getAttribute()->getAttributeCode()); parent::beforeSave($object); }
/** * Load and set gift card amounts into product object * * @param Mage_Catalog_Model_Product $product */ public function getAmounts($product) { $allGroups = Mage_Customer_Model_Group::CUST_GROUP_ALL; $prices = $product->getData('giftcard_amounts'); if (is_null($prices)) { if ($attribute = $product->getResource()->getAttribute('giftcard_amounts')) { $attribute->getBackend()->afterLoad($product); $prices = $product->getData('giftcard_amounts'); } } return $prices ? $prices : array(); }
/** * @param Mage_Catalog_Model_Product $product * @param $productSubscriptionsData * @param $storeId * @throws Exception */ protected function _updateProductSubscriptions(Mage_Catalog_Model_Product $product, $productSubscriptionsData, $storeId) { if (!$productSubscriptionsData) { if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) { $product->setData('adyen_subscription_type', Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED); Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('adyen_subscription')->__('Adyen Subscription Type is set back to \'Disabled\' because no subscriptions were defined')); } return; } /** @var array $productSubscriptionIds */ $productSubscriptionCollection = Mage::getModel('adyen_subscription/product_subscription')->getCollection()->addFieldToFilter('product_id', $product->getId()); $isGlobal = Mage::app()->isSingleStoreMode(); if (!$isGlobal && (int) $storeId) { /** @var $website Mage_Core_Model_Website */ $website = Mage::app()->getStore($storeId)->getWebsite(); $productSubscriptionCollection->addFieldToFilter('website_id', $website->getId()); } $productSubscriptionIds = $productSubscriptionCollection->getAllIds(); $resource = Mage::getSingleton('core/resource'); $connection = $resource->getConnection('core_write'); $i = 1; // Save subscriptions foreach ($productSubscriptionsData as $id => $subscriptionData) { $subscription = Mage::getModel('adyen_subscription/product_subscription')->load($id); if (!$subscription->getId()) { $subscription->setProductId($product->getId()); } if (!isset($subscriptionData['use_default']) && $storeId) { // Save store label $labelData = array('label' => $subscriptionData['label'], 'subscription_id' => $subscription->getId(), 'store_id' => $storeId); $connection->insertOnDuplicate($resource->getTableName('adyen_subscription/product_subscription_label'), $labelData, array('label')); unset($subscriptionData['label']); } if (isset($subscriptionData['use_default']) && $storeId) { // Delete store label $connection->delete($resource->getTableName('adyen_subscription/product_subscription_label'), array('subscription_id = ?' => $subscription->getId(), 'store_id = ?' => $storeId)); } if ($subscriptionData['customer_group_id'] == '') { $subscriptionData['customer_group_id'] = null; } $subscription->addData($subscriptionData); $subscription->setSortOrder($i * 10); if (in_array($id, $productSubscriptionIds)) { $productSubscriptionIds = array_diff($productSubscriptionIds, array($id)); } $subscription->save(); $i++; } // Delete subscriptions foreach ($productSubscriptionIds as $subscriptionId) { Mage::getModel('adyen_subscription/product_subscription')->setId($subscriptionId)->delete(); } }
public function getValueByProductInstance(Mage_Catalog_Model_Product $product) { $onlineCategory = $product->getData('online_category'); if (empty($onlineCategory)) { return null; } preg_match('/^(.+)\\(\\d+\\)$/x', $onlineCategory, $matches); if (empty($matches[1])) { return null; } return trim($matches[1]); }