diff --git a/WC_Pagantis.php b/WC_Pagantis.php
index 41bf1b3..334d784 100644
--- a/WC_Pagantis.php
+++ b/WC_Pagantis.php
@@ -3,7 +3,7 @@
* Plugin Name: Pagantis
* Plugin URI: http://www.pagantis.com/
* Description: Financiar con Pagantis
- * Version: 8.1.3
+ * Version: 8.2.0
* Author: Pagantis
*/
@@ -33,20 +33,21 @@ class WcPagantis
const ORDERS_TABLE = 'posts';
public $defaultConfigs = array('PAGANTIS_TITLE'=>'Instant Financing',
- 'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'pgSDK.simulator.types.SIMPLE',
- 'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'pgSDK.simulator.skins.BLUE',
- 'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons',
- 'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3,
- 'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12,
- 'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default',
- 'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'pgSDK.simulator.positions.INNER',
- 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'a:3:{i:0;s:48:"div.summary *:not(del)>.woocommerce-Price-amount";i:1;s:54:"div.entry-summary *:not(del)>.woocommerce-Price-amount";i:2;s:36:"*:not(del)>.woocommerce-Price-amount";}',
- 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'a:2:{i:0;s:22:"div.quantity input.qty";i:1;s:18:"div.quantity>input";}',
- 'PAGANTIS_FORM_DISPLAY_TYPE'=>0,
- 'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1,
- 'PAGANTIS_URL_OK'=>'',
- 'PAGANTIS_URL_KO'=>'',
- 'PAGANTIS_ALLOWED_COUNTRIES' => 'a:2:{i:0;s:2:"es";i:1;s:2:"it";}'
+ 'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'pgSDK.simulator.types.SIMPLE',
+ 'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'pgSDK.simulator.skins.BLUE',
+ 'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons',
+ 'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3,
+ 'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12,
+ 'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default',
+ 'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'pgSDK.simulator.positions.INNER',
+ 'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'a:3:{i:0;s:48:"div.summary *:not(del)>.woocommerce-Price-amount";i:1;s:54:"div.entry-summary *:not(del)>.woocommerce-Price-amount";i:2;s:36:"*:not(del)>.woocommerce-Price-amount";}',
+ 'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'a:2:{i:0;s:22:"div.quantity input.qty";i:1;s:18:"div.quantity>input";}',
+ 'PAGANTIS_FORM_DISPLAY_TYPE'=>0,
+ 'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1,
+ 'PAGANTIS_URL_OK'=>'',
+ 'PAGANTIS_URL_KO'=>'',
+ 'PAGANTIS_ALLOWED_COUNTRIES' => 'a:2:{i:0;s:2:"es";i:1;s:2:"it";}',
+ 'PAGANTIS_PROMOTION_EXTRA' => '
Finance this product without interest!
'
);
/** @var Array $extraConfig */
@@ -73,6 +74,73 @@ public function __construct()
add_action('rest_api_init', array($this, 'pagantisRegisterEndpoint')); //Endpoint
add_filter('load_textdomain_mofile', array($this, 'loadPagantisTranslation'), 10, 2);
register_activation_hook(__FILE__, array($this, 'pagantisActivation'));
+ add_action('woocommerce_product_options_general_product_data', array($this, 'pagantisPromotedProductTpl'));
+ add_action('woocommerce_process_product_meta', array($this, 'pagantisPromotedVarSave'));
+ add_action('woocommerce_product_bulk_edit_start', array($this,'pagantisPromotedBulkTemplate'));
+ add_action('woocommerce_product_bulk_edit_save', array($this,'pagantisPromotedBulkTemplateSave'));
+ }
+
+ /**
+ * Piece of html code to insert into BULK admin edit
+ */
+ public function pagantisPromotedBulkTemplate()
+ {
+ echo '
+
+
';
+ }
+
+ /**
+ * Php code to save our meta after a bulk admin edit
+ * @param $product
+ */
+ public function pagantisPromotedBulkTemplateSave($product)
+ {
+ $post_id = $product->get_id();
+ $pagantis_promoted_value = $_REQUEST['pagantis_promoted'];
+ if ($pagantis_promoted_value == 'on') {
+ $pagantis_promoted_value = 'yes';
+ } else {
+ $pagantis_promoted_value = 'no';
+ }
+
+ update_post_meta($post_id, 'custom_product_pagantis_promoted', esc_attr($pagantis_promoted_value));
+ }
+
+ /**
+ * Piece of html code to insert into PRODUCT admin edit
+ */
+ public function pagantisPromotedProductTpl()
+ {
+ global $post;
+ $_product = get_post_meta($post->ID);
+ woocommerce_wp_checkbox(
+ array(
+ 'id' => 'pagantis_promoted',
+ 'label' => __('Pagantis promoted', 'woocommerce'),
+ 'value' => $_product['custom_product_pagantis_promoted']['0'],
+ 'cbvalue' => 'yes',
+ 'echo' => true
+ )
+ );
+ }
+
+ /**
+ * Php code to save our meta after a PRODUCT admin edit
+ * @param $post_id
+ */
+ public function pagantisPromotedVarSave($post_id)
+ {
+ $pagantis_promoted_value = $_POST['pagantis_promoted'];
+ if ($pagantis_promoted_value == null) {
+ $pagantis_promoted_value = 'no';
+ }
+ update_post_meta($post_id, 'custom_product_pagantis_promoted', esc_attr($pagantis_promoted_value));
}
/*
@@ -205,6 +273,7 @@ public function pagantisAddProductSimulator()
return;
}
+ $post_id = $product->get_id();
$template_fields = array(
'total' => is_numeric($product->price) ? $product->price : 0,
'public_key' => $cfg['pagantis_public_key'],
@@ -213,7 +282,9 @@ public function pagantisAddProductSimulator()
'quantitySelector' => unserialize($this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']),
'priceSelector' => unserialize($this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']),
'totalAmount' => is_numeric($product->price) ? $product->price : 0,
- 'locale' => $locale
+ 'locale' => $locale,
+ 'promoted' => $this->isPromoted($post_id),
+ 'promotedMessage' => $this->extraConfig['PAGANTIS_PROMOTION_EXTRA']
);
wc_get_template('product_simulator.php', $template_fields, '', $this->template_path);
}
@@ -285,7 +356,7 @@ public function pagantisRowMeta($links, $file)
if ($file == plugin_basename(__FILE__)) {
$links[] = ''.__('Documentation', 'pagantis').'';
$links[] = ''.
- __('API documentation', 'pagantis').'';
+ __('API documentation', 'pagantis').'';
$links[] = ''.__('Support', 'pagantis').'';
return $links;
@@ -430,10 +501,10 @@ public function pagantisRegisterEndpoint()
'pagantis/v1',
'/logs/(?P\w+)/(?P\d+)/(?P\d+)',
array(
- 'methods' => 'GET',
- 'callback' => array(
- $this,
- 'readLogs')
+ 'methods' => 'GET',
+ 'callback' => array(
+ $this,
+ 'readLogs')
),
true
);
@@ -510,6 +581,17 @@ private function preparePriceSelector($css_price_selector)
return $css_price_selector;
}
+
+ /**
+ * @param $product_id
+ *
+ * @return string
+ */
+ private function isPromoted($product_id)
+ {
+ $metaProduct = get_post_meta($product_id);
+ return ($metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false';
+ }
}
/**
diff --git a/controllers/notifyController.php b/controllers/notifyController.php
index cc2c460..686e0de 100755
--- a/controllers/notifyController.php
+++ b/controllers/notifyController.php
@@ -336,6 +336,18 @@ private function saveOrder()
global $woocommerce;
$paymentResult = $this->woocommerceOrder->payment_complete();
if ($paymentResult) {
+ $metadataOrder = $this->pagantisOrder->getMetadata();
+ $metadataInfo = null;
+ foreach ($metadataOrder as $metadataKey => $metadataValue) {
+ if ($metadataKey == 'promotedProduct') {
+ $metadataInfo.= "/Producto promocionado = $metadataValue";
+ }
+ }
+
+ if ($metadataInfo != null) {
+ $this->woocommerceOrder->add_order_note($metadataInfo);
+ }
+
$this->woocommerceOrder->add_order_note("Notification received via $this->origin");
$this->woocommerceOrder->reduce_order_stock();
$this->woocommerceOrder->save();
diff --git a/controllers/paymentController.php b/controllers/paymentController.php
index ecda450..0a064b7 100755
--- a/controllers/paymentController.php
+++ b/controllers/paymentController.php
@@ -14,6 +14,7 @@
use Pagantis\OrdersApiClient\Model\Order\Configuration;
use Pagantis\OrdersApiClient\Client;
use Pagantis\OrdersApiClient\Model\Order;
+use Pagantis\ModuleUtils\Model\Log\LogEntry;
if (!defined('ABSPATH')) {
exit;
@@ -243,10 +244,21 @@ public function pagantisReceiptPage($order_id)
$orderUser->addOrderHistory($orderHistory);
}
+ $metadataOrder = new Metadata();
+ $metadata = array(
+ 'woocommerce' => WC()->version,
+ 'pagantis' => $this->plugin_info['Version'],
+ 'php' => phpversion()
+ );
+ foreach ($metadata as $key => $metadatum) {
+ $metadataOrder->addMetadata($key, $metadatum);
+ }
+
$details = new Details();
$shippingCost = $order->shipping_total;
$details->setShippingCost(intval(strval(100 * $shippingCost)));
$items = $woocommerce->cart->get_cart();
+ $promotedAmount = 0;
foreach ($items as $key => $item) {
$product = new Product();
$productDescription = sprintf(
@@ -258,15 +270,26 @@ public function pagantisReceiptPage($order_id)
$product
->setAmount(intval(100 * $item['line_total']))
->setQuantity($item['quantity'])
- ->setDescription($productDescription);
+ ->setDescription($productDescription)
+ ;
$details->addProduct($product);
+
+ $promotedProduct = $this->isPromoted($item['product_id']);
+ if ($promotedProduct == 'true') {
+ $promotedAmount+=$product->getAmount();
+ $promotedMessage = 'Promoted Item: ' . $product->getDescription() .
+ ' Price: ' . $item['line_total'] .
+ ' Qty: ' . $product->getQuantity() .
+ ' Item ID: ' . $item['id_product'];
+ $metadataOrder->addMetadata('promotedProduct', $promotedMessage);
+ }
}
$orderShoppingCart = new ShoppingCart();
$orderShoppingCart
->setDetails($details)
->setOrderReference($order->get_id())
- ->setPromotedAmount(0)
+ ->setPromotedAmount($promotedAmount)
->setTotalAmount(intval(strval(100 * $order->total)))
;
$orderConfigurationUrls = new Urls();
@@ -295,15 +318,7 @@ public function pagantisReceiptPage($order_id)
->setUrls($orderConfigurationUrls)
->setPurchaseCountry($this->language)
;
- $metadataOrder = new Metadata();
- $metadata = array(
- 'woocommerce' => WC()->version,
- 'pagantis' => $this->plugin_info['Version'],
- 'php' => phpversion()
- );
- foreach ($metadata as $key => $metadatum) {
- $metadataOrder->addMetadata($key, $metadatum);
- }
+
$orderApiClient = new Order();
$orderApiClient
->setConfiguration($orderConfiguration)
@@ -467,6 +482,7 @@ public function payment_fields()
$locale = strtolower(strstr(get_locale(), '_', true));
$allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
$allowedCountry = (in_array(strtolower($locale), $allowedCountries));
+ $promotedAmount = $this->getPromotedAmount();
$template_fields = array(
'public_key' => $this->pagantis_public_key,
@@ -476,7 +492,8 @@ public function payment_fields()
'simulator_enabled' => $this->settings['pagantis_simulator'],
'locale' => $locale,
'allowedCountry' => $allowedCountry,
- 'simulator_type' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE']
+ 'simulator_type' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'],
+ 'promoted_amount' => $promotedAmount
);
wc_get_template('checkout_description.php', $template_fields, '', $this->template_path);
}
@@ -811,4 +828,33 @@ private function checkDbLogTable()
}
return;
}
+
+ /**
+ * @param $product_id
+ *
+ * @return string
+ */
+ private function isPromoted($product_id)
+ {
+ $metaProduct = get_post_meta($product_id);
+ return ($metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false';
+ }
+
+ /**
+ * @return int
+ */
+ private function getPromotedAmount()
+ {
+ global $woocommerce;
+ $items = $woocommerce->cart->get_cart();
+ $promotedAmount = 0;
+ foreach ($items as $key => $item) {
+ $promotedProduct = $this->isPromoted($item['product_id']);
+ if ($promotedProduct == 'true') {
+ $promotedAmount+=$item['line_total'];
+ }
+ }
+
+ return $promotedAmount;
+ }
}
diff --git a/generate.sh b/generate.sh
index 68646ef..93e2157 100755
--- a/generate.sh
+++ b/generate.sh
@@ -59,3 +59,7 @@ then
vendor/bin/phpunit --group woocommerce3-buy
fi
fi
+
+containerPort=$(docker container port ${container})
+PORT=$(sed -e 's/.*://' <<< $containerPort)
+echo 'Build of Woocommerce complete: http://'${container}'.docker:'${PORT}
\ No newline at end of file
diff --git a/templates/checkout_description.php b/templates/checkout_description.php
index 627a24d..053d0d4 100644
--- a/templates/checkout_description.php
+++ b/templates/checkout_description.php
@@ -38,6 +38,7 @@ function loadSimulator()
publicKey: '',
selector: '.pagantisSimulator',
totalAmount: '',
+ totalPromotedAmount: '',
locale: locale
});
return false;
diff --git a/templates/product_simulator.php b/templates/product_simulator.php
index 9c79987..067b438 100644
--- a/templates/product_simulator.php
+++ b/templates/product_simulator.php
@@ -66,18 +66,24 @@ function loadSimulatorPagantis()
}
var priceSelector = findPriceSelector();
-
+ var promotedProduct = '';
var quantitySelector = findQuantitySelector();
+ simulator_options = {
+ publicKey: '',
+ type: ,
+ selector: positionSelector,
+ itemQuantitySelector: quantitySelector,
+ locale: locale,
+ itemAmountSelector: priceSelector
+ };
+
+ if (promotedProduct == 'true') {
+ simulator_options.itemPromotedAmountSelector = priceSelector;
+ }
+
if (typeof sdk != 'undefined') {
- window.WCSimulatorId = sdk.simulator.init({
- publicKey: '',
- type: ,
- selector: positionSelector,
- itemQuantitySelector: quantitySelector,
- itemAmountSelector: priceSelector,
- locale: locale
- });
+ window.WCSimulatorId = sdk.simulator.init(simulator_options);
return false;
}
}
@@ -87,4 +93,14 @@ function loadSimulatorPagantis()
loadSimulatorPagantis();
}, 2000);
+
+