-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/woocommerce-integration' into master
- Loading branch information
Showing
162 changed files
with
23,278 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Controllers; | ||
|
||
use Timber\Timber; | ||
|
||
class ProductController extends Controller | ||
{ | ||
/** @var array */ | ||
protected array $data; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
$this->data = Timber::context(); | ||
} | ||
|
||
public function index(): array | ||
{ | ||
$this->data['product'] = wc_get_product(get_the_ID()); | ||
$this->data['post'] = Timber::get_post(); | ||
$this->data['categories'] = get_the_terms(get_the_ID(), 'product_cat'); | ||
|
||
$related_limit = wc_get_loop_prop('columns'); | ||
$related_ids = wc_get_related_products(get_the_ID(), $related_limit); | ||
$this->data['related_products'] = Timber::get_posts($related_ids); | ||
|
||
return $this->data; | ||
} | ||
|
||
public function category(): array | ||
{ | ||
$queried_object = get_queried_object(); | ||
$term_id = $queried_object->term_id; | ||
$this->data['category'] = get_term($term_id, 'product_cat'); | ||
$this->data['title'] = single_term_title('', false); | ||
|
||
return $this->data; | ||
} | ||
|
||
public function archive(): array | ||
{ | ||
$this->data['attributes'] = array_map(fn ($taxonomy) => [ | ||
'label' => $taxonomy->attribute_label, | ||
'name' => $taxonomy->attribute_name, | ||
'terms' => get_terms([ | ||
'taxonomy' => 'pa_' . $taxonomy->attribute_name, | ||
'hide_empty' => false, | ||
]) ?? [], | ||
], wc_get_attribute_taxonomies()); | ||
|
||
return $this->data; | ||
} | ||
|
||
public function cart(): array | ||
{ | ||
$this->data['coupons_enabled'] = wc_coupons_enabled(); | ||
|
||
return $this->data; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
use Carbon_Fields\Container; | ||
use Carbon_Fields\Field; | ||
|
||
// not works with woo new form | ||
Container::make('post_meta', __('Products Data')) | ||
->where('post_type', '=', 'product') | ||
->add_fields([ | ||
Field::make('text', 'sub_title', 'Sub-title'), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
use Core\CustomWooVariants; | ||
|
||
CustomWooVariants::create('Name', 'name', 'text', []); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
if (!wp_verify_nonce($_POST['nonce'], 'ajax-nonce')) { | ||
wp_send_json(['type' => 'error', 'message' => 'nonce_error']); | ||
} | ||
|
||
$product_id = absint($_POST['product_id']); | ||
$variation_id = $_POST['variation'] ? absint($_POST['variation']) : 0; | ||
|
||
try { | ||
$result = WC()->cart->add_to_cart($product_id, absint($_POST['quantity']), $variation_id); | ||
if (!$result) { | ||
wp_send_json(['type' => 'error', 'message' => 'Error adding to cart']); | ||
} | ||
} catch (Exception $e) { | ||
wp_send_json(['type' => 'error', 'message' => $e->getMessage()]); | ||
} | ||
|
||
$cart = WC()->cart->get_cart(); | ||
$cart_data = []; | ||
|
||
foreach ($cart as $cart_item_key => $cart_item) { | ||
$_product = $cart_item['data']; | ||
$sale_price = null; | ||
|
||
if (!empty($_product->get_sale_price())) { | ||
$sale_price = wc_price($_product->get_sale_price()); | ||
} | ||
|
||
$item_data = [ | ||
'id' => $cart_item['product_id'], | ||
'name' => $_product->get_name(), | ||
'link' => get_permalink($cart_item['product_id']), | ||
'thumbnail' => $_product->get_image(), | ||
'quantity' => $cart_item['quantity'], | ||
'cart_item_key' => $result, | ||
'regular_price' => wc_price($_product->get_regular_price()), | ||
'sale_price' => $sale_price, | ||
]; | ||
|
||
$cart_data[] = $item_data; | ||
} | ||
|
||
wp_send_json([ | ||
'type' => 'success', | ||
'message' => 'Product added to the cart.', | ||
'cart' => $cart_data, | ||
'total' => number_format(WC()->cart->get_cart_contents_total(), 2, '.', ''), | ||
'subTotal' => WC()->cart->get_subtotal(), | ||
'count' => WC()->cart->get_cart_contents_count(), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
if (!wp_verify_nonce($_POST['nonce'], 'ajax-nonce')) { | ||
wp_send_json(['type' => 'error', 'message' => 'nonce_error']); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
if (!wp_verify_nonce($_POST['nonce'], 'ajax-nonce')) { | ||
wp_send_json(['type' => 'error', 'message' => 'nonce_error']); | ||
} | ||
|
||
$key = sanitize_text_field($_POST['key']); | ||
|
||
$response = WC()->cart->remove_cart_item($key); | ||
|
||
$total = WC()->cart->get_cart_contents_total(); | ||
$subTotal = WC()->cart->get_subtotal(); | ||
$cartItemCount = WC()->cart->get_cart_contents_count(); | ||
|
||
if ($response) { | ||
wp_send_json([ | ||
'type' => 'success', | ||
'message' => 'Product removed from the cart.', | ||
'total' => number_format($total, 2, '.', ''), | ||
'subTotal' => $subTotal, | ||
'count' => $cartItemCount | ||
]); | ||
} else { | ||
wp_send_json(['type' => 'error', 'response' => $response]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["resources/assets/src/scripts/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import axios from 'axios' | ||
import Toast from '@/libs/Toast' | ||
|
||
export function addToCart() { | ||
const preloader = document.querySelector('.js-preloader-main') | ||
const addButtons = document.querySelectorAll('.js-add-to-cart') | ||
|
||
const totals = document.querySelectorAll('.js-total') | ||
const subTotals = document.querySelectorAll('.js-sub-total') | ||
const cartCount = document.querySelector('.js-cart-total') | ||
|
||
const cartList = document.querySelector('.js-cart-list') | ||
const addedProduct = product => { | ||
return ` | ||
<tr class="js-cart-item" data-ajax="true" data-key="${product.cart_item_key}"> | ||
<td class="text-center"> | ||
<a href="${product.link}" class="d-block thumb-sm"> | ||
${product.thumbnail} | ||
</a> | ||
</td> | ||
<td class="text-start"> | ||
<a href="${product.link}">${product.name}</a> | ||
</td> | ||
<td>x${product.quantity}</td> | ||
<td class="text-end"> | ||
${product.sale_price ? `${product.sale_price}` : `${product.regular_price}`} | ||
</td> | ||
<td class="text-end"> | ||
<button type="button" data-key="${product.cart_item_key}" title="Remove" class="btn btn-danger js-remove-from-cart"> | ||
<i class="fa-solid fa-circle-xmark"></i> | ||
</button> | ||
</td> | ||
</tr>` | ||
} | ||
addButtons.forEach(addButton => { | ||
addButton.addEventListener('click', async event => { | ||
preloader.classList.add('js-preloading') | ||
|
||
const formData = new FormData() | ||
formData.append('action', 'addToCart') | ||
formData.append('nonce', data.nonce) | ||
formData.append('product_id', addButton.dataset.product_id) | ||
formData.append('quantity', addButton.dataset.quantity) | ||
if (addButton.dataset.variation) { | ||
formData.append('variation', addButton.dataset.variation) | ||
} | ||
|
||
try { | ||
const { data: response } = await axios.post(data.ajax_url, formData, { | ||
params: { action: 'addToCart' } | ||
}) | ||
|
||
if (response.type === 'success') { | ||
// totals | ||
totals.forEach(totalElement => { | ||
totalElement.innerHTML = response.total | ||
}) | ||
|
||
// sub-totals | ||
subTotals.forEach(subTotalElement => { | ||
subTotalElement.innerHTML = response.subTotal | ||
}) | ||
|
||
cartCount.innerHTML = response.count | ||
|
||
// cart items | ||
if (response.cart) { | ||
cartList.innerHTML = '' | ||
response.cart.forEach(product => { | ||
const newProduct = addedProduct(product) // Pass each product data to your addedProduct function | ||
cartList.innerHTML += newProduct | ||
}) | ||
} | ||
|
||
Toast.fire({ icon: 'success', iconColor: '#007cba', title: response.message }) | ||
} | ||
|
||
if (response.type === 'error') { | ||
Toast.fire({ icon: 'error', iconColor: 'red', title: response.message }) | ||
} | ||
|
||
preloader.classList.remove('js-preloading') | ||
} catch (error) { | ||
preloader.classList.remove('js-preloading') | ||
console.error(error) | ||
} | ||
}) | ||
}) | ||
} |
Oops, something went wrong.