Exemplo n.º 1
0
 /**
  * This method creates the datas to make a read only cart, for the pages like
  * the payment mode chooser.
  * @return str The php array
  */
 protected function cart_getReadonlyCommand()
 {
     if (!is_array($_SESSION[__CLASS__]['cart']) || count($_SESSION[__CLASS__]['cart']) == 0) {
         $_SESSION[__CLASS__]['cart'] = array();
         $normalProducts = false;
     } else {
         $normalProducts = true;
     }
     if (!is_array($_SESSION[__CLASS__]['cart_external']) || count($_SESSION[__CLASS__]['cart_external']) == 0) {
         $_SESSION[__CLASS__]['cart_external'] = array();
         $externalProducts = false;
     } else {
         $externalProducts = true;
     }
     if ($normalProducts || $externalProducts) {
         $taxeIncluded = $this->taxes == self::TAXES_INCLUDED;
         $totalPrice = new sh_price($taxeIncluded, $this->taxRate / 100, 0);
         $total = 0;
         $taxes = 0;
         foreach ($_SESSION[__CLASS__]['cart_external'] as $id => $product) {
             $className = $product['class'];
             $class = $this->linker->{$className};
             $shortId = $product['id'];
             $price = $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_PRICE);
             $values['contents'][] = array('image' => $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_IMAGE), 'name' => $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_NAME), 'reference' => $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_REFERENCE), 'shortDescription' => $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_SHORTDESCRIPTION), 'stock' => $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_STOCK), 'quantity' => $product['qty'], 'id' => $id, 'price' => $this->monney_format($price, true, false), 'totalPrice' => $this->monney_format($price * $product['qty'], true, false), 'link' => $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_LINK));
             $tax = $class->cart_getProductData($shortId, self::EXTERNAL_PRODUCT_TAXRATE);
             $totalPrice->add(new sh_price($taxeIncluded, $tax / 100, $price * $product['qty']));
             $taxes += $price * $product['qty'] * $tax / 100;
             $total += $price * $product['qty'];
         }
         foreach ($_SESSION[__CLASS__]['cart'] as $askedId => $quantity) {
             list($id, $variant) = explode('|', $askedId);
             // We verify if we the product [still] exists
             if ($this->productExists($id)) {
                 $addToDescription = '';
                 list($product) = $this->db_execute('product_get', array('id' => $id));
                 // We update the product datas with the variant's if needed
                 if ($product['hasVariants']) {
                     list($variant) = $this->db_execute('product_get_variant', array('product_id' => $id, 'variant_id' => $variant));
                     if ($product['variants_change_stock']) {
                         // We don't use the global stock, but the variant's one
                         $product['stock'] = $variant['stock'];
                     }
                     if ($product['variants_change_price']) {
                         // We don't use the global price, but the variant's one
                         $product['price'] = $variant['price'];
                     }
                     if ($product['variants_change_ref']) {
                         // We don't use the global ref, but the variant's one
                         $product['reference'] = $variant['ref'];
                     }
                     $cps = $this->variantCP_explode($variant['customProperties']);
                     foreach ($cps as $cp) {
                         $addToDescription .= '<br />' . $cp['name'] . ' : ' . $cp['value'];
                     }
                 }
                 if ($quantity > 0 && $product['stock'] > 0) {
                     // We verify if we can sell the quantity asked
                     if ($quantity > $product['stock']) {
                         // The user asks for more than what we have in stock, so we
                         // can only sell all the stock
                         $quantity = $product['stock'];
                         $_SESSION[__CLASS__]['cart'][$askedId] = $quantity;
                         $_SESSION[__CLASS__]['stocknotsufficient'][] = $product['name'];
                     }
                     $values['contents'][] = array('id' => $askedId, 'name' => $this->getI18n($product['name']), 'reference' => $product['reference'] . $addToDescription, 'shortDescription' => $this->getI18n($product['shortDescription']) . $addToDescription, 'quantity' => $quantity, 'priceOnly' => $product['price'], 'price' => $this->monney_format($product['price'], true, false), 'totalPrice' => $this->monney_format($product['price'] * $quantity, true, false));
                 } elseif ($product['stock'] == 0) {
                     // There is no stock anymore
                     $_SESSION[__CLASS__]['noMoreStock'][] = $product['name'];
                 } else {
                     // We wanted a quantity of 0, so we delete it
                     unset($_SESSION[__CLASS__]['cart'][$id]);
                 }
                 $taxRate = $product['taxRate'];
                 if (!is_numeric($taxRate)) {
                     $taxRate = $this->taxRate;
                 }
                 $totalPrice->add(new sh_price($taxeIncluded, $taxRate / 100, $product['price'] * $quantity));
                 $total += $product['price'] * $quantity;
                 $taxes += $product['price'] * $quantity * $taxRate / 100;
             }
         }
         if ($this->getParam('shipping>activated', true)) {
             $price = $_SESSION[__CLASS__]['shipping']['price'];
             $this->ship_getPrice($total, $price, $explanation, $taxRate);
             if ($_SESSION[__CLASS__]['shipping']['type'] == 'comeTakeIt') {
                 $values['contents'][] = array('id' => 0, 'name' => $this->getI18n('command_comeTakeItTitle'), 'reference' => $_SESSION[__CLASS__]['shipping']['address'] . $explanation, 'quantity' => 1, 'price' => $this->monney_format($price, true, false), 'totalPrice' => $this->monney_format($price, true, false));
                 $values['shipping']['comeTakeIt'] = true;
             } else {
                 $values['contents'][] = array('id' => 0, 'name' => $this->getI18n('command_shippingTitle'), 'reference' => $_SESSION[__CLASS__]['shipping']['shipper'] . $explanation, 'quantity' => 1, 'price' => $this->monney_format($price, true, false), 'totalPrice' => $this->monney_format($price, true, false));
                 $values['shipping']['shipper'] = $_SESSION[__CLASS__]['shipping']['shipper'];
                 $values['shipping']['toCustomer'] = true;
             }
             $totalPrice->add(new sh_price($taxeIncluded, $taxRate / 100, $price));
             $total += $price;
             $taxes += $price * $taxRate / 100;
         }
         if (is_array($_SESSION[__CLASS__]['noMoreStock'])) {
             foreach ($_SESSION[__CLASS__]['noMoreStock'] as $noMore) {
                 $values['noMoreStock'][]['name'] = $this->getI18n($noMore);
             }
         }
         unset($_SESSION[__CLASS__]['noMoreStock']);
         if (is_array($_SESSION[__CLASS__]['stocknotsufficient'])) {
             foreach ($_SESSION[__CLASS__]['stocknotsufficient'] as $stocknotsufficient) {
                 $values['stocknotsufficient'][]['name'] = $this->getI18n($stocknotsufficient);
             }
         }
         unset($_SESSION[__CLASS__]['stocknotsufficient']);
         $values['message']['content'] = $_SESSION[__CLASS__]['cart_message'];
         $values['general']['action'] = $this->linker->path->getLink('shop/cart_doAction/');
         $ht = $totalPrice->get(sh_price::PRICE_UNTAXED);
         $ttc = $totalPrice->get(sh_price::PRICE_TAXED);
         $_SESSION[__CLASS__]['cart_total'] = $values['total']['ttc'];
         if ($totalPrice->get(sh_price::TAX_TYPE) == sh_price::TAX_MODE_EXCLUDE) {
             $values['total']['ht'] = $this->monney_format($ht, true, false);
             $values['total']['ttc'] = $this->monney_format($ttc, true, false);
             $values['total']['paid'] = $ttc;
             // TTC with no format
         } else {
             $values['total']['ht'] = $this->monney_format($ht, true, false, self::ROUND_TO_UPPER);
             $values['total']['ttc'] = $this->monney_format($ttc, true, false);
             $values['total']['paid'] = $ttc;
             // TTC with no format
         }
     }
     $_SESSION[__CLASS__]['command']['elements'] = $values['contents'];
     $_SESSION[__CLASS__]['command']['total'] = $values['total'];
     $this->linker->html->addSpecialContents('shop_cart_content', $this->get_cart_plugin());
     $values['billing']['name'] = $this->linker->user->get('lastName') . ' ' . $this->linker->user->get('name');
     return $values;
 }
Exemplo n.º 2
0
 public function add(sh_price $price)
 {
     $newUntaxedPrice = $this->untaxedPrice + $price->get(self::PRICE_UNTAXED);
     $newTaxedPrice = $this->taxedPrice + $price->get(self::PRICE_TAXED);
     $this->setAmounts($newUntaxedPrice, $newTaxedPrice);
     if (!isset($this->taxDetails[$price->get(self::TAX_RATE)])) {
         $this->taxDetails[$price->get(self::TAX_RATE)] = 0;
     }
     $this->taxDetails[$price->get(self::TAX_RATE)] += $price->get(self::PRICE_TAXED) - $price->get(self::PRICE_UNTAXED);
     return $this;
 }