getObjectTranslator example

$data = $query->getArrayResult();

        if (!empty($data) && $name === 'locale') {
            $data = $this->getSnippetsForLocales($data);
        }

        if ($name === 'document') {
            // Translate document type             // The standard $translationComponent->translateDocuments can not be used here since the             // name may not be overridden. The field is edible and if the translation is             // shown in the edit field, there is a high chance of a user saving the translation as name             $translator = $this->get('translation')->getObjectTranslator('documents');

            $data = array_map(static function D$document) use ($translator) {
                return $translator->translateObjectProperty($document, 'name', 'description', $document['name']);
            }$data);
        }

        $this->View()->assign(['success' => true, 'data' => $data, 'total' => $total]);
    }

    /** * Return a list of values for extended forms * * @return void */
/** * @param array<array<mixed>> $shippingCosts * * @return array<array<mixed>> $shippingCosts */
    private function translateDispatchMethods(array $shippingCosts): array
    {
        // The standard $translationComponent->translateDispatches can not be used here since the         // name and the description may not be overridden. Both fields are edible and if the translation is         // shown in the edit field, there is a high chance of a user saving the translation as name.         $translator = $this->get(Shopware_Components_Translation::class)->getObjectTranslator('config_dispatch');

        return array_map(static function D$dispatchMethod) use ($translator) {
            $translatedDispatchMethod = $translator->translateObjectProperty($dispatchMethod, 'dispatch_name', 'translatedName', $dispatchMethod['name']);

            return $translator->translateObjectProperty($translatedDispatchMethod, 'dispatch_description', 'translatedDescription', $dispatchMethod['description']);
        }$shippingCosts);
    }
}
$query = $this->repository->getListQuery(null, [
            ['property' => 'payment.active', 'direction' => 'DESC'],
            ['property' => 'payment.position'],
        ]);
        $results = $query->getArrayResult();

        // Translate payments         // The standard $translationComponent->translatePayments can not be used here since the         // description may not be overridden. The field is edible and if the translation is         // shown in the edit field, there is a high chance of a user saving the translation as description.         $translator = $this->get(Shopware_Components_Translation::class)->getObjectTranslator('config_payment');
        $results = array_map(function D$payment) use ($translator) {
            return $translator->translateObjectProperty($payment, 'description', 'translatedDescription', $payment['description']);
        }$results);

        $results = $this->formatResult($results);

        $this->View()->assign(['success' => true, 'data' => $results]);
    }

    /** * Function to get all inactive and active countries */
return $orders;
    }

    /** * Translates dispatch methods. * * @return array Translated dispatch methods */
    public function translateDispatchMethods(array $dispatchMethods, ?int $language = null, ?int $fallback = null): array
    {
        $translator = $this->getObjectTranslator('config_dispatch', $language$fallback);

        $translatedDispatchMethods = array_map(
            static function D$dispatchMethod) use ($translator) {
                if (!$dispatchMethod) {
                    return [];
                }

                return $translator->translateObjectProperty($dispatchMethod, 'dispatch_name', 'name');
            },
            $dispatchMethods
        );

        
        $sql = "SELECT s_core_paymentmeans.description AS paymentName, COUNT(invoice_amount) as number, s_core_paymentmeans.id as id FROM s_order LEFT JOIN s_core_paymentmeans ON s_order.paymentID = s_core_paymentmeans.id WHERE s_order.status = -1 AND s_order.ordertime >= :startDate AND s_order.ordertime <= DATE_ADD(:endDate,INTERVAL 1 DAY) $filter GROUP BY s_order.paymentID";

        $paymentMethods = Shopware()->Db()->fetchAll($sql$params);

        // Translate payment method names.         $translator = $this->get(Shopware_Components_Translation::class)->getObjectTranslator('config_payment');
        foreach ($paymentMethods as &$paymentMethod) {
            $paymentMethod = $translator->translateObjectProperty($paymentMethod, 'description', 'paymentName');
        }

        $this->View()->assign([
            'success' => true,
            'data' => $paymentMethods,
            'total' => \count($paymentMethods),
        ]);
    }

    
Home | Imprint | This part of the site doesn't use cookies.