Skip to content

Commit

Permalink
Require payment if order contains subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jul 27, 2018
1 parent b465df6 commit 31ff63e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion client/jsonapi/src/Client/JsonApi/Order/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ protected function getPaymentForm( \Aimeos\MShop\Order\Item\Base\Iface $basket,
{
$view = $this->getView();
$context = $this->getContext();
$total = $basket->getPrice()->getValue() + $basket->getPrice()->getCosts();
$services = $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT );

if( $services === [] || $basket->getPrice()->getValue() + $basket->getPrice()->getCosts() <= '0.00' )
if( $services === [] || $total <= '0.00' && $this->isSubscription( $basket->getProducts() ) === false )
{
$orderCntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'order' );
$orderCntl->saveItem( $orderItem->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED ) );
Expand Down Expand Up @@ -291,6 +292,25 @@ protected function getUrlUpdate( \Aimeos\MW\View\Iface $view, array $params, arr
}


/**
* Tests if one of the products is a subscription
*
* @param \Aimeos\MShop\Order\Item\Base\Product\Iface[] $products Ordered products
* @return boolean True if at least one product is a subscription, false if not
*/
protected function isSubscription( array $products )
{
foreach( $products as $orderProduct )
{
if( $orderProduct->getAttributeItem( 'interval', 'config' ) ) {
return true;
}
}

return false;
}


/**
* Returns the response object with the rendered header and body
*
Expand Down

0 comments on commit 31ff63e

Please sign in to comment.