public function __construct(array $args)
 {
     $this->_product = $args['product'];
     $this->_store = $args['store'];
     $this->_coreHelper = $args['core'];
     $this->_weeeHelper = $args['weee'];
     $this->_taxHelper = $args['tax'];
     $this->_product = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect(Mage::getSingleton("catalog/config")->getProductAttributes())->addAttributeToFilter("entity_id", $this->_product->getEntityId())->setPage(1, 1)->addMinimalPrice()->addFinalPrice()->addTaxPercents()->load()->getFirstItem();
     $this->_simplePricesTax = $this->_taxHelper->displayPriceIncludingTax() || $this->_taxHelper->displayBothPrices();
     $this->_minimalPriceValue = $this->_product->getMinimalPrice();
     $this->_minimalPrice = $this->_taxHelper->getPrice($this->_product, $this->_minimalPriceValue, $this->_simplePricesTax);
     $this->_setPrices();
 }
Esempio n. 2
0
    /**
     * Retrieve url for add product to cart
     *
     * @param   Mage_Catalog_Model_Product $product
     * @return  string
     */
    public function getAddUrl($product, $additional = array())
    {
    	$continueUrl    = Mage::helper('core')->urlEncode($this->getCurrentUrl());
    	$urlParamName   = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
        $routeParams = array(
            $urlParamName   => $continueUrl,
            'product'       => $product->getEntityId()
        );

        if (!empty($additional)) {
            $routeParams = array_merge($routeParams, $additional);
        }

        if ($product->hasUrlDataObject()) {
            $routeParams['_store'] = $product->getUrlDataObject()->getStoreId();
            $routeParams['_store_to_url'] = true;
        }

        if ($this->_getRequest()->getRouteName() == 'checkout'
            && $this->_getRequest()->getControllerName() == 'cart') {
            $routeParams['in_cart'] = 1;
        }

        return $this->_getUrl('checkout/cart/add', $routeParams);
    }
Esempio n. 3
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;
 }
Esempio n. 4
0
 /**
  * Retrieve url for add product to cart
  *
  * @param Mage_Catalog_Model_Product $product
  * @param array $additional
  * @return string
  */
 public function getAddUrl($product, $additional = array())
 {
     $routeParams = array(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->_getHelperInstance('core')->urlEncode($this->getCurrentUrl()), 'product' => $product->getEntityId(), Mage_Core_Model_Url::FORM_KEY => $this->_getSingletonModel('core/session')->getFormKey());
     if (!empty($additional)) {
         $routeParams = array_merge($routeParams, $additional);
     }
     if ($product->hasUrlDataObject()) {
         $routeParams['_store'] = $product->getUrlDataObject()->getStoreId();
         $routeParams['_store_to_url'] = true;
     }
     if ($this->_getRequest()->getRouteName() == 'checkout' && $this->_getRequest()->getControllerName() == 'cart') {
         $routeParams['in_cart'] = 1;
     }
     return $this->_getUrl('checkout/cart/add', $routeParams);
 }
Esempio n. 5
0
 /**
  * Retrieve url for adding product to wishlist with params
  *
  * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
  * @param array $params
  *
  * @return  string|bool
  */
 public function getAddUrlWithParams($item, array $params = array())
 {
     $productId = null;
     if ($item instanceof Mage_Catalog_Model_Product) {
         $productId = $item->getEntityId();
     }
     if ($item instanceof Mage_Wishlist_Model_Item) {
         $productId = $item->getProductId();
     }
     if ($productId) {
         $params['product'] = $productId;
         $params[Mage_Core_Model_Url::FORM_KEY] = $this->_getSingletonModel('core/session')->getFormKey();
         return $this->_getUrlStore($item)->getUrl('wishlist/index/add', $params);
     }
     return false;
 }
 /**
  * @param Mage_Catalog_Model_Product $product
  * @param array                      $input
  * @param                            $weight
  * @return array
  */
 protected function _getNameSuggestFieldArray(Mage_Catalog_Model_Product $product, array $input, $weight)
 {
     return array("input" => $input, "output" => $product->getName(), "weight" => (int) $weight, "payload" => array("id" => $product->getEntityId(), "path" => $this->_getProductUrlPath($product)));
 }
Esempio n. 7
0
 /**
  * Retrieve Product URL using UrlDataObject
  *
  * @param Mage_Catalog_Model_Product $product
  * @param array $params
  * @return string
  */
 public function getUrl(Mage_Catalog_Model_Product $product, $params = array())
 {
     $routePath = '';
     $routeParams = $params;
     $storeId = $product->getStoreId();
     if (isset($params['_ignore_category'])) {
         unset($params['_ignore_category']);
         $categoryId = null;
     } else {
         $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
     }
     if ($product->hasUrlDataObject()) {
         $requestPath = $product->getUrlDataObject()->getUrlRewrite();
         $routeParams['_store'] = $product->getUrlDataObject()->getStoreId();
     } else {
         $requestPath = $product->getRequestPath();
         if (empty($requestPath) && $requestPath !== false) {
             $idPath = sprintf('product/%d', $product->getEntityId());
             if ($categoryId) {
                 $idPath = sprintf('%s/%d', $idPath, $categoryId);
             }
             $rewrite = $this->getUrlRewrite();
             $rewrite->setStoreId($storeId)->loadByIdPath($idPath);
             if ($rewrite->getId()) {
                 $requestPath = $rewrite->getRequestPath();
                 $product->setRequestPath($requestPath);
             } else {
                 $product->setRequestPath(false);
             }
         }
     }
     if (isset($routeParams['_store'])) {
         $storeId = Mage::app()->getStore($routeParams['_store'])->getId();
     }
     if ($storeId != Mage::app()->getStore()->getId()) {
         $routeParams['_store_to_url'] = true;
     }
     if (!empty($requestPath)) {
         $routeParams['_direct'] = $requestPath;
     } else {
         $routePath = 'catalog/product/view';
         $routeParams['id'] = $product->getId();
         $routeParams['s'] = $product->getUrlKey();
         if ($categoryId) {
             $routeParams['category'] = $categoryId;
         }
     }
     // reset cached URL instance GET query params
     if (!isset($routeParams['_query'])) {
         $routeParams['_query'] = array();
     }
     return $this->getUrlInstance()->setStore($storeId)->getUrl($routePath, $routeParams);
 }
 /**
  * Retrieve category ids where product is available
  *
  * @param Mage_Catalog_Model_Product $object
  * @return array
  */
 public function getAvailableInCategories($object)
 {
     // is_parent=1 ensures that we'll get only category IDs those are direct parents of the product, instead of
     // fetching all parent IDs, including those are higher on the tree
     $select = $this->_getReadAdapter()->select()->distinct()->from($this->getTable('catalog/category_product_index'), array('category_id'))->where('product_id = ? AND is_parent = 1', (int) $object->getEntityId());
     return $this->_getReadAdapter()->fetchCol($select);
 }
Esempio n. 9
0
 /**
  * Retrieve category ids where product is available
  *
  * @param Mage_Catalog_Model_Product $object
  * @return array
  */
 public function getAvailableInCategories($object)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getTable('catalog/category_product_index'), array('category_id'))->where('product_id = ?', (int) $object->getEntityId());
     return $this->_getReadAdapter()->fetchCol($select);
 }
Esempio n. 10
0
 /**
  * Retrieve request path
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $categoryId
  * @return bool|string
  */
 protected function _getRequestPath($product, $categoryId)
 {
     $idPath = sprintf('product/%d', $product->getEntityId());
     if ($categoryId) {
         $idPath = sprintf('%s/%d', $idPath, $categoryId);
     }
     $rewrite = $this->getUrlRewrite();
     $rewrite->setStoreId($product->getStoreId())->loadByIdPath($idPath);
     if ($rewrite->getId()) {
         return $rewrite->getRequestPath();
     }
     return false;
 }
Esempio n. 11
0
 private function _getParentProduct(Mage_Catalog_Model_Product $product)
 {
     $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getEntityId());
     if (is_array($parentIds) && count($parentIds) > 0) {
         $parentId = $parentIds[0];
         if ($parentId != null) {
             if (!array_key_exists($parentId, $this->_parentsById)) {
                 $this->_parentsById[$parentId] = Mage::getModel('catalog/product')->load($parentId);
             }
             return $this->_parentsById[$parentId];
         }
     }
     return null;
 }
Esempio n. 12
0
 /**
  * Retrieve product categories
  *
  * @param Mage_Catalog_Model_Product $object
  * @return array
  */
 public function getCategoryIdsWithAnchors($object)
 {
     $selectRootCategories = $this->_getReadAdapter()->select()->from(array($this->getTable('catalog/category')), array('entity_id'))->where('level <= 1');
     $rootIds = $this->_getReadAdapter()->fetchCol($selectRootCategories);
     $select = $this->_getReadAdapter()->select()->from(array($this->getTable('catalog/category_product_index')), array('category_id'))->where('product_id = ?', (int) $object->getEntityId())->where('category_id NOT IN(?)', $rootIds);
     return $this->_getReadAdapter()->fetchCol($select);
 }
Esempio n. 13
0
 /**
  * Accommodated grouped products by adding the tag for each associated product.
  * @param  Varien_Event_Observer      $observer
  * @param  Mage_Catalog_Model_Product $oProduct
  * @return array
  */
 private function _generateProductCacheTags(Varien_Event_Observer $observer, $oProduct)
 {
     if (!$oProduct) {
         return array();
     }
     $tags = array(Mage_Core_Block_Abstract::CACHE_GROUP, Mage_Core_Model_App::CACHE_TAG, Mage_Core_Model_Store::CACHE_TAG, Mage_Catalog_Model_Product::CACHE_TAG . '_' . $oProduct->getEntityId());
     if ($oProduct->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
         $aChildren = $oProduct->getTypeInstance(true)->getAssociatedProducts($oProduct);
         foreach ($aChildren as $oChild) {
             $tags[] = Mage_Catalog_Model_Product::CACHE_TAG . '_' . $oChild->getEntityId();
         }
     }
     return $tags;
 }
Esempio n. 14
0
 /**
  * Retrieve url for adding product to wishlist with params
  *
  * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
  * @param array $params
  *
  * @return  string|bool
  */
 public function getAddUrlWithParams($item, array $params = array())
 {
     $productId = null;
     if ($item instanceof Mage_Catalog_Model_Product) {
         $productId = $item->getEntityId();
     }
     if ($item instanceof Mage_Wishlist_Model_Item) {
         $productId = $item->getProductId();
     }
     if ($productId) {
         $params['product'] = $productId;
         return $this->_getUrlStore($item)->getUrl('wishlist/index/add', $params);
     }
     return false;
 }
Esempio n. 15
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);
     }
 }