-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixed handling when trying to exceed stock
- added iso-messages in frontend - system messages now list individual products out of stock
- Loading branch information
Showing
6 changed files
with
84 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,28 @@ | |
/** | ||
* Contao Open Source CMS | ||
* | ||
* Copyright (c) 2005-2017 Leo Feyer | ||
* Copyright (c) 2005-2021 Leo Feyer | ||
* | ||
* @package Isotope Simple ERP | ||
* @author Benny Born <[email protected]> | ||
* @author Michael Bösherz <[email protected]> | ||
* @license LGPL | ||
* @copyright 2017 numero2 - Agentur für Internetdienstleistungen | ||
* @copyright 2021 numero2 - Agentur für digitales Marketing | ||
*/ | ||
|
||
|
||
namespace numero2\IsotopeSimpleERP; | ||
|
||
use Contao\System; | ||
use Isotope\Interfaces\IsotopeProductCollection; | ||
use Isotope\Message; | ||
use Isotope\Model\Config; | ||
use Isotope\Model\Product; | ||
use Isotope\Model\ProductCollection; | ||
use Isotope\Model\ProductCollection\Order; | ||
use Isotope\Model\Product; | ||
|
||
|
||
class SimpleERP extends \System { | ||
class SimpleERP extends System { | ||
|
||
|
||
/** | ||
|
@@ -67,23 +70,29 @@ public function updateProductCount( IsotopeProductCollection $objOrder ) { | |
* | ||
* @return boolean | ||
*/ | ||
public function checkQtyForCollection( Product $objProduct, $intQuantity, IsotopeProductCollection $objCollection ) { | ||
public function checkQtyForCollection( Product $objProduct, $intQuantity=0, IsotopeProductCollection $objCollection ) { | ||
|
||
if( $objProduct->simple_erp_count > 0 ) { | ||
|
||
// check if we want to add more than we have in stock | ||
if( $intQuantity > $objProduct->simple_erp_count ) { | ||
return 0; | ||
} | ||
|
||
// find product in cart to check if the total quantity exceeds our stock | ||
$oInCart = NULL; | ||
$oInCart = $objCollection->getItemForProduct($objProduct); | ||
|
||
if( $oInCart && $oInCart->quantity >= $objProduct->simple_erp_count ) { | ||
return 0; | ||
} | ||
if( $oInCart && ($oInCart->quantity+$intQuantity) >= $objProduct->simple_erp_count ) { | ||
|
||
$qtyAddToCart = $objProduct->simple_erp_count-$oInCart->quantity; | ||
$qtyAddToCart = $qtyAddToCart<0?0:$qtyAddToCart; | ||
|
||
if( !$qtyAddToCart ) { | ||
Message::addError(sprintf( | ||
$GLOBALS['TL_LANG']['ERR']['simpleErpQuantityNotAvailable'] | ||
, $objProduct->getName() | ||
, $objProduct->simple_erp_count | ||
)); | ||
} | ||
|
||
return $qtyAddToCart; | ||
} | ||
} | ||
|
||
return $intQuantity; | ||
|
@@ -101,9 +110,20 @@ public function checkQtyForCollection( Product $objProduct, $intQuantity, Isotop | |
*/ | ||
public function updateQtyInCollection($objItem, $arrSet, $objCart) { | ||
|
||
if( $objItem->getProduct()->simple_erp_count > 0 ) { | ||
if( array_key_exists('quantity', $arrSet) && $arrSet['quantity'] && $arrSet['quantity'] > $objItem->getProduct()->simple_erp_count ) { | ||
$arrSet['quantity'] = $objItem->getProduct()->simple_erp_count; | ||
$objProduct = null; | ||
$objProduct = $objItem->getProduct(); | ||
|
||
if( $objProduct->simple_erp_count > 0 ) { | ||
|
||
if( array_key_exists('quantity', $arrSet) && $arrSet['quantity'] && $arrSet['quantity'] > $objProduct->simple_erp_count ) { | ||
|
||
$arrSet['quantity'] = $objProduct->simple_erp_count; | ||
|
||
Message::addError(sprintf( | ||
$GLOBALS['TL_LANG']['ERR']['simpleErpQuantityNotAvailable'] | ||
, $objProduct->getName() | ||
, $objProduct->simple_erp_count | ||
)); | ||
} | ||
} | ||
|
||
|
@@ -120,11 +140,22 @@ public function getSystemMessages() { | |
|
||
$this->import('Database'); | ||
|
||
$objUnavailProducts = NULL; | ||
$objUnavailProducts = $this->Database->prepare("SELECT COUNT(id) as num_unavail FROM ".Product::getTable()." WHERE simple_erp_disable_on_zero = '1' AND simple_erp_count = '0'")->execute(); | ||
$aMessages = []; | ||
|
||
$oProducts = null; | ||
$oProducts = Product::findBy(['published=?','simple_erp_count=?'],[1,'0']); | ||
|
||
if( $objUnavailProducts->num_unavail ) { | ||
return '<p class="tl_error">' . sprintf($GLOBALS['TL_LANG']['MSC']['simple_erp_non_avail'], $objUnavailProducts->num_unavail) . '</p>'; | ||
if( $oProducts ) { | ||
|
||
while( $oProducts->next() ) { | ||
|
||
$aMessages[] = '<p class="tl_error">' . sprintf( | ||
$GLOBALS['TL_LANG']['MSC']['simpleErpProductOutOfStock'] | ||
, $oProducts->name | ||
) . '</p>'; | ||
} | ||
} | ||
|
||
return implode('',$aMessages); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,12 +3,13 @@ | |
/** | ||
* Contao Open Source CMS | ||
* | ||
* Copyright (c) 2005-2017 Leo Feyer | ||
* Copyright (c) 2005-2021 Leo Feyer | ||
* | ||
* @package Isotope Simple ERP | ||
* @author Benny Born <[email protected]> | ||
* @author Michael Bösherz <[email protected]> | ||
* @license LGPL | ||
* @copyright 2017 numero2 - Agentur für Internetdienstleistungen | ||
* @copyright 2021 numero2 - Agentur für digitales Marketing | ||
*/ | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -3,19 +3,20 @@ | |
/** | ||
* Contao Open Source CMS | ||
* | ||
* Copyright (c) 2005-2017 Leo Feyer | ||
* Copyright (c) 2005-2021 Leo Feyer | ||
* | ||
* @package Isotope Simple ERP | ||
* @author Benny Born <[email protected]> | ||
* @author Michael Bösherz <[email protected]> | ||
* @license LGPL | ||
* @copyright 2017 numero2 - Agentur für Internetdienstleistungen | ||
* @copyright 2021 numero2 - Agentur für digitales Marketing | ||
*/ | ||
|
||
|
||
/** | ||
* Hooks | ||
* HOOKS | ||
*/ | ||
$GLOBALS['ISO_HOOKS']['postCheckout'][] = array('numero2\IsotopeSimpleERP\SimpleERP', 'updateProductCount'); | ||
$GLOBALS['ISO_HOOKS']['addProductToCollection'][] = array('numero2\IsotopeSimpleERP\SimpleERP', 'checkQtyForCollection'); | ||
$GLOBALS['ISO_HOOKS']['updateItemInCollection'][] = array('numero2\IsotopeSimpleERP\SimpleERP','updateQtyInCollection'); | ||
$GLOBALS['TL_HOOKS']['getSystemMessages'][] = array('numero2\IsotopeSimpleERP\SimpleERP', 'getSystemMessages'); | ||
$GLOBALS['ISO_HOOKS']['postCheckout'][] = ['numero2\IsotopeSimpleERP\SimpleERP', 'updateProductCount']; | ||
$GLOBALS['ISO_HOOKS']['addProductToCollection'][] = ['numero2\IsotopeSimpleERP\SimpleERP', 'checkQtyForCollection']; | ||
$GLOBALS['ISO_HOOKS']['updateItemInCollection'][] = ['numero2\IsotopeSimpleERP\SimpleERP','updateQtyInCollection']; | ||
$GLOBALS['TL_HOOKS']['getSystemMessages'][] = ['numero2\IsotopeSimpleERP\SimpleERP', 'getSystemMessages']; |
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 |
---|---|---|
|
@@ -3,12 +3,13 @@ | |
/** | ||
* Contao Open Source CMS | ||
* | ||
* Copyright (c) 2005-2017 Leo Feyer | ||
* Copyright (c) 2005-2021 Leo Feyer | ||
* | ||
* @package Isotope Simple ERP | ||
* @author Benny Born <[email protected]> | ||
* @author Michael Bösherz <[email protected]> | ||
* @license LGPL | ||
* @copyright 2017 numero2 - Agentur für Internetdienstleistungen | ||
* @copyright 2021 numero2 - Agentur für digitales Marketing | ||
*/ | ||
|
||
|
||
|
@@ -18,19 +19,20 @@ | |
$GLOBALS['TL_DCA']['tl_iso_product']['fields']['simple_erp_count'] = array( | ||
'label' => &$GLOBALS['TL_LANG']['tl_iso_product']['simple_erp_count'], | ||
'exclude' => true, | ||
'search' => true, | ||
'filter' => true, | ||
'sorting' => true, | ||
'inputType' => 'text', | ||
'eval' => array( 'mandatory'=>false, 'tl_class'=>'w50' ), | ||
'attributes' => array( 'legend'=>'general_legend', 'multilingual'=>false, 'fe_sorting'=>true ), | ||
'eval' => [ 'mandatory'=>false, 'tl_class'=>'w50' ], | ||
'attributes' => [ 'legend'=>'general_legend', 'multilingual'=>false, 'fe_sorting'=>true ], | ||
'sql' => "varchar(255) NOT NULL default ''", | ||
); | ||
|
||
$GLOBALS['TL_DCA']['tl_iso_product']['fields']['simple_erp_disable_on_zero'] = array( | ||
'label' => &$GLOBALS['TL_LANG']['tl_iso_product']['simple_erp_disable_on_zero'], | ||
'exclude' => true, | ||
'filter' => true, | ||
'inputType' => 'checkbox', | ||
'eval' => array( 'tl_class'=>'w50' ), | ||
'attributes' => array( 'legend'=>'general_legend' ), | ||
'eval' => [ 'tl_class'=>'w50' ], | ||
'attributes' => [ 'legend'=>'general_legend' ], | ||
'sql' => "char(1) NOT NULL default ''", | ||
); |
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