/**
  * Add one of an item to a cart (Product Page)
  *
  * @see the addtocart function within AddProductForm class
  * @param SS_HTTPRequest $request
  * @param AjaxHTTPResponse $response
  * @param Buyable $buyable [optional]
  * @param int $quantity [optional]
  * @param AddProductForm $form [optional]
  */
 public function updateAddProductFormResponse(&$request, &$response, $buyable, $quantity, $form)
 {
     if ($request->isAjax()) {
         if (!$response) {
             $response = $this->owner->getController()->getResponse();
         }
         $response->removeHeader('Content-Type');
         $response->addHeader('Content-Type', 'application/json; charset=utf-8');
         $shoppingcart = ShoppingCart::curr();
         $shoppingcart->calculate();
         // recalculate the shopping cart
         $data = array('id' => (string) $buyable->ID, 'internalItemID' => $buyable->InternalItemID, 'title' => $buyable->Title, 'url' => $buyable->URLSegment, 'categories' => $buyable->getCategories()->column('Title'), 'addLink' => $buyable->addLink(), 'removeLink' => $buyable->removeLink(), 'removeallLink' => $buyable->removeallLink(), 'setquantityLink' => $buyable->Item()->setquantityLink(), 'message' => array('content' => $form->Message(), 'type' => $form->MessageType()));
         $form->clearMessage();
         // include totals if required
         if ($shoppingcart) {
             $data['subTotal'] = $shoppingcart->SubTotal();
             $data['grandTotal'] = $shoppingcart->GrandTotal();
         }
         $this->owner->extend('updateAddProductFormResponseShopJsonResponse', $data, $request, $response, $buyable, $quantity, $form);
         $response->setBody(json_encode($data));
     }
 }