magento2.3 – Magento 2.4.2: How to change tax label from Tax to Tax(PST/GST/HST)?

We got a custom shipping module created to handle shipping to addresses from within the US and Canada. I would need to change tax label from Tax to Tax(PST/GST/HST) in the payment page only when the destination country is Canada. Below is the whole script handling custom shipping. How can I achieve it?

<?php

namespace PerfectmakeupmirrorsCustomShippingModelCarrier;

use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier;
use MagentoFrameworkAppResourceConnection;

/**
 * Custom shipping model
 */
class Customshipping extends AbstractCarrier implements CarrierInterface
{
    const FEDEX_METHODS = (
        'EUROPE_FIRST_INTERNATIONAL_PRIORITY' => 'Europe First Priority',
        'FEDEX_1_DAY_FREIGHT' => '1 Day Freight',
        'FEDEX_2_DAY_FREIGHT' => '2 Day Freight',
        'FEDEX_2_DAY' => '2 Day',
        'FEDEX_2_DAY_AM' => '2 Day AM',
        'FEDEX_3_DAY_FREIGHT' => '3 Day Freight',
        'FEDEX_EXPRESS_SAVER' => 'Express Saver',
        'FEDEX_GROUND' => 'Ground',
        'FIRST_OVERNIGHT' => 'First Overnight',
        'GROUND_HOME_DELIVERY' => 'Home Delivery',
        'INTERNATIONAL_ECONOMY' => 'International Economy',
        'INTERNATIONAL_ECONOMY_FREIGHT' => 'Intl Economy Freight',
        'INTERNATIONAL_FIRST' => 'International First',
        'INTERNATIONAL_GROUND' => 'International Ground',
        'INTERNATIONAL_PRIORITY' => 'International Priority',
        'INTERNATIONAL_PRIORITY_FREIGHT' => 'Intl Priority Freight',
        'PRIORITY_OVERNIGHT' => 'Priority Overnight',
        'SMART_POST' => 'Smart Post',
        'STANDARD_OVERNIGHT' => 'Standard Overnight',
        'FEDEX_FREIGHT' => 'Freight',
        'FEDEX_NATIONAL_FREIGHT' => 'National Freight'
    );
    const SHIPPING_STANDARD = 'STD';
    const SHIPPING_2ND_DAY = '2DY';
    const SHIPPING_OVERNIGHT = 'ON';
    protected $_shipping_mode_strings = array(
        self::SHIPPING_STANDARD => 'Standard Ground',
        self::SHIPPING_2ND_DAY => 'Second Day',
        self::SHIPPING_OVERNIGHT => 'Next Day Air',
    );

    /**
     * @var string
     */
    protected $_code = 'customshipping';

    /**
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * @var MagentoShippingModelRateResultFactory
     */
    private $rateResultFactory;

    /**
     * @var MagentoQuoteModelQuoteAddressRateResultMethodFactory
     */
    private $rateMethodFactory;

    /**
     * @var PerfectmakeupmirrorsCustomShippingHelperData
     */
    private $helper;

    /**
     * @var PsrLogLoggerInterface
     */
    protected $_logger;

    /**
     * @var PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier;
     */
    private $carrierFedex;

    /**
     * @var MagentoFrameworkAppResourceConnection;
     */
    protected $resource;

    /**
     * @var MagentoFrameworkAppResourceConnection;
     */
    protected $scopeConfig;

    /**
     * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
     * @param MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory
     * @param PsrLogLoggerInterface $logger
     * @param MagentoShippingModelRateResultFactory $rateResultFactory
     * @param MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory
     * @param MagentoFrameworkAppResourceConnection $resource
     * @param array $data
     */
    public function __construct(
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
        PsrLogLoggerInterface $logger,
        MagentoShippingModelRateResultFactory $rateResultFactory,
        MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
        PerfectmakeupmirrorsCustomShippingHelperData $helper,
        PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier $carrierFedex,
        MagentoFrameworkAppResourceConnection $resource,
        array $data = ()
    ) {
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);

        $this->rateResultFactory = $rateResultFactory;
        $this->rateMethodFactory = $rateMethodFactory;
        $this->carrierFedex = $carrierFedex;
        $this->_logger = $logger;
        $this->helper = $helper;
        $this->resource = $resource;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * Custom Shipping Rates Collector
     *
     * @param RateRequest $request
     * @return MagentoShippingModelRateResult|bool
     */
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }
        
        if ($request->getDestCountryId() == "CA") {
            // Shipping to Canada.
            // 1. Get the array of method objects from $fedex_results object
            // 2. Loop through the array of method objects to set carrier.
            // 3. Set carrier to custom shipping.
            // 4. Add brokerage to the shipping cost based on the table canada_brokerage_fees.
            $fedex_results = $this->carrierFedex->collectRates($request);

            // MagentoQuoteModelQuoteAddressRateResultMethod $methods
            $methods = $fedex_results->getAllRates();
            foreach ($methods as $method) {
                // 3. Set carrier to custom shipping.
                $method->setCarrier($this->_code);
                $method->setMethodTitle("(including brokerage and duty)");
                $method->setCarrierTitle("");

                // Get subtotal from the $request object.
                // The request object is not giving the subtotal directly.
                // Using Quote object.
                // Refer https://magento.stackexchange.com/questions/341393/magento-2-4-2-how-to-get-order-sub-total-in-my-custom-module/341410#341410
                $quote = null;
                $items = $request->getAllItems();
                foreach($items as $item) {
                    /** @var Quote $quote */
                    $quote = $item->getQuote();
                    break;
                }
                if (!$quote) {
                    return false;
                }
                $subtotal = $quote->getSubtotal();                

                // Convert subtotal from USD to CAD
                // Get current CAD rate.
                $current_usd_to_cad_rate = $this->get_magento_system_info("pmm/currency_conversion/usd_to_cad_conversion");
                $subtotal_cad = $subtotal * floatval($current_usd_to_cad_rate);

                // Use table canada_brokerage_fee in Magento DB
                // Create DB connection
                // http://blog.chapagain.com.np/magento-2-run-custom-sql-query/
                $connection = $this->resource->getConnection();
                $tableName = $this->resource->getTableName('canada_brokerage_fees');

                // Compute brokerage.
                // Fetch relevant fee from the table canada_brokerage_fees 
                // based on the merchandise total.
                $sql = $connection->select()->from($tableName)->where('max_merchandise_cost <= ?', $subtotal_cad)
                ->order('brokerage_cost_cad DESC')->limit(1);
                $result = $connection->fetchAll($sql);                
                $brokerage_cost_cad = $result(0)('brokerage_cost_cad') ?? 0;

                // TODO
                // Compute duty and add it to brokerage_cost_cad.
                // All mirror and skin care products are duty free.

                // Set new price with brokerage added to the shipping cost.
                $method->setPrice($method->getPrice() + $brokerage_cost_cad);
            }
            return $fedex_results;
        } elseif (($request->getDestRegionCode() == "AK") || ($request->getDestRegionCode() == "HI") || ($request->getDestCountryId() == "PR")) {
            // For Alaska, Hawaii, and Puerto Rico
            // We want to get the shipping computation using Fedex

            $fedex_results = $this->carrierFedex->collectRates($request);
            // 1. Get the array of method objects from $fedex_results object
            // 2. Loop through the array of method objects to set carrier.
            // 3. Set carrier to custom shipping. 

            // MagentoQuoteModelQuoteAddressRateResultMethod $methods
            $methods = $fedex_results->getAllRates();
            foreach ($methods as $method) {
                $method->setCarrier($this->_code);
                $method->setMethodTitle("(including brokerage and duty)");
                $method->setCarrierTitle("");
            }
            return $fedex_results;
        }

        // Below Processing is for Mainland USA.
        // Custom Shipping needs to be computed.
        /** @var MagentoShippingModelRateResult $result */
        $result = $this->rateResultFactory->create();

        /** @var MagentoQuoteModelQuoteAddressRateResultMethod $method */
        $method = $this->rateMethodFactory->create();

        $method->setCarrier($this->_code);
        $method->setCarrierTitle($this->getConfigData('title'));

        $method->setMethod($this->_code);
        $method->setMethodTitle($this->getConfigData('name'));

        $this->_logger->info(__FILE__ . ': At Start');

        // Get all the items.
        // NOTE: This getAllItems here is related to Quote and not the order.
        if ((!($items = $request->getAllItems())) or (count($items) == 0)) {
            return FALSE;
        }

        //Standard code commented. Custom code added.
        //$shippingCost = (float)$this->getConfigData('shipping_cost');
        $shippingCost = (float)$this->helper->compute_standard_shipping_cost($items);

        $method->setPrice($shippingCost);
        $method->setCost($shippingCost);

        $result->append($method);

        return $result;
    }

    /**
     * Get all the allowed methods for Custom Shipping. This sends the CustomShipping
     * method as well as all the allowed methods of Fedex. This is required to ensure
     * the Fedex shipping methods to be considered as valid methods.
     * 
     * @return array
     */
    public function getAllowedMethods()
    {
        $custom_shipping_methods = ($this->_code => $this->getConfigData('name'));
        $allowed_methods = array_merge($custom_shipping_methods, $this->FEDEX_METHODS);
        return $allowed_methods;
    }

    /**
     * get_magento_system_info - receives the path as parameter.
     * This parameter holds the path to the field.
     * This function returns a value in Magento core_config_data table.
     * 
     * @param string $path
     * @return string $config_data
     */
    private function get_magento_system_info($path)
    {
        // Refer https://store.magenest.com/blog/get-set-config-data-programmatically-magento-2/
        // Refer https://firebearstudio.com/blog/how-to-write-and-get-config-values-by-scope-in-magento-2.html

        // Call functions to get config data with default (global) scope
        return $this->scopeConfig->getValue($path);
    }
}

module – Magento 2.4.2: How to change the shipping label?

With a custom shipping module, I am adding brokerage and duties to the shipping cost for an order from Canada. How can the shipping label be changed so that it reads “Shipping includes brokerage and duties”

enter image description here

Below is entire customshipping.php script

<?php

namespace PerfectmakeupmirrorsCustomShippingModelCarrier;

use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier;
use MagentoFrameworkAppResourceConnection;

/**
 * Custom shipping model
 */
class Customshipping extends AbstractCarrier implements CarrierInterface
{
    const FEDEX_METHODS = (
        'EUROPE_FIRST_INTERNATIONAL_PRIORITY' => 'Europe First Priority',
        'FEDEX_1_DAY_FREIGHT' => '1 Day Freight',
        'FEDEX_2_DAY_FREIGHT' => '2 Day Freight',
        'FEDEX_2_DAY' => '2 Day',
        'FEDEX_2_DAY_AM' => '2 Day AM',
        'FEDEX_3_DAY_FREIGHT' => '3 Day Freight',
        'FEDEX_EXPRESS_SAVER' => 'Express Saver',
        'FEDEX_GROUND' => 'Ground',
        'FIRST_OVERNIGHT' => 'First Overnight',
        'GROUND_HOME_DELIVERY' => 'Home Delivery',
        'INTERNATIONAL_ECONOMY' => 'International Economy',
        'INTERNATIONAL_ECONOMY_FREIGHT' => 'Intl Economy Freight',
        'INTERNATIONAL_FIRST' => 'International First',
        'INTERNATIONAL_GROUND' => 'International Ground',
        'INTERNATIONAL_PRIORITY' => 'International Priority',
        'INTERNATIONAL_PRIORITY_FREIGHT' => 'Intl Priority Freight',
        'PRIORITY_OVERNIGHT' => 'Priority Overnight',
        'SMART_POST' => 'Smart Post',
        'STANDARD_OVERNIGHT' => 'Standard Overnight',
        'FEDEX_FREIGHT' => 'Freight',
        'FEDEX_NATIONAL_FREIGHT' => 'National Freight'
    );
    const SHIPPING_STANDARD = 'STD';
    const SHIPPING_2ND_DAY = '2DY';
    const SHIPPING_OVERNIGHT = 'ON';
    protected $_shipping_mode_strings = array(
        self::SHIPPING_STANDARD => 'Standard Ground',
        self::SHIPPING_2ND_DAY => 'Second Day',
        self::SHIPPING_OVERNIGHT => 'Next Day Air',
    );

    /**
     * @var string
     */
    protected $_code = 'customshipping';

    /**
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * @var MagentoShippingModelRateResultFactory
     */
    private $rateResultFactory;

    /**
     * @var MagentoQuoteModelQuoteAddressRateResultMethodFactory
     */
    private $rateMethodFactory;

    /**
     * @var PerfectmakeupmirrorsCustomShippingHelperData
     */
    private $helper;

    /**
     * @var PsrLogLoggerInterface
     */
    protected $_logger;

    /**
     * @var PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier;
     */
    private $carrierFedex;

    /**
     * @var MagentoFrameworkAppResourceConnection;
     */
    protected $resource;

    /**
     * @var MagentoFrameworkAppResourceConnection;
     */
    protected $scopeConfig;

    /**
     * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
     * @param MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory
     * @param PsrLogLoggerInterface $logger
     * @param MagentoShippingModelRateResultFactory $rateResultFactory
     * @param MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory
     * @param MagentoFrameworkAppResourceConnection $resource
     * @param array $data
     */
    public function __construct(
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
        PsrLogLoggerInterface $logger,
        MagentoShippingModelRateResultFactory $rateResultFactory,
        MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
        PerfectmakeupmirrorsCustomShippingHelperData $helper,
        PerfectmakeupmirrorsPmmFedexModelPmmFedexCarrier $carrierFedex,
        MagentoFrameworkAppResourceConnection $resource,
        array $data = ()
    ) {
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);

        $this->rateResultFactory = $rateResultFactory;
        $this->rateMethodFactory = $rateMethodFactory;
        $this->carrierFedex = $carrierFedex;
        $this->_logger = $logger;
        $this->helper = $helper;
        $this->resource = $resource;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * Custom Shipping Rates Collector
     *
     * @param RateRequest $request
     * @return MagentoShippingModelRateResult|bool
     */
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }
        
        if ($request->getDestCountryId() == "CA") {
            // Shipping to Canada.
            // 1. Get the array of method objects from $fedex_results object
            // 2. Loop through the array of method objects to set carrier.
            // 3. Set carrier to custom shipping.
            // 4. Add brokerage to the shipping cost based on the table canada_brokerage_fees.
            $fedex_results = $this->carrierFedex->collectRates($request);

            // MagentoQuoteModelQuoteAddressRateResultMethod $methods
            $methods = $fedex_results->getAllRates();
            foreach ($methods as $method) {
                // 3. Set carrier to custom shipping.
                $method->setCarrier($this->_code);

                // Get subtotal from the $request object.
                // The request object is not giving the subtotal directly.
                // Using Quote object.
                // Refer https://magento.stackexchange.com/questions/341393/magento-2-4-2-how-to-get-order-sub-total-in-my-custom-module/341410#341410
                $quote = null;
                $items = $request->getAllItems();
                foreach($items as $item) {
                    /** @var Quote $quote */
                    $quote = $item->getQuote();
                    break;
                }
                if (!$quote) {
                    return false;
                }
                $subtotal = $quote->getSubtotal();                

                // Convert subtotal from USD to CAD
                // Get current CAD rate.
                $current_usd_to_cad_rate = $this->get_magento_system_info("pmm/currency_conversion/usd_to_cad_conversion");
                $subtotal_cad = $subtotal * floatval($current_usd_to_cad_rate);

                // Use table canada_brokerage_fee in Magento DB
                // Create DB connection
                // http://blog.chapagain.com.np/magento-2-run-custom-sql-query/
                $connection = $this->resource->getConnection();
                $tableName = $this->resource->getTableName('canada_brokerage_fees');

                // Compute brokerage.
                // Fetch relevant fee from the table canada_brokerage_fees 
                // based on the merchandise total.
                $sql = $connection->select()->from($tableName)->where('max_merchandise_cost <= ?', $subtotal_cad)
                ->order('brokerage_cost_cad DESC')->limit(1);
                $result = $connection->fetchAll($sql);                
                $brokerage_cost_cad = $result(0)('brokerage_cost_cad') ?? 0;

                // TODO
                // Compute duty and add it to brokerage_cost_cad.
                // All mirror and skin care products are duty free.

                // Set new price with brokerage added to the shipping cost.
                $method->setPrice($method->getPrice() + $brokerage_cost_cad);
            }
            return $fedex_results;
        } elseif (($request->getDestRegionCode() == "AK") || ($request->getDestRegionCode() == "HI") || ($request->getDestCountryId() == "PR")) {
            // For Alaska, Hawaii, and Puerto Rico
            // We want to get the shipping computation using Fedex

            $fedex_results = $this->carrierFedex->collectRates($request);
            // 1. Get the array of method objects from $fedex_results object
            // 2. Loop through the array of method objects to set carrier.
            // 3. Set carrier to custom shipping. 

            // MagentoQuoteModelQuoteAddressRateResultMethod $methods
            $methods = $fedex_results->getAllRates();
            foreach ($methods as $method) {
                $method->setCarrier($this->_code);
            }
            return $fedex_results;
        }

        // Below Processing is for Mainland USA.
        // Custom Shipping needs to be computed.
        /** @var MagentoShippingModelRateResult $result */
        $result = $this->rateResultFactory->create();

        /** @var MagentoQuoteModelQuoteAddressRateResultMethod $method */
        $method = $this->rateMethodFactory->create();

        $method->setCarrier($this->_code);
        $method->setCarrierTitle($this->getConfigData('title'));

        $method->setMethod($this->_code);
        $method->setMethodTitle($this->getConfigData('name'));

        $this->_logger->info(__FILE__ . ': At Start');

        // Get all the items.
        // NOTE: This getAllItems here is related to Quote and not the order.
        if ((!($items = $request->getAllItems())) or (count($items) == 0)) {
            return FALSE;
        }

        //Standard code commented. Custom code added.
        //$shippingCost = (float)$this->getConfigData('shipping_cost');
        $shippingCost = (float)$this->helper->compute_standard_shipping_cost($items);

        $method->setPrice($shippingCost);
        $method->setCost($shippingCost);

        $result->append($method);

        return $result;
    }

    /**
     * Get all the allowed methods for Custom Shipping. This sends the CustomShipping
     * method as well as all the allowed methods of Fedex. This is required to ensure
     * the Fedex shipping methods to be considered as valid methods.
     * 
     * @return array
     */
    public function getAllowedMethods()
    {
        $custom_shipping_methods = ($this->_code => $this->getConfigData('name'));
        $allowed_methods = array_merge($custom_shipping_methods, $this->FEDEX_METHODS);
        return $allowed_methods;
    }

    /**
     * get_magento_system_info - receives the path as parameter.
     * This parameter holds the path to the field.
     * This function returns a value in Magento core_config_data table.
     * 
     * @param string $path
     * @return string $config_data
     */
    private function get_magento_system_info($path)
    {
        // Refer https://store.magenest.com/blog/get-set-config-data-programmatically-magento-2/
        // Refer https://firebearstudio.com/blog/how-to-write-and-get-config-values-by-scope-in-magento-2.html

        // Call functions to get config data with default (global) scope
        return $this->scopeConfig->getValue($path);
    }
}

sql server – Color Label printing for Folder Filing

I am creating a report to take 6 digits and print them on a label.
The numbers are assigned a specific color, IE 0=yellow, 1=red, 2=blue and so one. I can go and created the 6 different details. I use HighLighting Expert to assign the rule for the value. Is it possible to copy the setting(s) from 1 detail to another? I will be using this same color coding for other labels.
I don’t want to have to created this over again for every field and change human error!!
Thank you
Cameron

prometheus – Relabel node-exporter series to have common label with kube_state_metrics by regex

I don’t suppose anybody has a handy way of fixing labels such that you can do a group_left/join on one series from kube_state_metrics and one from node-exporter. This is surprisingly difficult to do given that out of the box at least for me they do not share any labels in common that can be pivoted on.

The way I see this I have two options:

  1. somehow mess with the scrape targets such that I can put a common label to the series, which may or may not be possible. Looking at this stuff is complicated. But in any case this increases my cardinality probably in ways I don’t want.

  2. Do a gross regex relabel to create my own common label to pivot on.
    I have the following close-ish labels to work with where I can do a transform to get my pivot point:

instance="10.26.10.113:9100" < node-exporter
internal_ip="10.26.10.113" < kube_state_metrics

I’m doing the following query as a test with the following truncated output

label_replace(node_cpu_seconds_total{mode="idle"}, "instance", "$1", "instance", "(^:)*")

node_cpu_seconds_total{instance="10.26.10.113:9100, mode="idle"}    4975537.86

I would have expected that regex to capture everything before the : and then replace the instance label just that first capture group. It however does not. If I change the second last field of the query, the instance label disappears entirely.

label_replace(node_cpu_seconds_total{mode="idle"}, "instance", "$1", "internal_ip", "(^:)*")
node_cpu_seconds_total{mode="idle"} 4975537.86

What am I doing wrong? I believe the regex is valid RE2 regex syntax according to https://regoio.herokuapp.com/. As best as I can read the documentation, my syntax appears to be correct as well.
https://prometheus.io/docs/prometheus/latest/querying/functions/#label_replace

8 – Why does my shopping cart item not have a label?

I’m working on D8 site with Drupal Commerce.
I have to create a dynamic product variation and add it to cart for the user checkout.

The problem I have, is when you land on the cart page, the line item doesn’t have a label (title) it replaced with the price of the item. Please refer to the attached image.

Here’s my code:

   //create variation
            $variation = ProductVariation::create((
                'type' => 'fk_payment',
                'sku' => 'FK'.$faid,
                'status' => TRUE,
                'price' => new Price($trans->getTotal(), $trans->getCurrency()),
                'title' => "Example item label title",
              ));

            $variation->save();

            //Load the product
            $product_id = 4;
            $product = Product::load($product_id);
            $product->addVariation($variation);
            $product->save();

            //load store
            $storeId = $product->get('stores')->getValue()(0)('target_id');
            $store = Drupal::entityTypeManager()
            ->getStorage('commerce_store')
            ->load($storeId);
            
            //prepare cart
            $cart = Drupal::service('commerce_cart.cart_provider');
            $cart = $cart->getCart('default', $store);
            
            if (!$cart) {
                $cart = Drupal::service('commerce_cart.cart_provider');
                $cart = $cart->createCart('default', $store);
            }

            // Process to place order programatically.
            $cart_manager = Drupal::service('commerce_cart.cart_manager');

            //empty the cart
            if (!empty($cart)) {
                $cart_manager->emptyCart($cart);
            }

            $cart_manager->addEntity($cart, $variation);

enter image description here

Product label designer wanted

If you have past experience in product label designing, please kindly inbox me your portfolio.

Or better if you have participated in any design contest here in DP, please send me the link.

Regards

8 – Why my shopping cart item doesn’t have a label?

I’m working on D8 site with Drupal commerce.
I have to create a dynamic product variation and add to cart for the user checkout.

The problem I have, is when you landed on the cart page, the line item doesn’t have a label (title) it replaced with the price of the item. Please refer to the attached image.

Here’s my code:

   //create variation
            $variation = ProductVariation::create((
                'type' => 'fk_payment',
                'sku' => 'FK'.$faid,
                'status' => TRUE,
                'price' => new Price($trans->getTotal(), $trans->getCurrency()),
                'title' => "Example item label title",
              ));

            $variation->save();

            //Load the product
            $product_id = 4;
            $product = Product::load($product_id);
            $product->addVariation($variation);
            $product->save();

            //load store
            $storeId = $product->get('stores')->getValue()(0)('target_id');
            $store = Drupal::entityTypeManager()
            ->getStorage('commerce_store')
            ->load($storeId);
            
            //prepare cart
            $cart = Drupal::service('commerce_cart.cart_provider');
            $cart = $cart->getCart('default', $store);
            
            if (!$cart) {
                $cart = Drupal::service('commerce_cart.cart_provider');
                $cart = $cart->createCart('default', $store);
            }

            // Process to place order programatically.
            $cart_manager = Drupal::service('commerce_cart.cart_manager');

            //empty the cart
            if (!empty($cart)) {
                $cart_manager->emptyCart($cart);
            }

            $cart_manager->addEntity($cart, $variation);

enter image description here

plotting – How can I label a table of histograms with the names of the data symbols, not the data themselves?

How can I label a table of histograms with the names of the data symbols, not the data themselves?

If I want to make a table of plots with each plot labeled with the name of the function it plots, this is simple:

f[x_] := x; g[x_] := x^2;
Table[Plot[p[x], {x, -1, 1}, PlotLabel -> p], {p, {f, g}}]

However, if I want to do the same for Histogram, I have not figured out how. I have tried various combinations using ToString, Hold, HoldForm, and Unevaluated, as well as ChartLabels. For example,

l = RandomReal[{0, 1}, 20]; m = RandomReal[{0, 1}, 20];
Table[Histogram[p, PlotLabel -> p], {p, {l, m}}]

does not work, as the labels are the values of l and m, not the strings l and m.

The same question applies to the format analogous to

Plot[#[x], {x, -1, 1}, PlotLabel -> #] & /@ {f, g}

which works for Plot but not for Histogram.

Google Sheets: Line Graph of alternating columns. 1st Column as label

Month Notes January Notes February
Net Worth $500 $600
Liabilities $50 $40
Credit Cards $10 $20
Credit Card 1 $5 $10
Credit Cards 2 $5 $10
Savings & Checking $400 $500
Investments $100 $200

I have a google spreadsheet I use for tracking monthly financials that looks something like this. I use a new tab or sheet per year.
I was looking to add a Dashboard to the first tab that would display an individual line for each row.

Essentially I want the row and column labels to be the same I have here but translate the numerical values into a line graph.

I have attempted to select all of the cells with the respective data manually. I have tried selecting the ranges – but with my notes columns and there are detailed rows underneath each of the rows displayed here i.e. credit cards have a row each for each card, etc. So the rows and columns in the sheet are not exactly contiguous. I’m pretty sure I’ll have to manually click each item. I have also tried selecting a row with the column intended become that row’s label and the numeric values in that row as the plotted lines – but that doesn’t seem to work very well either. Especially if I try to add more than one row. to display multiple lines.

r – how to label lines when they are from different columns in ggplot

My dataframe is like

Date Y1 Y2
1   1   1
2   2   1
3   2   4
4   5   4
5   2   3
...

I use the following piece to plot Y1 and Y2

ggplot(aes(x = date))+
    geom_line(aes(y = Y1), color = "darkred", size = 1) + 
    geom_line(aes(y = Y2), color = "steelblue", size = 1) +
    geom_vline(xintercept = 2, linetype= 'dashed')+
    theme(panel.background = element_blank(),
          legend.position = 'bottom',
          plot.title = element_text(hjust = 0.5, size = 14))

But the legend option did not work and the figure has no legend.
How can I add the legend or label to the lines including the vertical one?
Thanks a lot for your help.