Lấy được product ID từ commerce Promotion trong Drupal 8

Lấy được product ID từ commerce Promotion trong Drupal 8

Trong bài viết này mình sẽ chỉ cho bạn cách lấy product ID từ Promotion Entity. Bài viết này áp dụng trên CMS Drupal 8

>> Hướng dẫn in ra câu truy vấn SQL queries để debugging trong Drupal 8

>> Hướng dẫn tạo Pager trong Drupal 8 không cần DB_SELECT() và PAGERDEFAULT

Load the promotions

$promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion')->loadMultiple();

foreach ($promotions as $promotion) {
// Load the offer for the promotion
$offer = $promotion->getOffer();
// Load the configuration for the offer
$conf = $offer->getConfiguration();
// Then you can find the list of products for this offer
$offer_products = $conf['conditions'][0]['configuration']['products'];

// The offer_products array contains the uuid of the products to obtain the product id you have to use

// Drupal\commerce\EntityUuidMapperInterface -> mapToIds()

// Cicle on offer_products and get the id foreach product
foreach ($offer_products as $key => $value) {
    $product_id = $this->entityUuidMapper->mapToIds('commerce_product', [$value['product']]);
}
Bạn thấy bài viết này như thế nào?: 
Average: 10 (2 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Hướng dẫn Solr Integrations với Drupal Sarnia Module

Hướng dẫn Solr Integrations với Drupal Sarnia Module

Every day, companies and organizations with lots of content are weighing the pros and cons of adopting Drupal.

Google Adsense

Kiếm tiền Google Adsense thành công 100%

Google Adsense (GA) là một dịch vụ miễn phí để các nhà phát triển web kiếm tiền bằng cách hiển thị quảng cáo của Google. GA bao gồm GA Search, GA Content ...

Đã có Facebook Messenger cho Windows!

Đã có Facebook Messenger cho Windows!

Facebook Messenger dành cho Windows nay không còn ở chế độ thử nghiệm cá nhân nữa, mà đã có bản download chính thức ngay tại trang Help Center ...

Công ty diệt chuột T&C

 

Diet con trung