1.Create a Layout File:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="js">
<block class="Poc\ImportPro\Block\Adminhtml\Product\Edit\PocProductPrice" name="poc_edit_js" template="Poc_ImportPro::catalog/product/pocproductprice.phtml"/>
</referenceContainer>
</body>
</page>
2. Create Block File:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Poc\ImportPro\Block\Adminhtml\Product\Edit;
class PocProductPrice extends \Magento\Backend\Block\Template {
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $coreRegistry = null;
/**
* Json helper
*
* @var \Magento\Framework\Json\Helper\Data
*/
protected $jsonHelper;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
protected $serialize;
/**
* product_condition config path
*/
const XML_PATH_PRODUCT_CONDITION = 'product_condition/condition/po_co';
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Serialize\Serializer\Json $serialize,
array $data = []
) {
$this->coreRegistry = $registry;
$this->jsonHelper = $jsonHelper;
$this->scopeConfig = $scopeConfig;
$this->serialize = $serialize;
parent::__construct($context, $data);
}
/**
* Get currently edited product
*
* @return \Magento\Catalog\Model\Product
*/
public function getProduct() {
return $this->coreRegistry->registry('current_product');
}
public function getProductCondition() {
$product = $this->getProduct();
if ($product) {
$whioutColon = str_replace(":","",$product->getAttributeText('condition'));
$whioutCondition = trim(str_replace("Condition","",$whioutColon));
return strtolower(str_replace(" ","_",$whioutCondition));
}
return null;
}
/**
* Get store object of currently edited product
*
* @return \Magento\Store\Model\Store
*/
public function getStore() {
$product = $this->getProduct();
if ($product) {
return $this->_storeManager->getStore($product->getStoreId());
}
return $this->_storeManager->getStore();
}
/**
* Get config value
* @param $configPath
* @param null $store
* @return mixed
*/
public function getConfigValue($configPath, $store = null) {
return $this->scopeConfig->getValue(
$configPath,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* Get serialized config value
* temporarily solution to get unserialized config value
* should be deprecated in 2.3.x
*
* @param $configPath
* @param null $store
* @return mixed
*/
public function getSerializedConfigValue($store = null) {
$productcostconfig = $this->getConfigValue(self::XML_PATH_PRODUCT_CONDITION, $store = null);
if (empty($productcostconfig)) return false;
$condtions = $this->serialize->unserialize($productcostconfig);
$options = array();
foreach($condtions as $condtion){
$condtionName = strtolower(str_replace(" ","_",$condtion['condition_name']));
$options [$condtionName] = array(
'condition_name' => $condtionName,
'condition_rate' => $condtion['condition_rate'],
);
}
return $options;
}
}
3. Create Template file:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
/** @var \Poc\ImportPro\Block\Adminhtml\Product\Edit\PosProductPrice $block */
?>
<script>
require(["jquery", "prototype", "mage/backend/tabs"],
function($){
var posproductcondition = "<?php echo $block->getProductCondition(); ?>";
var systemconfig = <?php echo json_encode($block->getSerializedConfigValue()); ?>;
$(document).ready(function(){
$(document).ajaxStop(function () {
$(document).on("change", "input[type='text'][name='product[cost]']", function() {
var cost = $(this).val();
var $rate= 0;
$rate = systemconfig[posproductcondition].condition_rate;
$rate = parseFloat($rate);
console.log("aaaaaaaaaaaaaaaaaa",$rate);
var finalprice = parseFloat(cost) + $rate;
//$("input[type='text'][name='product[price]']").val(finalprice);
$("input[type='text'][name='product[price]']").attr('value', finalprice).trigger('change');
});
});
});
});
</script>
![]()
8 Comments
israelnightclub.comנערות ליווי בתל באביב · July 30, 2022 at 9:25 pm
Good day! I just would like to give you a huge thumbs up for your great info youve got right here on this post. I will be coming back to your website for more soon.
נערות ליווי באילת -israelxclub.co.il · August 5, 2022 at 5:44 pm
Good post. I learn something totally new and challenging on blogs I stumbleupon everyday. Its always useful to read through content from other authors and practice something from other sites.
israel night club · August 17, 2022 at 6:41 am
When I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I recieve four emails with the exact same comment. Perhaps there is a way you can remove me from that service? Many thanks!
נערות ליווי במרכז-israel night club · September 3, 2022 at 9:38 am
I want to to thank you for this wonderful read!! I absolutely loved every little bit of it. I have you saved as a favorite to look at new stuff you postÖ
דירות דיסקרטיות במרכז · September 5, 2022 at 8:25 am
You ought to take part in a contest for one of the greatest blogs on the web. Im going to highly recommend this site!
israelnightclub · September 20, 2022 at 4:53 am
Itís difficult to find educated people for this topic, however, you seem like you know what youíre talking about! Thanks
דירות דיסקרטיות · December 27, 2022 at 1:42 pm
You ought to take part in a contest for one of the best sites on the net. I will highly recommend this blog!
דירה דיסקרטית באשדוד · January 26, 2023 at 9:14 pm
I need to to thank you for this great read!! I definitely loved every little bit of it. Ive got you saved as a favorite to check out new things you postÖ