public function createIndexData(Mage_Catalog_Model_Product $object)
 {
     $searchEntityId = $object->getId();
     $priceAttributeId = $this->getTierPriceAttribute()->getId();
     if ($object->isGrouped()) {
         $priceAttributeId = $this->getPriceAttribute()->getId();
         $associated = $object->getTypeInstance()->getAssociatedProducts();
         $searchEntityId = array();
         foreach ($associated as $product) {
             $searchEntityId[] = $product->getId();
         }
     }
     if (!count($searchEntityId)) {
         return false;
     }
     $result = array();
     $data = array();
     $data['store_id'] = $object->getStoreId();
     $data['entity_id'] = $object->getId();
     $search['store_id'] = $object->getStoreId();
     $search['entity_id'] = $searchEntityId;
     $search['attribute_id'] = $priceAttributeId;
     foreach ($this->_customerGroups as $group) {
         $search['customer_group_id'] = $group->getId();
         $data['customer_group_id'] = $group->getId();
         $value = $this->_getResource()->getMinimalValue($search);
         if (is_null($value)) {
             continue;
         }
         $data['value'] = $value;
         $result[] = $data;
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Varien_Gdata_Gshopping_Entry $entry
  * @return Varien_Gdata_Gshopping_Entry
  */
 public function convertAttribute($product, $entry)
 {
     $entry->cleanTaxes();
     if (Mage::helper('tax')->getConfig()->priceIncludesTax()) {
         return $entry;
     }
     $calc = Mage::helper('tax')->getCalculator();
     $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId());
     $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId());
     $targetCountry = Mage::getSingleton('googleshopping/config')->getTargetCountry($product->getStoreId());
     $ratesTotal = 0;
     foreach ($rates as $rate) {
         if ($targetCountry == $rate['country']) {
             $regions = $this->_parseRegions($rate['state'], $rate['postcode']);
             $ratesTotal += count($regions);
             if ($ratesTotal > self::RATES_MAX) {
                 Mage::throwException(Mage::helper('googleshopping')->__("Google shopping only supports %d tax rates per product", self::RATES_MAX));
             }
             foreach ($regions as $region) {
                 $entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => $region));
             }
         }
     }
     return $entry;
 }
Esempio n. 3
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     $url = $product->getProductUrl(false);
     if ($url) {
         $config = Mage::getSingleton('googleshoppingapi/config');
         if (!Mage::getStoreConfigFlag('web/url/use_store') && $config->getAddStoreCodeToUrl()) {
             Mage::log($config->getAddStoreCodeToUrl() ? "true" : "false");
             $urlInfo = parse_url($url);
             $store = $product->getStore()->getCode();
             if (isset($urlInfo['query']) && $urlInfo['query'] != '') {
                 $url .= '&___store=' . $store;
             } else {
                 $url .= '?___store=' . $store;
             }
         }
         if ($config->getAddUtmSrcGshopping($product->getStoreId())) {
             $url .= '&utm_source=GoogleShopping';
         }
         if ($customUrlParameters = $config->getCustomUrlParameters($product->getStoreId())) {
             $url .= $customUrlParameters;
         }
         $shoppingProduct->setLink($url);
     }
     return $shoppingProduct;
 }
Esempio n. 4
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Varien_Gdata_Gshopping_Entry $entry
  * @return Varien_Gdata_Gshopping_Entry
  */
 public function convertAttribute($product, $entry)
 {
     $config = Mage::getSingleton('Mage_GoogleShopping_Model_Config');
     $targetCountry = $config->getTargetCountry($product->getStoreId());
     $value = $config->getCountryInfo($targetCountry, 'language', $product->getStoreId());
     return $this->_setAttribute($entry, 'content_language', self::ATTRIBUTE_TYPE_TEXT, $value);
 }
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     $config = Mage::getSingleton('googleshoppingapi/config');
     $targetCountry = $config->getTargetCountry($product->getStoreId());
     $value = $config->getCountryInfo($targetCountry, 'language', $product->getStoreId());
     $shoppingProduct->setContentLanguage($value);
 }
Esempio n. 6
0
 /**
  * Load product tier prices
  *
  * @deprecated since 1.3.2.3
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return array
  */
 public function loadProductPrices($product, $attribute)
 {
     $websiteId = null;
     if ($attribute->isScopeGlobal()) {
         $websiteId = 0;
     } else {
         if ($product->getStoreId()) {
             $websiteId = Mage::app()->getStore($product->getStoreId())->getWebsiteId();
         }
     }
     return $this->loadPriceData($product->getId(), $websiteId);
 }
Esempio n. 7
0
 /**
  * Get product url
  *
  * @param  Mage_Catalog_Model_Product $product
  * @param  bool $useSid
  * @return string
  */
 public function getProductUrl($product, $useSid = true)
 {
     $cacheUrlKey = 'url_' . ($product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : 'NONE') . '_' . intval($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();
         $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);
         }
         if (VPROF) {
             Varien_Profiler::start('REWRITE: ' . __METHOD__);
         }
         $rewrite = $this->getUrlRewrite();
         if ($product->getStoreId()) {
             $rewrite->setStoreId($product->getStoreId());
         } else {
             $rewrite->setStoreId(AO::app()->getStore()->getId());
         }
         $idPath = 'product/' . $product->getId();
         if ($product->getCategoryId() && !$product->getDoNotUseCategoryId() && AO::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()));
             if (VPROF) {
                 Varien_Profiler::stop('REWRITE: ' . __METHOD__);
             }
             $this->getUrlInstance()->setUseSession($originalSid);
             return $this->getData($cacheUrlKey);
         }
         if (VPROF) {
             Varien_Profiler::stop('REWRITE: ' . __METHOD__);
         }
         if (VPROF) {
             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);
         if (VPROF) {
             Varien_Profiler::stop('REGULAR: ' . __METHOD__);
         }
     }
     return $url;
 }
Esempio n. 8
0
 /**
  * Get items which are available for update/delete when product is saved
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_GoogleShopping_Model_Resource_Item_Collection
  */
 protected function _getItemsCollection($product)
 {
     $items = Mage::getResourceModel('Mage_GoogleShopping_Model_Resource_Item_Collection')->addProductFilterId($product->getId());
     if ($product->getStoreId()) {
         $items->addStoreFilter($product->getStoreId());
     }
     foreach ($items as $item) {
         if (!Mage::getStoreConfigFlag('google/googleshopping/observed', $item->getStoreId())) {
             $items->removeItemByKey($item->getId());
         }
     }
     return $items;
 }
Esempio n. 9
0
 /**
  * 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;
 }
 /**
  * @param Mage_Catalog_Model_Product $productModel
  * @return Ess_M2ePro_Model_Magento_Product
  */
 public function setProduct(Mage_Catalog_Model_Product $productModel)
 {
     $this->_productModel = $productModel;
     $this->setProductId($this->_productModel->getId());
     $this->setStoreId($this->_productModel->getStoreId());
     return $this;
 }
Esempio n. 11
0
 public function setProduct(Mage_Catalog_Model_Product $product)
 {
     $store = Mage::app()->getStore($product->getStoreId());
     $product->setStore($store);
     $this->_product = $product;
     return $this;
 }
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     $destInfo = Mage::getSingleton('googleshoppingapi/config')->getDestinationsInfo($product->getStoreId());
     //         $shoppingProduct->setDestinationsMode($destInfo);
     // TODO: implement support for destinations
     //array(3) { ["ProductSearch"]=> NULL ["ProductAds"]=> NULL ["CommerceSearch"]=> NULL }
     return $shoppingProduct;
 }
Esempio n. 13
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Varien_Gdata_Gshopping_Entry $entry
  * @return Varien_Gdata_Gshopping_Entry
  */
 public function convertAttribute($product, $entry)
 {
     $entry->cleanTaxes();
     if (Mage::helper('Mage_Tax_Helper_Data')->getConfig()->priceIncludesTax()) {
         return $entry;
     }
     $calc = Mage::helper('Mage_Tax_Helper_Data')->getCalculator();
     $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId());
     $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId());
     $targetCountry = Mage::getSingleton('Mage_GoogleShopping_Model_Config')->getTargetCountry($product->getStoreId());
     foreach ($rates as $rate) {
         if ($targetCountry == $rate['country']) {
             $entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => empty($rate['state']) ? '*' : $rate['state']));
         }
     }
     return $entry;
 }
 /**
  * Load gallery images for product
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object
  * @return array
  */
 public function loadGallery($product, $object)
 {
     // Select gallery images for product
     $select = $this->_getReadAdapter()->select()->from(array('main' => $this->getMainTable()), array('value_id', 'value AS file'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=value.value_id AND value.store_id=' . (int) $product->getStoreId(), array('label', 'position', 'disabled'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=default_value.value_id AND default_value.store_id=0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled'))->where('main.attribute_id = ?', $object->getAttribute()->getId())->where('main.entity_id = ?', $product->getId())->order('IF(value.position IS NULL, default_value.position, value.position) ASC');
     $result = $this->_getReadAdapter()->fetchAll($select);
     $this->_removeDuplicates($result);
     return $result;
 }
Esempio n. 15
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Varien_Gdata_Gshopping_Entry $entry
  * @return Varien_Gdata_Gshopping_Entry
  */
 public function convertAttribute($product, $entry)
 {
     $targetCountry = Mage::getSingleton('Mage_GoogleShopping_Model_Config')->getTargetCountry($product->getStoreId());
     $value = Mage::getModel('Mage_GoogleShopping_Model_Type')->loadByAttributeSetId($product->getAttributeSetId(), $targetCountry);
     $val = $value->getCategory() == Mage_GoogleShopping_Helper_Category::CATEGORY_OTHER ? '' : $value->getCategory();
     $this->_setAttribute($entry, 'google_product_category', self::ATTRIBUTE_TYPE_TEXT, htmlspecialchars_decode($val, ENT_NOQUOTES));
     return $entry;
 }
Esempio n. 16
0
 /**
  * Load video gallery for product
  *
  * @param Mage_Catalog_Model_Product $product
  * @param IcebergCommerce_VideoGallery_Model_Backend_Video $object
  * @return array
  */
 public function loadGallery($product, $object)
 {
     $attribute = $object ? $object->getAttribute() : Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product', 'video_gallery');
     // Select gallery images for product
     $select = $this->_getReadAdapter()->select()->from(array('main' => $this->getTable(self::GALLERY_TABLE)), array('value_id', 'thumbnail AS file', 'value', 'provider'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=value.value_id AND value.store_id=' . (int) $product->getStoreId(), array('label', 'position', 'disabled', 'description'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id=default_value.value_id AND default_value.store_id=0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled', 'description_default' => 'description'))->where('main.attribute_id = ?', $attribute->getId())->where('main.entity_id = ?', $product->getId())->order('IF(value.position IS NULL, default_value.position, value.position) ASC');
     $result = $this->_getReadAdapter()->fetchAll($select);
     $this->_removeDuplicates($result);
     return $result;
 }
Esempio n. 17
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     $parentId = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
     $parentItem = Mage::getModel('catalog/product')->load($parentId);
     $cCatId = array_reverse($childItem->getCategoryIds());
     $pCatId = array_reverse($parentItem->getCategoryIds());
     $cCat = Mage::getModel('catalog/category')->load($cCatId[0]);
     $pCat = Mage::getModel('catalog/category')->load($pCatId[0]);
     $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
     if (!Mage::getStoreConfig('web/seo/use_rewrites')) {
         if ($product->getTypeId() == 'simple' && $parentItem->getTypeId() == 'configurable' || 'bundle' || 'grouped') {
             $url = $parentItem->getProductUrl(false);
         } else {
             $url = $childItem->getProductUrl(false);
         }
     } else {
         if ($product->getTypeId() == 'simple' && $parentItem->getTypeId() == 'configurable' || 'bundle' || 'grouped') {
             $url = "{$baseUrl}{$parentItem->getUrlPath($pCat)}";
         } else {
             $url = "{$baseUrl}{$product->getUrlPath($cCat)}";
         }
     }
     if ($url) {
         $config = Mage::getSingleton('googleshoppingapi/config');
         if (!Mage::getStoreConfigFlag('web/url/use_store') && $config->getAddStoreCodeToUrl()) {
             Mage::log($config->getAddStoreCodeToUrl() ? "true" : "false");
             $urlInfo = parse_url($url);
             $store = $product->getStore()->getCode();
             if (isset($urlInfo['query']) && $urlInfo['query'] != '') {
                 $url .= '&___store=' . $store;
             } else {
                 $url .= '?___store=' . $store;
             }
         }
         if ($config->getAddUtmSrcGshopping($product->getStoreId())) {
             $url .= '&utm_source=GoogleShopping';
         }
         if ($customUrlParameters = $config->getCustomUrlParameters($product->getStoreId())) {
             $url .= $customUrlParameters;
         }
         $shoppingProduct->setLink($url);
     }
     return $shoppingProduct;
 }
Esempio n. 18
0
 /**
  * Load gallery images for product
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object
  * @return array
  */
 public function loadGallery($product, $object)
 {
     $adapter = $this->_getReadAdapter();
     $positionCheckSql = $adapter->getCheckSql('value.position IS NULL', 'default_value.position', 'value.position');
     // Select gallery images for product
     $select = $adapter->select()->from(array('main' => $this->getMainTable()), array('value_id', 'value AS file'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), $adapter->quoteInto('main.value_id = value.value_id AND value.store_id = ?', (int) $product->getStoreId()), array('label', 'position', 'disabled'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id = default_value.value_id AND default_value.store_id = 0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled'))->where('main.attribute_id = ?', $object->getAttribute()->getId())->where('main.entity_id = ?', $product->getId())->order($positionCheckSql . ' ' . Varien_Db_Select::SQL_ASC);
     $result = $adapter->fetchAll($select);
     $this->_removeDuplicates($result);
     return $result;
 }
 /**
  * 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);
         }
     }
 }
Esempio n. 20
0
 /**
  * Load product tier prices
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return array
  */
 public function loadProductPrices($product, $attribute)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), array('website_id', 'all_groups', 'cust_group' => 'customer_group_id', 'price_qty' => 'qty', 'price' => 'value'))->where('entity_id=?', $product->getId())->order('qty');
     if ($attribute->isScopeGlobal()) {
         $select->where('website_id=?', 0);
     } else {
         if ($storeId = $product->getStoreId()) {
             $select->where('website_id IN (?)', array(0, Mage::app()->getStore($storeId)->getWebsiteId()));
         }
     }
     return $this->_getReadAdapter()->fetchAll($select);
 }
Esempio n. 21
0
 /**
  * Delete product data
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @return Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax
  */
 public function deleteProductData($product, $attribute)
 {
     $where = array('entity_id = ?' => (int) $product->getId(), 'attribute_id = ?' => (int) $attribute->getId());
     $adapter = $this->_getWriteAdapter();
     if (!$attribute->isScopeGlobal()) {
         $storeId = $product->getStoreId();
         if ($storeId) {
             $where['website_id IN(?)'] = array(0, Mage::app()->getStore($storeId)->getWebsiteId());
         }
     }
     $adapter->delete($this->getMainTable(), $where);
     return $this;
 }
Esempio n. 22
0
 /**
  * Load Url rewrite by specified product
  *
  * @param Mage_Core_Model_Abstract $object
  * @param Mage_Catalog_Model_Product $product
  * @return Enterprise_Catalog_Model_Resource_Product
  */
 public function loadByProduct(Mage_Core_Model_Abstract $object, Mage_Catalog_Model_Product $product)
 {
     $idField = $this->_getReadAdapter()->getIfNullSql('url_rewrite_cat.id', 'default_urc.id');
     $requestPath = $this->_getReadAdapter()->getIfNullSql('url_rewrite.request_path', 'default_ur.request_path');
     $select = $this->_getReadAdapter()->select()->from(array('main_table' => $this->getTable('catalog/product')), array($this->getIdFieldName() => $idField))->where('main_table.entity_id = ?', (int) $product->getId())->joinLeft(array('url_rewrite_cat' => $this->getTable('enterprise_catalog/product')), 'url_rewrite_cat.product_id = main_table.entity_id AND url_rewrite_cat.store_id = ' . (int) $product->getStoreId(), array(''))->joinLeft(array('url_rewrite' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'url_rewrite.url_rewrite_id = url_rewrite_cat.url_rewrite_id', array(''))->joinLeft(array('default_urc' => $this->getTable('enterprise_catalog/product')), 'default_urc.product_id = main_table.entity_id AND default_urc.store_id = 0', array(''))->joinLeft(array('default_ur' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'default_ur.url_rewrite_id = default_urc.url_rewrite_id', array('request_path' => $requestPath));
     $result = $this->_getReadAdapter()->fetchRow($select);
     if (isset($result['id']) && !empty($result['id'])) {
         $object->setData($result);
     }
     $this->unserializeFields($object);
     $this->_afterLoad($object);
     return $this;
 }
Esempio n. 23
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     $parentId = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
     $parentItem = Mage::getModel('catalog/product')->load($parentId);
     $category = Mage::getModel('catalog/category')->load();
     if (!Mage::getStoreConfig('web/seo/use_rewrites')) {
         if ($product->getTypeId() == 'simple' && $parentItem->getTypeId() == 'configurable' || 'bundle' || 'grouped') {
             $url = $parentItem->getProductUrl(false);
         } else {
             $url = $product->getProductUrl(false);
         }
     } else {
         if ($product->getTypeId() == 'simple' && $parentItem->getTypeId() == 'configurable' || 'bundle' || 'grouped') {
             $url = sprintf('%s%s', Mage::getBaseUrl(), $parentItem->getUrlPath($category));
         } else {
             $url = sprintf('%s%s', Mage::getBaseUrl(), $product->getUrlPath($category));
         }
     }
     if ($url) {
         if (!Mage::getStoreConfigFlag('web/url/use_store')) {
             $urlInfo = parse_url($url);
             $store = $product->getStore()->getCode();
             if (isset($urlInfo['query']) && $urlInfo['query'] != '') {
                 $url .= '&___store=' . $store;
             } else {
                 $url .= '?___store=' . $store;
             }
         }
         $config = Mage::getSingleton('googleshoppingapi/config');
         if ($config->getAddUtmSrcGshopping($product->getStoreId())) {
             $url .= '&utm_source=GoogleShopping';
         }
         if ($customUrlParameters = $config->getCustomUrlParameters($product->getStoreId())) {
             $url .= $customUrlParameters;
         }
         $shoppingProduct->setLink($url);
     }
     return $shoppingProduct;
 }
Esempio n. 24
0
 /**
  * Delete product data
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @return Enterprise_GiftCard_Model_Resource_Attribute_Backend_Giftcard_Amount
  */
 public function deleteProductData($product, $attribute)
 {
     $condition = array();
     if (!$attribute->isScopeGlobal()) {
         if ($storeId = $product->getStoreId()) {
             $condition['website_id IN (?)'] = array(0, Mage::app()->getStore($storeId)->getWebsiteId());
         }
     }
     $condition['entity_id=?'] = $product->getId();
     $condition['attribute_id=?'] = $attribute->getId();
     $this->_getWriteAdapter()->delete($this->getMainTable(), $condition);
     return $this;
 }
Esempio n. 25
0
 /**
  * Get the price for catalog rules
  *
  * @param Mage_Catalog_Model_Product $product
  *
  * @return float
  */
 public function calcProductPriceRule(Mage_Catalog_Model_Product $product)
 {
     $rulePrice = null;
     if (Mage::helper("shopgate/config")->getIsMagentoVersionLower15()) {
         $pId = $product->getId();
         $storeId = $product->getStoreId();
         $date = Mage::app()->getLocale()->storeTimeStamp($storeId);
         $wId = Mage::app()->getStore($storeId)->getWebsiteId();
         $rulePrice = Mage::getResourceModel('catalogrule/rule')->getRulePrice($date, $wId, 0, $pId);
     } else {
         $rulePrice = Mage::getModel("catalogrule/rule")->calcProductPriceRule($product, $product->getPrice());
     }
     return $rulePrice;
 }
Esempio n. 26
0
 /**
  * Get items which are available for update/delete when product is saved
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Weboffice_GoogleShoppingApi_Model_Mysql4_Item_Collection
  */
 protected function _getItemsCollection($product)
 {
     $items = Mage::getResourceModel('googleshoppingapi/item_collection')->addProductFilterId($product->getId());
     if ($product->getStoreId()) {
         $items->addStoreFilter($product->getStoreId());
     }
     $clientAuthenticated = true;
     foreach ($items as $item) {
         if (!Mage::getStoreConfigFlag('bvt_googleshoppingapi_config/settings/observed', $item->getStoreId())) {
             $items->removeItemByKey($item->getId());
         } else {
             $service = Mage::getModel('googleshoppingapi/googleShopping');
             if (!$service->isAuthenticated($item->getStoreId())) {
                 $items->removeItemByKey($item->getId());
                 $clientAuthenticated = false;
             }
         }
     }
     if (!$clientAuthenticated) {
         Mage::getSingleton('adminhtml/session')->addWarning(Mage::helper('googleshoppingapi')->__('Product was not updated on GoogleShopping for at least one store. Please authenticate and save the product again or update manually.'));
     }
     return $items;
 }
Esempio n. 27
0
 /**
  * Get product url
  *
  * @param  Mage_Catalog_Model_Product $product
  * @return string
  */
 public function getProductUrl($product)
 {
     Varien_Profiler::start('REWRITE: ' . __METHOD__);
     $rewrite = $this->getUrlRewrite();
     if ($product->getStoreId()) {
         $rewrite->setStoreId($product->getStoreId());
     }
     $idPath = 'product/' . $product->getId();
     if ($product->getCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
         $idPath .= '/' . $product->getCategoryId();
     }
     $rewrite->loadByIdPath($idPath);
     if ($rewrite->getId()) {
         $url = $this->getUrlInstance()->getBaseUrl() . $rewrite->getRequestPath();
         Varien_Profiler::stop('REWRITE: ' . __METHOD__);
         return $url;
     }
     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()));
     Varien_Profiler::stop('REGULAR: ' . __METHOD__);
     return $url;
 }
Esempio n. 28
0
 /**
  * Load gallery images for product
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object
  * @return array
  */
 public function loadCartImage($product, $options)
 {
     $adapter = $this->_getReadAdapter();
     $positionCheckSql = $adapter->getCheckSql('value.position IS NULL', 'default_value.position', 'value.position');
     $_att_id = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'media_gallery')->getId();
     // Select gallery images for product
     $select = $adapter->select()->from(array('main' => $this->getMainTable()), array('value_id', 'value AS file'))->joinLeft(array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), $adapter->quoteInto('main.value_id = value.value_id AND value.store_id = ?', (int) $product->getStoreId()), array('label', 'position', 'disabled'))->joinLeft(array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), 'main.value_id = default_value.value_id AND default_value.store_id = 0', array('label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled', 'associated_attributes_default' => 'associated_attributes'))->where('main.attribute_id = ?', $_att_id)->where('main.entity_id = ?', $product->getId())->order($positionCheckSql . ' ' . Varien_Db_Select::SQL_ASC);
     foreach ($options as $selected_option) {
         $select->where("default_value.associated_attributes like ?", "%" . $selected_option . "%");
     }
     //echo $select;
     $result = $adapter->fetchAll($select);
     $this->_removeDuplicates($result);
     return $result;
 }
Esempio n. 29
0
 /**
  * Load gallery images for product using reusable select method
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object
  * @return array
  */
 public function loadGallery($product, $object)
 {
     $eventObjectWrapper = new Varien_Object(array('product' => $product, 'backend_attribute' => $object));
     Mage::dispatchEvent($this->_eventPrefix . '_load_gallery_before', array('event_object_wrapper' => $eventObjectWrapper));
     if ($eventObjectWrapper->hasProductIdsOverride()) {
         $productIds = $eventObjectWrapper->getProductIdsOverride();
     } else {
         $productIds = array($product->getId());
     }
     $select = $this->_getLoadGallerySelect($productIds, $product->getStoreId(), $object->getAttribute()->getId());
     $adapter = $this->_getReadAdapter();
     $result = $adapter->fetchAll($select);
     $this->_removeDuplicates($result);
     return $result;
 }
Esempio n. 30
0
 /**
  * Retrieve Store Id
  *
  * @return int
  */
 public function getStoreId()
 {
     return (int) $this->_product->getStoreId();
 }