public function testGetUrlPath()
 {
     $this->_model->setUrlPath('test');
     $this->assertEquals('test', $this->_model->getUrlPath());
     $category = new Mage_Catalog_Model_Category();
     $category->setUrlPath('category');
     $this->assertEquals('category/test', $this->_model->getUrlPath($category));
 }
 public function testGetUrlPath()
 {
     $this->_model->setUrlPath('test');
     $this->assertEquals('test', $this->_model->getUrlPath());
     /** @var $category Mage_Catalog_Model_Category */
     $category = Mage::getModel('Mage_Catalog_Model_Category');
     $category->setUrlPath('category');
     $this->assertEquals('category/test', $this->_model->getUrlPath($category));
 }
 public static function getFullProductUrl(Mage_Catalog_Model_Product $product, Mage_Catalog_Model_Category $category = null, $mustBeIncludedInNavigation = true)
 {
     $currentCategory = Mage::registry('current_category');
     $catIds = $product->getCategoryIds();
     $url = Mage::getModel('core/url_rewrite')->getCollection()->addFilter('is_system', '1')->addFilter('product_id', $product->getId())->addFilter('store_id', Mage::app()->getStore()->getId())->addFieldToFilter('category_id', array('gt' => '0'));
     if ($currentCategory && in_array($currentCategory->getId(), $catIds)) {
         $catId = $currentCategory->getId();
         $url->addFilter('category_id', $catId);
     }
     $rs = $url->setOrder('url_rewrite_id', 'DESC')->getFirstItem();
     if (!$rs->getRequestPath()) {
         return $product->getUrlPath();
     }
     return Mage::getBaseUrl() . $rs->getRequestPath();
 }
Exemple #4
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;
 }
Exemple #5
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;
 }
 /**
  * @param Mage_Catalog_Model_Product $product
  * @return string
  */
 protected function _getProductUrlPath(Mage_Catalog_Model_Product $product)
 {
     return $product->getUrlPath();
 }
Exemple #7
0
 protected function _sendOfferMessages(Mage_Catalog_Model_Product $product, $performThoroughCheck = false)
 {
     if ($this->_isValueRegistered('xcom_offer_messages_sent', $product->getId())) {
         return;
     }
     $this->_registerValue('xcom_offer_messages_sent', $product->getId());
     $cancelledSids = array();
     $createdSids = array();
     if ($performThoroughCheck || $product->getIsChangedWebsites()) {
         $oldWids = $this->_getRegisterValueForKey('xcom_offer_old_stores', $product->getId());
         if (!isset($oldWids)) {
             $oldWids = array();
         }
         $cancelledSids = array_diff($oldWids, $product->getStoreIds());
         $createdSids = array_diff($product->getStoreIds(), $oldWids);
     }
     $updatedSids = array_diff($product->getStoreIds(), $cancelledSids, $createdSids);
     // There is a case where product was duplicated and just now a sku was filled in
     if ($product->getOrigData()) {
         $oldSku = $product->getOrigData('sku');
         $sku = $product->getSku();
         if (empty($oldSku) && !empty($sku)) {
             $createdSids = array_merge($createdSids, $updatedSids);
             $updatedSids = array();
         }
     }
     if ($product->dataHasChangedFor('price')) {
         foreach ($updatedSids as $sid) {
             $offerInputData = array('product' => $product, 'store_id' => $sid);
             Mage::helper('xcom_xfabric')->send('com.x.webstore.v1/WebStoreOfferUpdate/WebStoreOfferPriceUpdated', $offerInputData);
         }
     }
     if ($this->_isValueRegistered('xcom_inventory_updated', $product->getId())) {
         foreach ($updatedSids as $sid) {
             $offerInputData = array('product' => $product, 'store_id' => $sid);
             Mage::helper('xcom_xfabric')->send('com.x.webstore.v1/WebStoreOfferUpdate/WebStoreOfferQuantityUpdated', $offerInputData);
         }
     }
     if ($product->dataHasChangedFor('visibility') || $product->dataHasChangedFor('status')) {
         foreach ($updatedSids as $sid) {
             $offerInputData = array('product' => $product, 'store_id' => $sid);
             Mage::helper('xcom_xfabric')->send('com.x.webstore.v1/WebStoreOfferUpdate/WebStoreOfferUpdated', $offerInputData);
         }
     }
     if ($product->dataHasChangedFor('url_key')) {
         foreach ($updatedSids as $sid) {
             Mage::getModel('xcom_chronicle/product_url_update')->setProductId($product->getEntityId())->setStoreId($sid)->setUrlPath($product->getUrlPath())->save();
         }
     }
     foreach ($createdSids as $sid) {
         $offerInputData = array('product' => $product, 'store_id' => $sid);
         Mage::helper('xcom_xfabric')->send('com.x.webstore.v1/WebStoreOfferCreation/WebStoreOfferCreated', $offerInputData);
     }
     foreach ($cancelledSids as $sid) {
         $storeProduct = $this->_getRegisterValueForKey('xcom_offer_old_stores_products', $product->getId() . '_' . $sid);
         if (empty($storeProduct)) {
             $offerInputData = array('product' => $product, 'store_id' => $sid);
         } else {
             $offerInputData = array('product' => $storeProduct);
         }
         Mage::helper('xcom_xfabric')->send('com.x.webstore.v1/WebStoreOfferDeletion/WebStoreOfferDeleted', $offerInputData);
     }
 }