About Kien Wiliam
Magento Ecommerce Developer
Posts by Kien Wiliam
Magento Ecommerce Developer
When installing Magento 2 on your machine you should ask yourself: Do I need more problems in my life? If the answer is Yes, continue reading. I’ll be installing Magento 2 on my dev machine – Linux Ubuntu 16.04 with Php 7.0.7 Mysql 5.7.12 Composer 1.1.2 Before continuing, make sure you have all the prerequisites, required […]
MAGENTO 1 : Get Url in phtml files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<!-- Get Base Url --> Mage::getBaseUrl(); <!-- Get Skin Url --> Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); <!-- Unsecure Skin Url --> $this->getSkinUrl('images/imagename.jpg'); <!-- Secure Skin Url --> $this->getSkinUrl('images/imagename.gif', array('_secure'=>true)); <!-- Get Media Url --> Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); <!-- Get Js Url --> Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); <!-- Get Store Url --> Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); <!-- Get Current Url --> Mage::helper('core/url')->getCurrentUrl(); |
Get Url in cms pages or static blocks
1 2 3 4 5 6 7 8 9 10 11 |
<!-- Get Base Url --> {{store url=""}} <!-- Get Skin Url --> {{skin url='images/imagename.jpg'}} <!-- Get Media Url --> {{media url='/imagename.jpg'}} <!-- Get Store Url --> {{store url='mypage.html'}} |
MAGENTO 2 : Below is a block class of my custom module. I have injected object of StoreManagerInterface & UrlInterface in the constructor of my module’s block class. Both of them can be used to fetch base and current URL. In […]
You can copy vendor/magento/module-sales/view/frontend/email/shipment_new.html to your theme and edit line 56 (here you can change block for which display track information), you can change it like this
1 2 3 4 5 6 |
{{ block class='Your_Package\\Your_Module\\Block\\Sales\\Email\\Shipment\\Track' area='frontend' template='Magento_Sales::email/shipment/track.phtml' shipment=$shipment order=$order }} |
After that you need create this block
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?php namespace Your_Package\Your_Module\Block\Sales\Email\Shipment; use \Magento\Framework\View\Element\Template; class Track extends Template { /** * @var \Magento\Shipping\Model\Order\TrackFactory */ protected $_trackFactory; /** * Constructor * * @param \Magento\Shipping\Model\Order\TrackFactory $trackFactory * @param Template\Context $context * @param array $data */ public function __construct( \Magento\Shipping\Model\Order\TrackFactory $trackFactory, Template\Context $context, array $data = []) { $this->_trackFactory = $trackFactory; parent::__construct($context, $data); } /** * Retrieve tracking by tracking entity id * * @return array */ public function getTrackingInfoByTrackId($trackId) { /** @var \Magento\Shipping\Model\Order\Track $track */ $track = $this->_trackFactory->create()->load($trackId); if ($track->getEntityId()) { $result = $track->getNumberDetail(); } else { $result = null; } return $result; } } |
Then copy template vendor/magento/module-sales/view/frontend/templates/email/shipment/track.phtml to your theme and change line 25 to
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<td> <?php $trackingInfo = $block->getTrackingInfoByTrackId($_item->getEntityId()); ?> <?php if ($trackingInfo->getUrl()): ?> <a href="<?= $block->escapeHtml($trackingInfo->getUrl()) ?>" onclick="this.target='_blank'"> <?= $block->escapeHtml($_item->getNumber()) ?> </a> <?php else: ?> <?= $block->escapeHtml($_item->getNumber()) ?> <?php endif; ?> </td> |
You also may need copy vendor/magento/module-sales/view/frontend/email/shipment_new_guest.html […]
Creating an upgrade script for cloning a product with \Magento\Catalog\Model\Product\Copier has a bug.
1 2 3 4 5 6 7 8 9 10 11 |
public function __construct( \Magento\Catalog\Model\Product\Copier $productCopier, \Magento\Framework\App\State $appState ) { $this->productCopier = $productCopier; try { $appState->setAreaCode('frontend'); } catch( \Magento\Framework\Exception\LocalizedException $e ) { // intentionally left empty } } |
Then have error when use product Copier function :
1 2 3 4 5 6 7 |
PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento\Catalog\Model\Product\CopyConstructorInterface in /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:73 Stack trace: #0 /var/www/m210/vendor/magento/framework/ObjectManager/ObjectManager.php(71): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\Catalog...') #1 /var/www/m210/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(126): Magento\Framework\ObjectManager\ObjectManager->get('Magento\Catalog...') #2 /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(53): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, 'Magento\Catalog...', NULL, 'copyConstructor', 'Magento\Catalog...') #3 /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(82): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments('Magento\Catalog...', Array, Array) #4 /var/www/m210/vendor/magento/frame in /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 73 |
Simple try the our solution below : Create di.xml file in frontend folder with the content below :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Model\Product\CopyConstructor\Composite"> <arguments> <argument name="constructors" xsi:type="array"> <item name="crossSell" xsi:type="string">Magento\Catalog\Model\Product\CopyConstructor\CrossSell</item> <item name="upSell" xsi:type="string">Magento\Catalog\Model\Product\CopyConstructor\UpSell</item> <item name="related" xsi:type="string">Magento\Catalog\Model\Product\CopyConstructor\Related</item> <item name="catalog_inventory" xsi:type="string">Magento\CatalogInventory\Model\Product\CopyConstructor\CatalogInventory</item> <item name="downloadable" xsi:type="string">Magento\Downloadable\Model\Product\CopyConstructor\Downloadable</item> </argument> </arguments> </type> <type name="Magento\Catalog\Model\Product\Copier"> <arguments> <argument name="copyConstructor" xsi:type="object">Magento\Catalog\Model\Product\CopyConstructor\Composite</argument> </arguments> </type> </config> |
See image : This solution also applied for magento 2 issue 7056 […]
Go to the file : vendor/magento/module-checkout/Model/PaymentInformationManagement.php vendor/magento/module-checkout/Model/GuestPaymentInformationManagement.php Change function savePaymentInformationAndPlaceOrder() from
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/** * {@inheritDoc} */ public function savePaymentInformationAndPlaceOrder( $cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress); try { $orderId = $this->cartManagement->placeOrder($cartId); } catch (\Exception $e) { throw new CouldNotSaveException( __('An error occurred on the server. Please try to place the order again.'), $e ); } return $orderId; } |
To
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * {@inheritDoc} */ public function savePaymentInformationAndPlaceOrder( $cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress); try { $orderId = $this->cartManagement->placeOrder($cartId); } catch (\Exception $e) { throw new CouldNotSaveException( $e ); } return $orderId; } |
Check log and see result ! Thank for reading this post, Hope it helps.
You can easily import/export your database using phpMyAdmin menu in cPanel. To do so, it allows processing only the databases that do not exceed 50Mb. If your database is bigger, you will need to use SSH commands. Note that before performing an export or import, you will need to assign a database to a user. You can do it in cPanel […]