This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

I've added the below code to controller.php of the paypal_payment_standard package.

I've added the below code inside public function form() {

$fields = array_merge($fields, $this->getProductFields($o));
$fields = array_merge($fields, $this->getOrderFields($o));
$fields['upload'] = 1;

and change the below code: previously it looks like this

$fields['cmd'] = '_xclick';

Now it looks like this:

$fields['cmd'] = '_cart';

Now at the outside of the public function form() {//code} I put some code mentioning below:

private function getOrderFields($o) {
      $fields = array();
 
      /* Get the tax rates so we can pick sales tax out of the line items */
      Loader::model('sales/tax/rate', 'core_commerce');
      $tr = CoreCommerceSalesTaxRate::getList();
      $taxrates = array();
      foreach ($tr as $taxrate) {
         $taxrates[$taxrate->getSalesTaxRateName()] = $taxrate;
      }
 
        /* Get the list of discounts so we can pick discounts out of the line items */
        $d = CoreCommerceDiscount::getList();
        $discounts = array();
        foreach ($d as $discount) {
            $discounts[$discount->getDiscountName()] = $discount;
        }
 
      $items = $o->getOrderLineItems();
 
      /* Get the shipping method name so we can pick it out of the line items */
      $shipping_amount = 0.00;
      $shipMethod = $o->getOrderShippingMethod();
      if ($shipMethod) {
         $shipMethodName = $shipMethod->getName();
 
         /* Get the shipping cost */
         foreach($items as $it) {
            $itName = $it->getLineItemName();
            if ($itName == $shipMethodName) {
               $shipping_amount += $it->getLineItemTotal();
            }
         }
      }
      /* PayPal Cart doesn't support a shipping value for the whole cart, so there are three methods of
         * dealing with this:
       *  1) Use the cart handling fee
       *  2) Add the shipping fee to the first item - this seems to be the best method as it's simple and
       *     PayPal doesn't appear to break down the shipping (amongst items) anywhere in it's reporting
       *  3) Apportion shipping fee amongst items - this is more complex than #2 but would probably be
       *     more desirable if PayPal showed how shipping was apportioned.
       */
      //$fields['handling_cart'] = $shipping_amount; // Method 1
      $fields['shipping_1'] = $shipping_amount; // Method 2
 
      /* Get the total tax */
      $tax_amount = 0;
      foreach($items as $it) {
         $itName = $it->getLineItemName();
         if (isset($taxrates[$itName])) {
            $tax_amount += $it->getLineItemTotal();
         }
      }
      if ($tax_amount) {
         $fields['tax_cart'] = $tax_amount;
      }
 
      /* Get the discount info */
      $discount_amount = 0.00;
      $discount_code = '';
      foreach($items as $it) {
         $itName = $it->getLineItemName();
         if (isset($discounts[$itName])) {
            $discount_amount += $it->getLineItemTotal();
            if (!empty($discount_code)) {
               $discount_code .= '/';
            }
            $discount_code .= $discounts[$itName]->getDiscountCode();
         }
      }
      if ($discount_amount) {
         $fields['discount_amount_cart'] = $discount_amount;
      }
 
      return $fields;
   }
 
   private function getProductFields($o) {
      Loader::model('attribute/categories/core_commerce_product', 'core_commerce');
 
      //$pkg = Package::getByHandle('paypal_website_payments_standard');
      $pkg = Package::getByHandle('core_commerce');
      $n = 1;
      foreach($o->getProducts() as $pr) {
         //$numberField = $pkg->config('PAYMENT_METHOD_PAYPAL_CART_PRODUCT_NUMBER');
 
         $number = $pr->getProductID();
         $fields['item_number_'.$n] = $number;
         $fields['item_name_'.$n] = $pr->getProductName();
         $fields['amount_'.$n] = $pr->getProductPriceToPay() + $pr->getProductPriceAttributeAdjustment($pr->orderProductID);
         $fields['quantity_'.$n] = $pr->getQuantity();
         $n++;
      }
 
      return $fields;
   }
Loading Conversation