Skip to content

Commit

Permalink
Change getImageUrl method and obtain store currency code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz-Silpion committed Sep 9, 2018
1 parent 96854e0 commit 5c2fc9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
28 changes: 18 additions & 10 deletions Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class Product extends \Magento\Catalog\Model\Product {
*/
public $priceHelper;

/**
* @var Magento\Catalog\Helper\Image
*/
public $imageHelper;

/**
* Category model for feed
*
Expand All @@ -53,13 +58,6 @@ class Product extends \Magento\Catalog\Model\Product {
* @var \Magento\Catalog\Model\Product\Gallery\ReadHandler
*/
public $galleryReadHandler;

/**
* Store data container
*
* @var \Magento\Store\Model\Store\Interceptor
*/
public $store;

/**
* Stock item
Expand All @@ -80,9 +78,9 @@ protected function _construct()
$this->filterManager = $objectManager->create('Magento\Framework\Filter\FilterManager');
$this->stockItemRepository = $objectManager->create('Magento\CatalogInventory\Model\Stock\StockItemRepository');
$this->priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
$this->imageHelper = $objectManager->create('Magento\Catalog\Helper\Image');
$this->categoryModel = $objectManager->create('Magento\Catalog\Model\Category');
$this->galleryReadHandler = $objectManager->create('Magento\Catalog\Model\Product\Gallery\ReadHandler');
$this->store = $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore();
}

/**
Expand Down Expand Up @@ -205,15 +203,25 @@ public function getSpecialPriceWithCurrency()
{
return $this->priceHelper->currency(parent::getSpecialPrice(), true, false);
}

/**
* Get currency code only
*
* @return string
*/
public function getCurrencyCode()
{
return $this->_storeManager->getStore()->getCurrentCurrency()->getCode();
}

/**
* Get product image url
*
* @return string
*/
public function getImageUrl()
public function getImageUrl($type = 'product_page_main_image_default')
{
return $this->store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $this->getImage();
return $this->imageHelper->init($this, $type)->getUrl();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"type": "magento2-module",
"version": "1.0.4",
"version": "1.0.5",
"license": [
"OSL-3.0"
],
Expand All @@ -23,4 +23,4 @@
"LCB\\Feeds\\": ""
}
}
}
}
4 changes: 2 additions & 2 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="LCB_Feeds" setup_version="1.0.4"></module>
<module name="LCB_Feeds" setup_version="1.0.5"></module>
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Catalog"/>
</sequence>
</config>
</config>

0 comments on commit 5c2fc9b

Please sign in to comment.