Beispiel #1
0
 public function getProductOptionsHtml(Mage_Catalog_Model_Product $product, $type)
 {
     $blockOption = Mage::app()->getLayout()->createBlock("Mage_Catalog_Block_Product_View_Options");
     $blockOption->addOptionRenderer("default", "catalog/product_view_options_type_default", "catalog/product/view/options/type/default.phtml");
     $blockOption->addOptionRenderer("text", "catalog/product_view_options_type_text", "inchoo_catalog/product/view/options/type/text.phtml");
     $blockOption->addOptionRenderer("file", "catalog/product_view_options_type_file", "catalog/product/view/options/type/file.phtml");
     $blockOption->addOptionRenderer("select", "catalog/product_view_options_type_select", "catalog/product/view/options/type/select_config.phtml");
     $blockOption->addOptionRenderer("date", "catalog/product_view_options_type_date", "catalog/product/view/options/type/date.phtml");
     $blockOptionsHtml = null;
     if ($product->getTypeId() == "simple" || $product->getTypeId() == "virtual" || $product->getTypeId() == "configurable") {
         $blockOption->setProduct($product);
         if ($product->getOptions()) {
             foreach ($product->getOptions() as $o) {
                 $blockOptionsHtml .= $blockOption->getOptionHtml($o);
             }
         }
     }
     if ($product->getTypeId() == "configurable") {
         $blockViewType = Mage::app()->getLayout()->createBlock("Mage_Catalog_Block_Product_View_Type_Configurable");
         $blockViewType->setProduct($product);
         $blockViewType->setTemplate("catalog/product/view/type/options/configurable.phtml");
         $blockViewType->setCountConf($this->_count);
         $blockViewType->setType($type);
         $this->_count++;
         $blockOptionsHtml .= $blockViewType->toHtml();
     }
     return $blockOptionsHtml;
 }
Beispiel #2
0
 /**
  * Product type instance factory
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Catalog_Model_Product_Type_Abstract
  */
 public static function factory($product)
 {
     $types = self::getTypes();
     if (!empty($types[$product->getTypeId()]['model'])) {
         $typeModelName = $types[$product->getTypeId()]['model'];
     } else {
         $typeModelName = self::DEFAULT_TYPE_MODEL;
     }
     $typeModel = Mage::getModel($typeModelName);
     $typeModel->setProduct($product);
     return $typeModel;
 }
 /**
  * Collect the basic information about the product and return it as an array.
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 protected function _collectProductInfo(Mage_Catalog_Model_Product $product)
 {
     //basic product info, same for every possible product type
     $productInfo = array('id' => $product->getId(), 'type' => $product->getTypeId(), 'name' => $product->getName(), 'saleable' => $product->isSaleable(), 'price' => Mage::helper('tax')->getPrice($product, $product->getFinalPrice()), 'priceTemplate' => $this->getPriceTemplate());
     $manufacturer = $this->_getManufacturer($product);
     if ($manufacturer) {
         $productInfo['manufacturer'] = $manufacturer;
     }
     //if product has active special price
     if ($oldPrice = $this->getOldPrice($product)) {
         $productInfo['oldPrice'] = $oldPrice;
     }
     //allowed sale quantities
     if ($qtyLimits = $this->getProductQtyLimits($product)) {
         list($minQty, $maxQty) = $qtyLimits;
         if ($minQty !== null) {
             $productInfo['minqty'] = $minQty;
         }
         if ($maxQty !== null) {
             $productInfo['maxqty'] = $maxQty;
         }
     }
     //add product tax info
     if ($taxInfo = $this->getProductTax($product)) {
         $productInfo['tax'] = $taxInfo;
     }
     //get additional info, if possible
     //this may be different for various product types
     $productInfo = $this->_collectAdditionalProductInfo($product, $productInfo);
     return $productInfo;
 }
Beispiel #4
0
 /**
  * Returns helper for product type
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_Catalog_Helper_Product_Configuration_Interface
  */
 protected function _getProductHelper($product)
 {
     // Retrieve whole array of renderers
     $productHelpers = $this->getProductHelpers();
     if (!is_array($productHelpers)) {
         $column = $this->getColumn();
         if ($column) {
             $grid = $column->getGrid();
             if ($grid) {
                 $productHelpers = $grid->getProductConfigurationHelpers();
                 $this->setProductHelpers($productHelpers ? $productHelpers : array());
             }
         }
     }
     // Check whether we have helper for our product
     $productType = $product->getTypeId();
     if (isset($productHelpers[$productType])) {
         $helperName = $productHelpers[$productType];
     } else {
         if (isset($productHelpers['default'])) {
             $helperName = $productHelpers['default'];
         } else {
             $helperName = 'catalog/product_configuration';
         }
     }
     $helper = Mage::helper($helperName);
     if (!$helper instanceof Mage_Catalog_Helper_Product_Configuration_Interface) {
         Mage::throwException($this->__("Helper for options rendering doesn't implement required interface."));
     }
     return $helper;
 }
Beispiel #5
0
 /**
  * Create the separated index of product images
  *
  * @param Mage_Catalog_Model_Product $product
  * @param array|null $preValues
  * @return Mage_ConfigurableSwatches_Helper_Data
  */
 public function indexProductImages($product, $preValues = null)
 {
     if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
         return;
         // we only index images on configurable products
     }
     if (!isset($this->_productImagesByLabel[$product->getId()])) {
         $images = array();
         $searchValues = array();
         if (!is_null($preValues) && is_array($preValues)) {
             // If a pre-defined list of valid values was passed
             $preValues = array_map('Mage_ConfigurableSwatches_Helper_Data::normalizeKey', $preValues);
             foreach ($preValues as $value) {
                 $searchValues[] = $value;
             }
         } else {
             // we get them from all config attributes if no pre-defined list is passed in
             $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
             // Collect valid values of image type attributes
             foreach ($attributes as $attribute) {
                 if (Mage::helper('configurableswatches')->attrIsSwatchType($attribute->getAttributeId())) {
                     foreach ($attribute->getPrices() as $option) {
                         // getPrices returns info on individual options
                         $searchValues[] = Mage_ConfigurableSwatches_Helper_Data::normalizeKey($option['label']);
                     }
                 }
             }
         }
         $mapping = $product->getChildAttributeLabelMapping();
         $mediaGallery = $product->getMediaGallery();
         $mediaGalleryImages = $product->getMediaGalleryImages();
         if (empty($mediaGallery['images']) || empty($mediaGalleryImages)) {
             $this->_productImagesByLabel[$product->getId()] = array();
             return;
             //nothing to do here
         }
         $imageHaystack = array_map(function ($value) {
             return Mage_ConfigurableSwatches_Helper_Data::normalizeKey($value['label']);
         }, $mediaGallery['images']);
         foreach ($searchValues as $label) {
             $imageKeys = array();
             $swatchLabel = $label . self::SWATCH_LABEL_SUFFIX;
             $imageKeys[$label] = array_search($label, $imageHaystack);
             if ($imageKeys[$label] === false) {
                 $imageKeys[$label] = array_search($mapping[$label]['default_label'], $imageHaystack);
             }
             $imageKeys[$swatchLabel] = array_search($swatchLabel, $imageHaystack);
             if ($imageKeys[$swatchLabel] === false) {
                 $imageKeys[$swatchLabel] = array_search($mapping[$label]['default_label'] . self::SWATCH_LABEL_SUFFIX, $imageHaystack);
             }
             foreach ($imageKeys as $imageLabel => $imageKey) {
                 if ($imageKey !== false) {
                     $imageId = $mediaGallery['images'][$imageKey]['value_id'];
                     $images[$imageLabel] = $mediaGalleryImages->getItemById($imageId);
                 }
             }
         }
         $this->_productImagesByLabel[$product->getId()] = $images;
     }
 }
 /**
  * Initialize product view layout
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Catalog_ProductController
  */
 protected function _initProductLayout($product)
 {
     $update = $this->getLayout()->getUpdate();
     $update->addHandle('default');
     $this->addActionLayoutHandles();
     $update->addHandle('PRODUCT_TYPE_' . $product->getTypeId());
     $update->addHandle('PRODUCT_' . $product->getId());
     if ($product->getPageLayout()) {
         $this->getLayout()->helper('page/layout')->applyHandle($product->getPageLayout());
     }
     $this->loadLayoutUpdates();
     $update->addUpdate($product->getCustomLayoutUpdate());
     $this->generateLayoutXml()->generateLayoutBlocks();
     if ($product->getPageLayout()) {
         $this->getLayout()->helper('page/layout')->applyTemplate($product->getPageLayout());
     }
     $currentCategory = Mage::registry('current_category');
     if ($root = $this->getLayout()->getBlock('root')) {
         $root->addBodyClass('product-' . $product->getUrlKey());
         if ($currentCategory instanceof Mage_Catalog_Model_Category) {
             $root->addBodyClass('categorypath-' . $currentCategory->getUrlPath())->addBodyClass('category-' . $currentCategory->getUrlKey());
         }
     }
     return $this;
 }
Beispiel #7
0
 /**
  * Get unit/final price for a product model.
  *
  * @param Mage_Catalog_Model_Product $product    the product model.
  * @param bool                       $finalPrice if final price.
  * @param bool                       $inclTax    if tax is to be included.
  *
  * @return float
  */
 protected function _getProductPrice($product, $finalPrice = false, $inclTax = true)
 {
     $price = 0;
     switch ($product->getTypeId()) {
         case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
             // Get the bundle product "from" price.
             $price = $product->getPriceModel()->getTotalPrices($product, 'min', $inclTax);
             break;
         case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
             // Get the grouped product "starting at" price.
             /** @var $tmpProduct Mage_Catalog_Model_Product */
             $tmpProduct = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addAttributeToFilter('entity_id', $product->getId())->setPage(1, 1)->addMinimalPrice()->addTaxPercents()->load()->getFirstItem();
             if ($tmpProduct) {
                 $price = $tmpProduct->getMinimalPrice();
                 if ($inclTax) {
                     $price = Mage::helper('tax')->getPrice($tmpProduct, $price, true);
                 }
             }
             break;
         default:
             $price = $finalPrice ? $product->getFinalPrice() : $product->getPrice();
             if ($inclTax) {
                 $price = Mage::helper('tax')->getPrice($product, $price, true);
             }
             break;
     }
     return $price;
 }
 /**
  * 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)
 {
     $value = $this->_googleAvailabilityMap[(int) $product->isSalable()];
     if ($product->getTypeId() == "configurable") {
         $value = $this->_googleAvailabilityMap[1];
     }
     return $shoppingProduct->setAvailability($value);
 }
Beispiel #9
0
 /**
  * Determines if a product is a Shopgate Coupon
  *
  * @param Mage_Catalog_Model_Product $product
  * @return boolean
  */
 public function isShopgateCoupon(Mage_Catalog_Model_Product $product)
 {
     $attributeSetModel = Mage::getModel("eav/entity_attribute_set")->load($product->getAttributeSetId());
     if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL && $attributeSetModel->getAttributeSetName() == self::COUPON_ATTRIUBTE_SET_NAME) {
         return true;
     }
     return false;
 }
Beispiel #10
0
 /**
  * Product type instance factory
  *
  * @param   Mage_Catalog_Model_Product $product
  * @param   bool $singleton
  * @return  Mage_Catalog_Model_Product_Type_Abstract
  */
 public static function factory($product, $singleton = false)
 {
     $types = self::getTypes();
     if (!empty($types[$product->getTypeId()]['model'])) {
         $typeModelName = $types[$product->getTypeId()]['model'];
     } else {
         $typeModelName = self::DEFAULT_TYPE_MODEL;
     }
     if ($singleton === true) {
         $typeModel = Mage::getSingleton($typeModelName);
     } else {
         $typeModel = Mage::getModel($typeModelName);
         $typeModel->setProduct($product);
     }
     $typeModel->setConfig($types[$product->getTypeId()]);
     return $typeModel;
 }
Beispiel #11
0
 /**
  * Retrieve product attributes as xml object
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string $itemNodeName
  * @return Mage_XmlConnect_Model_Simplexml_Element
  */
 public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNodeName = 'item')
 {
     /** @var $item Mage_XmlConnect_Model_Simplexml_Element */
     $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>');
     if ($product && $product->getId()) {
         $item->addChild('entity_id', $product->getId());
         $item->addChild('name', $item->escapeXml($product->getName()));
         $item->addChild('entity_type', $product->getTypeId());
         $item->addChild('short_description', $item->escapeXml($product->getShortDescription()));
         $description = Mage::helper('xmlconnect')->htmlize($item->xmlentities($product->getDescription()));
         $item->addChild('description', $description);
         $item->addChild('link', $product->getProductUrl());
         if ($itemNodeName == 'item') {
             $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small');
             $propertyToResizeName = 'small_image';
         } else {
             $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_big');
             $propertyToResizeName = 'image';
         }
         $icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName)->resize($imageToResize);
         $iconXml = $item->addChild('icon', $icon);
         $file = Mage::helper('xmlconnect')->urlToPath($icon);
         $iconXml->addAttribute('modification_time', filemtime($file));
         $item->addChild('in_stock', (int) $product->getIsInStock());
         $item->addChild('is_salable', (int) $product->isSalable());
         /**
          * By default all products has gallery (because of collection not load gallery attribute)
          */
         $hasGallery = 1;
         if ($product->getMediaGalleryImages()) {
             $hasGallery = sizeof($product->getMediaGalleryImages()) > 0 ? 1 : 0;
         }
         $item->addChild('has_gallery', $hasGallery);
         /**
          * If product type is grouped than it has options as its grouped items
          */
         if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE || $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
             $product->setHasOptions(true);
         }
         $item->addChild('has_options', (int) $product->getHasOptions());
         if ($minSaleQty = $this->_getMinimalQty($product)) {
             $item->addChild('min_sale_qty', (int) $minSaleQty);
         }
         if (!$product->getRatingSummary()) {
             Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId());
         }
         $item->addChild('rating_summary', round((int) $product->getRatingSummary()->getRatingSummary() / 10));
         $item->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount());
         if ($this->getChild('product_price')) {
             $this->getChild('product_price')->setProduct($product)->setProductXmlObj($item)->collectProductPrices();
         }
         if ($this->getChild('additional_info')) {
             $this->getChild('additional_info')->addAdditionalData($product, $item);
         }
     }
     return $item;
 }
 /**
  * Retrieve add to cart url
  *
  * @param Mage_Catalog_Model_Product $product
  * @return string
  */
 public function getAddToCartUrl($product)
 {
     if ($product->getTypeId() === Solvingmagento_AffiliateProduct_Model_Product_Type::TYPE_AFFILIATE) {
         return Mage::helper('solvingmagento_affiliateproduct')->getRedirectUrl($product);
     }
     $beforeCompareUrl = Mage::getSingleton('catalog/session')->getBeforeCompareUrl();
     $params = array('product' => $product->getId(), Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl($beforeCompareUrl));
     return $this->_getUrl('checkout/cart/add', $params);
 }
Beispiel #13
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;
 }
Beispiel #14
0
 /**
  * Get product html block
  *
  * @param string                     $mode
  * @param Mage_Catalog_Model_Product $product
  * @param array                      $data
  *
  * @return string
  */
 public function getProductHtml($mode, Mage_Catalog_Model_Product $product, $data = array())
 {
     if ($this->isModuleEnabled('Ho_Bootstrap')) {
         $renderer = Mage::helper('ho_bootstrap/list')->getProductRenderer($mode, $product->getTypeId(), $product->getAttributeSetId());
     } else {
         $renderer = array('block' => 'ho_simplebundle/catalog_product_list_type_simplebundle', 'template' => 'ho/simplebundle/catalog/product/list/type/default/simplebundle.phtml');
     }
     /** @var $block Ho_Bootstrap_Block_Catalog_Product_List_Type_Default */
     $block = Mage::app()->getLayout()->createBlock($renderer['block'])->setTemplate($renderer['template'])->setProduct($product)->addData($data);
     return $block->toHtml();
 }
Beispiel #15
0
 /**
  * Tries calculate price without discount; if can't returns null
  * @param $product
  * @param $store
  */
 public function getCatalogRegularPrice(Mage_Catalog_Model_Product $product, $store = null)
 {
     switch ($product->getTypeId()) {
         case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
         case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
         case 'giftcard':
             return null;
         default:
             return $product->getPrice();
     }
 }
Beispiel #16
0
 /**
  * @return string|void
  */
 public function setDisplayType()
 {
     if ($this->item->isGrouped()) {
         parent::setDisplayType(Shopgate_Model_Catalog_Product::DISPLAY_TYPE_LIST);
     }
     if ($this->item->isConfigurable()) {
         parent::setDisplayType(Shopgate_Model_Catalog_Product::DISPLAY_TYPE_SELECT);
     }
     if ($this->item->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
         parent::setDisplayType(Shopgate_Model_Catalog_Product::DISPLAY_TYPE_SIMPLE);
     }
 }
Beispiel #17
0
 /**
  * Add special fields to product get response
  *
  * @param Mage_Catalog_Model_Product $product
  */
 protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product)
 {
     $pricesFilterKeys = array('price_id', 'all_groups', 'website_price');
     $groupPrice = $product->getData('group_price');
     $product->setData('group_price', $this->_filterOutArrayKeys($groupPrice, $pricesFilterKeys, true));
     $tierPrice = $product->getData('tier_price');
     $product->setData('tier_price', $this->_filterOutArrayKeys($tierPrice, $pricesFilterKeys, true));
     $stockData = $product->getStockItem()->getData();
     $stockDataFilterKeys = array('item_id', 'product_id', 'stock_id', 'low_stock_date', 'type_id', 'stock_status_changed_auto', 'stock_status_changed_automatically', 'product_name', 'store_id', 'product_type_id', 'product_status_changed', 'product_changed_websites', 'use_config_enable_qty_increments');
     $product->setData('stock_data', $this->_filterOutArrayKeys($stockData, $stockDataFilterKeys));
     $product->setData('product_type_name', $product->getTypeId());
 }
 /**
  * Check if the passed in 'catalog/product' class instance object is a gift card product type before proceeding
  * to get its 'open_amount_max' attribute value and the largest card amount of the product. Further business
  * logics attempt to use 'open_amount_max' attribute value when there is one, otherwise use the largest card
  * amount to build the 'CustomAttributes/Attribute[@name="MaxGCAmount"]' Element. When both 'open_amount_max'
  * attribute value and largest card amounts are less or equal to zero an exception is thrown.
  * @param  string                     $attrValue
  * @param  string                     $attribute
  * @param  Mage_Catalog_Model_Product $product
  * @param  DOMDocument                $doc
  * @return mixed
  * @throws EbayEnterprise_Catalog_Model_Pim_Product_Validation_Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function passMaxGCAmount($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc)
 {
     if ($product->getTypeId() !== Enterprise_GiftCard_Model_Catalog_Product_Type_Giftcard::TYPE_GIFTCARD) {
         return null;
     }
     $value = max($product->getOpenAmountMax(), $this->_getMaxGiftCardAmount($product));
     if ($value <= 0) {
         $msg = "%s SKU '%s' a Gift card product is missing both 'Open Amount Max Value' and 'Card Amounts' data.";
         throw Mage::exception('EbayEnterprise_Catalog_Model_Pim_Product_Validation', sprintf($msg, __FUNCTION__, $product->getSku()));
     }
     return Mage::helper('ebayenterprise_catalog/pim')->getValueAsDefault($value, $attribute, $product, $doc);
 }
 /**
  * Get cheapest simple product
  *
  * @param Mage_Catalog_Model_Product $product Product
  *
  * @return Mage_Catalog_Model_Product
  */
 public function getCheapestSimpleProduct($product)
 {
     $typeId = $product->getTypeId();
     $cheapestProduct = $product;
     if ($typeId == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
         /** @var Mage_Catalog_Model_Product_Type_Configurable $modelConfigurable */
         $modelConfigurable = Mage::getModel('catalog/product_type_configurable');
         $childProducts = $modelConfigurable->getUsedProductIds($product);
         $cheapestProduct = $this->_getCheapestProduct($childProducts);
     }
     return $cheapestProduct;
 }
Beispiel #20
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;
 }
Beispiel #21
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)
 {
     $value = array();
     if ($product->getTypeId() == "configurable") {
         $associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
         foreach ($associatedProducts as $item) {
             $value[] = $this->getProductAttributeValue($item);
         }
     } else {
         $value[] = $this->getProductAttributeValue($product);
     }
     $shoppingProduct->setSizes(array($value));
     return $shoppingProduct;
 }
Beispiel #22
0
 public function getProduct()
 {
     if (!is_null($this->product)) {
         return $this->product;
     }
     if ($this->proxyItem->getProduct()->getTypeId() == Ess_M2ePro_Model_Magento_Product::TYPE_GROUPED) {
         $this->product = $this->getAssociatedGroupedProduct();
         if (is_null($this->product)) {
             throw new Exception('There is no associated products found for grouped product.');
         }
     } else {
         $this->product = $this->proxyItem->getProduct();
         if ($this->product->getTypeId() == Ess_M2ePro_Model_Magento_Product::TYPE_BUNDLE) {
             $this->product->setPriceType(Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_PARENT);
         }
     }
     // tax class id should be set before price calculation
     $this->product->setTaxClassId($this->getProductTaxClassId());
     $price = $this->getBaseCurrencyPrice();
     $this->product->setPrice($price);
     $this->product->setSpecialPrice($price);
     return $this->product;
 }
 public function processAfterSave(Mage_Catalog_Model_Product $object, $forceId = null)
 {
     $associated = array();
     switch ($object->getTypeId()) {
         case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
             $associated = $object->getTypeInstance(true)->getAssociatedProducts($object);
             break;
         case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE:
             $associated = $object->getTypeInstance(true)->getUsedProducts(null, $object);
             break;
     }
     if (!$this->_isObjectIndexable($object) && is_null($forceId)) {
         return;
     }
     $data = array();
     if ($this->_runOnce) {
         $data = $this->createIndexData($object);
     } else {
         $attributes = $object->getAttributes();
         foreach ($attributes as $attribute) {
             if ($this->_isAttributeIndexable($attribute) && $object->getData($attribute->getAttributeCode()) != null) {
                 $row = $this->createIndexData($object, $attribute);
                 if ($row && is_array($row)) {
                     if (isset($row[0]) && is_array($row[0])) {
                         $data = array_merge($data, $row);
                     } else {
                         $data[] = $row;
                     }
                 }
             }
         }
     }
     $function = 'saveIndex';
     if ($data && is_array($data)) {
         if (isset($data[0]) && is_array($data[0])) {
             $function = 'saveIndices';
         }
         $this->{$function}($data, $object->getStoreId(), $forceId != null ? $forceId : $object->getId());
     }
     if (!$this->_processChildrenForConfigurable && $object->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
         return;
     }
     if ($associated && $this->_processChildren) {
         foreach ($associated as $child) {
             $child->setStoreId($object->getStoreId())->setWebsiteId($object->getWebsiteId());
             $this->processAfterSave($child, $object->getId());
         }
     }
 }
Beispiel #24
0
 /**
  * Factory to product singleton product type instances
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Catalog_Model_Product_Type_Abstract
  */
 public static function factory($product)
 {
     $types = self::getTypes();
     $typeId = $product->getTypeId();
     if (!empty($types[$typeId]['model'])) {
         $typeModelName = $types[$typeId]['model'];
     } else {
         $typeModelName = self::DEFAULT_TYPE_MODEL;
         $typeId = self::DEFAULT_TYPE;
     }
     /** @var $typeModel Mage_Catalog_Model_Product_Type_Abstract */
     $typeModel = Mage::getSingleton($typeModelName);
     $typeModel->setConfig($types[$typeId]);
     return $typeModel;
 }
Beispiel #25
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)
 {
     $sizes = array();
     if ($product->getTypeId() == "configurable") {
         $associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
         foreach ($associatedProducts as $item) {
             $sizes[] = $this->getProductAttributeValue($item);
         }
     } else {
         $value = $this->getProductAttributeValue($product);
         $sizes = explode(",", $value);
         $sizes = array_map('trim', $sizes);
     }
     return $shoppingProduct->setSizes($sizes);
 }
Beispiel #26
0
 /**
  * Disable MAP if it's bundle with dynamic price type
  *
  * @param Mage_Catalog_Model_Product $product
  * @return bool
  */
 public function beforeSave($product)
 {
     if (!$product instanceof Mage_Catalog_Model_Product || $product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE || $product->getPriceType() != Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
         return parent::beforeSave($product);
     }
     parent::beforeSave($product);
     $attributeCode = $this->getAttribute()->getName();
     $value = $product->getData($attributeCode);
     if (empty($value)) {
         $value = Mage::helper('catalog')->isMsrpApplyToAll();
     }
     if ($value) {
         $product->setData($attributeCode, 0);
     }
     return $this;
 }
Beispiel #27
0
 /**
  * @param Mage_Catalog_Model_Product $configurableProduct
  * @return array
  * @throws Exception
  */
 public function getSimpleProductsForConfigurableProduct($configurableProduct)
 {
     if ($configurableProduct->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
         $error_message = $this->__(self::ERROR_PRODUCT_NOT_CONFIGURABLE, $configurableProduct->getSku());
         throw new Exception($error_message);
     }
     $parent_id = $configurableProduct->getId();
     $child_product_ids_return = $this->_getConfigurableProductTypeModel()->getChildrenIds($parent_id);
     $child_product_ids = reset($child_product_ids_return);
     $child_products_array = array();
     foreach ($child_product_ids as $child_product_id) {
         $childProduct = Mage::getModel('catalog/product')->load($child_product_id);
         if (is_object($childProduct) && $childProduct->getId()) {
             $child_products_array[] = $childProduct;
         }
     }
     return $child_products_array;
 }
Beispiel #28
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;
     }
     $routeName = $product->getTypeId() == 'buyback' ? 'buyback' : 'checkout';
     if ($this->_getRequest()->getRouteName() == $routeName && $this->_getRequest()->getControllerName() == 'cart') {
         $routeParams['in_cart'] = 1;
     }
     return $this->_getUrl($routeName . '/cart/add', $routeParams);
 }
 /**
  * Create Product array from Mage_Catalog_Model_Product
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 public function getProductData(Mage_Catalog_Model_Product $product)
 {
     try {
         $data = array('url' => $product->getProductUrl(), 'title' => htmlspecialchars($product->getName()), 'spider' => 1, 'price' => $product->getPrice(), 'description' => urlencode($product->getDescription()), 'tags' => htmlspecialchars($product->getMetaKeyword()), 'images' => array(), 'vars' => array('sku' => $product->getSku(), 'storeId' => '', 'typeId' => $product->getTypeId(), 'status' => $product->getStatus(), 'categoryId' => $product->getCategoryId(), 'categoryIds' => $product->getCategoryIds(), 'websiteIds' => $product->getWebsiteIds(), 'storeIds' => $product->getStoreIds(), 'groupPrice' => $product->getGroupPrice(), 'formatedPrice' => $product->getFormatedPrice(), 'calculatedFinalPrice' => $product->getCalculatedFinalPrice(), 'minimalPrice' => $product->getMinimalPrice(), 'specialPrice' => $product->getSpecialPrice(), 'specialFromDate' => $product->getSpecialFromDate(), 'specialToDate' => $product->getSpecialToDate(), 'relatedProductIds' => $product->getRelatedProductIds(), 'upSellProductIds' => $product->getUpSellProductIds(), 'getCrossSellProductIds' => $product->getCrossSellProductIds(), 'isSuperGroup' => $product->isSuperGroup(), 'isGrouped' => $product->isGrouped(), 'isConfigurable' => $product->isConfigurable(), 'isSuper' => $product->isSuper(), 'isSalable' => $product->isSalable(), 'isAvailable' => $product->isAvailable(), 'isVirtual' => $product->isVirtual(), 'isRecurring' => $product->isRecurring(), 'isInStock' => $product->isInStock(), 'weight' => $product->getSku()));
         // Add product images
         if (self::validateProductImage($product->getImage())) {
             $data['images']['full'] = array("url" => $product->getImageUrl());
         }
         if (self::validateProductImage($product->getSmallImage())) {
             $data['images']['smallImage'] = array("url" => $product->getSmallImageUrl($width = 88, $height = 77));
         }
         if (self::validateProductImage($product->getThumbnail())) {
             $data['images']['thumb'] = array("url" => $product->getThumbnailUrl($width = 75, $height = 75));
         }
         return $data;
         return $data;
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
 /**
  * Retrieve url for add product to cart
  *
  * @param Mage_Catalog_Model_Product $product    product object
  * @param array                      $additional additional route parameters
  *
  * @return string
  */
 public function getAddUrl($product, $additional = array())
 {
     if ($product->getTypeId() === Solvingmagento_AffiliateProduct_Model_Product_Type::TYPE_AFFILIATE) {
         return Mage::helper('solvingmagento_affiliateproduct')->getRedirectUrl($product);
     }
     $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);
 }