クラス
Cart
ソース ソース
ファイル: src/Components/Cart/Cart.php
class Cart
{
/**
* Loads cart CSS
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
public static function loadCss() {
wp_enqueue_style(
'wcexics-cart',
WCEXICS_PLUGIN_URL . '/src/Components/Cart/cart.css',
[],
WCEXICS_VERSION
);
}
/**
* Builds HTML for a combo-set cart item
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param array $rows group items cart
* @return string
*/
public static function getComboSetCartDetailsHtml($rows) {
$groupshtml = '<div class="wcexics combo-set-cart">';
foreach ($rows as $row) {
$gitemhtml = '';
foreach ($row['groupItems'] as $item) {
$hookargs = [
'item' => $item,
'row' => $row,
'rows' => $rows,
];
$gitemhtml .= '<li>';
$gitemhtml .= apply_filters(
'wcexics_filter_cart_details_html_item_name',
'<div>' . $item['name'] . '</div>',
$hookargs
);
$options = $item['options'];
if (is_array($options) && count($options) > 0) {
$optstr = '';
foreach ($options as $key => $value) {
if (!empty($key)) {
$key = urldecode($key);
if (is_array($value)) {
$c = '';
$optstr .= esc_html($key) . ' : ';
foreach ($value as $v) {
$optstr .= $c . nl2br(esc_html(urldecode($v)));
$c = ', ';
}
$optstr .= "<br />\n";
} else {
$optstr .= esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value))) . "<br />\n";
}
}
}
if (!empty($optstr)) {
$gitemhtml .= '<div class="combo-set-cart-group-item-options">';
$gitemhtml .= '<div class="combo-set-cart-group-item-options__label">';
$gitemhtml .= '(' . __('options for items', 'usces') . ')';
$gitemhtml .= '</div>';
$gitemhtml .= '<div class="combo-set-cart-group-item-options__values">';
$gitemhtml .= $optstr;
$gitemhtml .= '</div>';
$gitemhtml .= '</div>';
}
}
$gitemhtml .= '</li>';
}
$groupshtml .= '<div class="combo-set-cart__group-label">' . $row['groupLabel'] . '</div>';
$groupshtml .= '<div class="combo-set-cart__group-item"><ul>' . $gitemhtml . '</ul></div>';
}
$groupshtml .= '</div>';
return $groupshtml;
}
/**
* Builds a details string for a combo-set cart item
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param array $rows
* @param bool $add_dashes
* @return string
*/
public static function getComboSetCartDetailsNoHtml($rows, $add_dashes = true) {
$details = '';
foreach ($rows as $row) {
$rowdetails = '';
foreach ($row['groupItems'] as $item) {
$ddash = $add_dashes ? '--' : '';
$tdash = $add_dashes ? '---' : '';
$rowdetails .= "{$ddash}" . wp_strip_all_tags($item['name']);
$options = $item['options'];
if (is_array($options) && count($options) > 0) {
$optstr = '';
foreach ($options as $key => $value) {
if (!empty($key)) {
$key = urldecode($key);
if (is_array($value)) {
$c = '';
$optstr .= "\r\n\t\t{$tdash} " . esc_html($key) . ' : ';
foreach ($value as $v) {
$optstr .= $c . nl2br(esc_html(urldecode($v)));
$c = ', ';
}
} else {
$optstr .= "\r\n\t\t{$tdash} " . esc_html($key) . ' : ' . nl2br(esc_html(urldecode($value)));
}
}
}
if (!empty($optstr)) {
$rowdetails .= "\r\n\t\t{$tdash} (" . __('options for items', 'usces') . ')';
$rowdetails .= $optstr;
}
}
}
$details .= "\r\n" . $row['groupLabel'];
$details .= ' : ';
$details .= $rowdetails;
}
return $details;
}
/**
* Builds a details string for a combo-set cart item (space separated for CSV)
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param array $rows
* @return string
*/
public static function getComboSetCartDetailsSpaceSeparated($rows) {
$ext = 'csv';
$sp = ':';
$nb = ' ';
$groups = [];
foreach ($rows as $row) {
$itemlist = [];
foreach ($row['groupItems'] as $item) {
$itemlist[] = wp_strip_all_tags($item['name']);
if (!empty($item['options']) && is_array($item['options'])) {
$optstrs = [];
foreach ($item['options'] as $key => $value) {
$meta_value = maybe_unserialize($value);
if (is_array($meta_value)) {
$meta_vals = '';
foreach ($meta_value as $array_val) {
$meta_vals .= $nb . urldecode($array_val);
}
$optstrs[] = usces_entity_decode(urldecode($key) . $sp . $meta_vals, $ext);
} else {
$optstrs[] = usces_entity_decode(urldecode($key) . $sp . urldecode($value), $ext);
}
}
$itemlist[] = join($nb, $optstrs);
}
}
$groups[] = usces_entity_decode(
urldecode($row['groupLabel']) . $sp . urldecode(join($nb, $itemlist)),
$ext
);
}
$details = join($nb, $groups);
return $details;
}
}
- getComboSetCartDetailsHtml — Builds HTML for a combo-set cart item
- getComboSetCartDetailsNoHtml — Builds a details string for a combo-set cart item
- getComboSetCartDetailsSpaceSeparated — Builds a details string for a combo-set cart item (space separated for CSV)
- loadCss — Loads cart CSS