Magento 2 Entwicklung: Unterschied zwischen den Versionen
Aus Vosp.info
V (Diskussion | Beiträge) |
V (Diskussion | Beiträge) (→get product) |
||
Zeile 82: | Zeile 82: | ||
=== get product=== | === get product=== | ||
==== by ==== | ==== by ==== | ||
− | |||
<source lang=php> | <source lang=php> | ||
class Data extends \Magento\Framework\App\Helper\AbstractHelper | class Data extends \Magento\Framework\App\Helper\AbstractHelper | ||
Zeile 92: | Zeile 91: | ||
$this->_productRepository = $productRepository; | $this->_productRepository = $productRepository; | ||
} | } | ||
− | + | </source> | |
+ | ===== sku ===== | ||
+ | <source lang=php> | ||
return $this->_productRepository->get($sku); | return $this->_productRepository->get($sku); | ||
− | |||
</source> | </source> | ||
===== id ===== | ===== id ===== | ||
Zeile 100: | Zeile 100: | ||
return $this->_productRepository->getById($id); | return $this->_productRepository->getById($id); | ||
</source> | </source> | ||
− | |||
− | |||
=== Customized configurable product === | === Customized configurable product === |
Version vom 19. September 2017, 17:11 Uhr
Inhaltsverzeichnis
Code Snippets Magento2
phtml get arguments Xml/Cms
CMS Page => Design Layout XML
<referenceContainer name="content">
<block class="Anc\Apname\Block\Blockname" name="ancname" as="ancname" template="Magento_Theme::anc//ancname.phtml" >
<arguments>
<argument name="ancspec" xsi:type="array">
<item name="ancFnc" xsi:type="array">
<item name="product" xsi:type="string">5</item>
</item>
</argument>
</arguments>
</block>
</referenceContainer>
Phtml File
$argsFromXml=$block->getData('ancspec') ;
Code Migration Snippets 1.x => 2.x
Text Ausgabe
1.x
echo $this->__('Outputtext');
2.x
echo __('Outputtext');
Bilder
1.x
<img src="<?php echo $this->getSkinUrl('images/product/dir/name.jpg'); ?>" alt="<?php echo $this->__('Name'); ?>"
{{skin url='images/product/dir/name.jpg'}}
2.x
<img src="<?php echo $this->getViewFileUrl('images/product/dir/name.jpg'); ?>" alt="<?php echo __('Name'); ?>" />
{{view url='images/product/dir/name.jpg'}}
Url
1.x
<a href="<?php echo Mage::getUrl('produkte'); ?>" ?>"
2.x
<a href="<?php echo $this->getUrl('produkte'); ?>" ?>" />
Helper
1.x
Mage::helper('anchelper')->ancfnc();
2.x
$this->helper('Anc\Appname\Helper\Anchelper');
Currency
1.x
Mage::helper('core')->currency($_product->getPrice(),true,true)
2.x
$this->helper('Magento\Framework\Pricing\Helper\Data')->currency($_product->getPrice(),true,false);
get product
by
class Data extends \Magento\Framework\App\Helper\AbstractHelper
....
public function __construct(
\Magento\Catalog\Model\ProductRepository $productRepository,
)
{
$this->_productRepository = $productRepository;
}
sku
return $this->_productRepository->get($sku);
id
return $this->_productRepository->getById($id);
Customized configurable product
Preis wird nicht mehr bei Wechsel aktualisiert
$templatestring ="<div class="priceReferenceValue price-box" data-role="priceBox" data-product-id="' . $_product->getId() . '" ><span class="value"> {BASE_PRICE}</span></div>";
- app/design/frontend/Anc/ancdesign/Magento_ConfigurableProduct/web/js/configurable.js
_calculatePrice: function (config) {
var displayPrices = $(this.options.priceHolderSelector).priceBox('option').prices,
newPrices = this.options.spConfig.optionPrices[_.first(config.allowedProducts)];
_.each(displayPrices, function (price, code) {
if (newPrices[code]) {
displayPrices[code].amount = newPrices[code].amount - displayPrices[code].amount;
}
});
/**
* neuen Preis setzen
*/
$(".priceReferenceValue .value .price").html(newPrices.finalPrice.amount.replace(/\./g, ',') + ' €');
return displayPrices;
},