protected function generateProductsData() { $delimiter = ';'; $titles = array(); $id_lang = $this->use_lang; $new_path = new Sampledatainstall(); $f = fopen($new_path->sendPath() . 'output/products.vsc', 'w'); foreach ($this->product_fields as $field => $array) { $titles[] = $array['label']; } fputcsv($f, $titles, $delimiter, '"'); $products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true); foreach ($products as $product) { $line = array(); $p = new Product($product['id_product'], true, $id_lang, 1); foreach ($this->product_fields as $field => $array) { $line[$field] = property_exists('Product', $field) && !is_array($p->{$field}) && !Tools::isEmpty($p->{$field}) ? $p->{$field} : ''; } $cats = $p->getProductCategoriesFull($p->id, 1); $cat_array = array(); foreach ($cats as $cat) { $cat_array[] = $cat['id_category']; } $line['categories'] = implode(',', $cat_array); $line['price_tex'] = $p->getPrice(false); $line['price_tin'] = $p->getPrice(true); $line['upc'] = $p->upc ? $p->upc : ''; $line['features'] = ''; $features = $p->getFrontFeatures($id_lang); $position = 1; $devider = ''; foreach ($features as $feature) { $sql = 'SELECT `id_feature` FROM ' . _DB_PREFIX_ . 'feature_lang WHERE `name` = "' . pSql($feature['name']) . '"'; $sql1 = 'SELECT `id_feature_value` FROM ' . _DB_PREFIX_ . 'feature_value_lang WHERE `value` = "' . pSql($feature['value']) . '"'; $id_feature = Db::getInstance()->getValue($sql); $id_feature_value = Db::getInstance()->getValue($sql1); $line['features'] .= $devider . $id_feature . ':' . $id_feature_value . ':' . $position; $devider = ','; $position++; } $specificPrice = SpecificPrice::getSpecificPrice($p->id, 1, 0, 0, 0, 0); $line['reduction_price'] = ''; $line['reduction_percent'] = ''; $line['reduction_from'] = ''; $line['reduction_to'] = ''; if ($specificPrice) { if ($specificPrice['reduction_type'] == 'amount') { $line['reduction_price'] = $specificPrice['reduction']; } elseif ($specificPrice['reduction_type'] == 'percent') { $line['reduction_percent'] = $specificPrice['reduction']; } if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') { $line['reduction_from'] = $specificPrice['from']; $line['reduction_to'] = $specificPrice['to']; } } $tags = $p->getTags($id_lang); $line['tags'] = $tags; $link = new Link(); $imagelinks = array(); $images = $p->getImages($id_lang); foreach ($images as $image) { $imagelink = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']); $this->copyConverFileName($imagelink); $imagelinks[] = $imagelink; } $line['image'] = implode(',', $imagelinks); $line['delete_existing_images'] = 0; $line['shop'] = 1; $warehouses = Warehouse::getWarehousesByProductId($p->id); $line['warehouse'] = ''; if (!empty($warehouses)) { $line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses)); } $values = array(); $accesories = $p->getAccessories($id_lang); if (isset($accesories) && $accesories && count($accesories)) { foreach ($accesories as $accesorie) { $values[] = $accesorie['id_product']; } } $line['accessories'] = $values ? implode(',', $values) : ''; $values = array(); $carriers = $p->getCarriers(); if (isset($carriers) && $carriers && count($carriers)) { foreach ($carriers as $carrier) { $values[] = $carrier['id_carrier']; } } $line['carriers'] = $values ? implode(',', $values) : ''; $values = array(); $customization_fields_ids = $p->getCustomizationFieldIds(); if (class_exists('CustomizationField') && isset($customization_fields_ids) && $customization_fields_ids && count($customization_fields_ids)) { foreach ($customization_fields_ids as $customization_field_id) { $cf = new CustomizationField($customization_field_id['id_customization_field'], $this->use_lang); $values[] = $cf->id . ':' . $cf->type . ':' . $cf->required . ':' . $cf->name; } } $line['customization_fields_ids'] = $values ? implode(',', $values) : ''; $values = array(); $attachments = $p->getAttachments($this->use_lang); if (isset($attachments) && $attachments && count($attachments)) { foreach ($attachments as $attachment) { $values[] = $attachment['id_attachment']; } } $line['attachments'] = $values ? implode(',', $values) : ''; if (!property_exists('Product', 'base_price')) { // for versions < 1.6.0.13 $line['base_price'] = !is_array($p->base_price) && !Tools::isEmpty($p->base_price) ? $p->base_price : ''; } if (!$line[$field]) { $line[$field] = ''; } fputcsv($f, $line, $delimiter, '"'); } fclose($f); }
/** * Assign price and tax to the template. */ protected function assignPriceAndTax() { $id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0; $id_group = (int) Group::getCurrent()->id; $id_country = $id_customer ? (int) Customer::getCurrentCountry($id_customer) : (int) Tools::getCountry(); // Tax $tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $this->context->smarty->assign('tax_rate', $tax); $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $product_price_with_tax = Tools::ps_round($product_price_with_tax, 2); } $id_currency = (int) $this->context->cookie->id_currency; $id_product = (int) $this->product->id; $id_product_attribute = Tools::getValue('id_product_attribute', null); $id_shop = $this->context->shop->id; $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_product_attribute, false, (int) $this->context->customer->id); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount['id_product_attribute']) { $combination = new Combination((int) $quantity_discount['id_product_attribute']); $attributes = $combination->getAttributesName((int) $this->context->language->id); foreach ($attributes as $attribute) { $quantity_discount['attributes'] = $attribute['name'] . ' - '; } $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - '); } if ((int) $quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') { $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency); } } $product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false); $this->quantity_discounts = $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $this->product->ecotax); $this->context->smarty->assign(array('no_tax' => Tax::excludeTaxeOption() || !$tax, 'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'), 'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group))); }
/** * public __construct * * @description initialise our checkout */ public function __construct(&$product) { // If we are being created then there is only 1 of us parent::__construct($product->getCode(), $product->getName(), $product->getPrice()); $this->quantity = 1; $this->totalPrice = parent::getPrice(); }
public function addToTotal(Product $product) { // if(!is_null($product)) // { // $this->total += $product->getPrice(); // } $this->total += $product->getPrice(); }
function compute(Product $product) { $discountProvider = DiscountProvider::getInstance(); $discountAsPercent = $discountProvider->getDiscountFor($product->getId()); $price = $product->getPrice(); $discountAsValue = $price * $discountAsPercent / 100; return $price - $discountAsValue; }
public function getPrice() { $price = parent::getPrice(); if ($this->expire <= 10) { $price /= 2; } return $price; }
public static function create(Product $oProduct) { $oCartProduct = new CartProduct(); $oCartProduct->setImage($oProduct->getImage()); $oCartProduct->setId($oProduct->getId()); $oCartProduct->setDescription($oProduct->getDescription()); $oCartProduct->setName($oProduct->getName()); $oCartProduct->setPrice($oProduct->getPrice()); return $oCartProduct; }
public function add(Product $toBeAdded) { $stmt = $this->database->prepare("INSERT INTO `store`.`Products` (\n\t\t\t`pk` , `title` , `description` , `price` )\n\t\t\t\tVALUES (?, ?, ?, ?)"); if ($stmt === FALSE) { throw new \Exception($this->database->error); } $pk = $toBeAdded->getUniqueString(); $title = $toBeAdded->getTitle(); $description = $toBeAdded->getDescription(); $price = $toBeAdded->getPrice(); $stmt->bind_param('sssd', $pk, $title, $description, $price); $stmt->execute(); }
/** * Hozzá adja, elmenti az adatbázisban az új termék adatait. * * @param Product $product * @return Exception|string */ public function productAddStore($product) { //die("temrék neve: " . $product->getName()); if ($this->checkProductExist($product->getName()) === FALSE) { try { self::$conn->preparedInsert("termekek", array("nev", "kat_azon", "kisz_azon", "suly", "egysegar", "min_keszlet", "min_rend", "kim_azon", "akcio", "reszletek", "kep"), array($product->getName(), $product->getCategory(), $product->getPackage(), $product->getWeight(), $product->getPrice(), $product->getMinStock(), $product->getMinOrder(), $product->getHighlight(), $product->getDiscount(), $product->getDescription(), $product->getImg())); //die("Sql után!"); } catch (Exception $e) { return new Exception("Nem sikerült elmenteni a terméket!"); } //$stmt = $conn->preparedQuery("SELECT t_azon FROM termekek WHERE nev=?",array("$name")); return "Sikeres termék felvitel!"; } else { return "Létezik már ilyen termék!"; } }
private function getVariants() { $groups = array(); if ($this->combinations && count($this->combinations)) { foreach ($this->combinations as $combination) { if (!array_key_exists($combination['id_product_attribute'], $groups)) { $groups[$combination['id_product_attribute']] = array('code' => PowatagProductAttributeHelper::getVariantCode($combination), 'numberInStock' => PowaTagProductQuantityHelper::getCombinationQuantity($combination), 'productImages' => $this->getCombinationImages($combination['id_product_attribute']), 'originalPrice' => array('amount' => $this->formatNumber($this->product->getPrice($this->display_taxes, null), 2), 'currency' => $this->context->currency->iso_code), 'finalPrice' => array('amount' => $this->formatNumber($this->product->getPrice($this->display_taxes, $combination['id_product_attribute']), 2), 'currency' => $this->context->currency->iso_code)); } $groups[$combination['id_product_attribute']]['options'][$combination['group_name']] = $combination['attribute_name']; } sort($groups); } else { $variant = array('code' => PowaTagProductHelper::getProductSKU($this->product), 'numberInStock' => PowaTagProductQuantityHelper::getProductQuantity($this->product), 'finalPrice' => array('amount' => $this->formatNumber($this->product->getPrice($this->display_taxes, null), 2), 'currency' => $this->context->currency->iso_code)); $groups = array($variant); } return $groups; }
public function testChildProduct() { $this->product->setPrice($this->usd, 20); $this->product->shippingWeight->set(200); $this->product->save(); $child = $this->product->createChildProduct(); $root = Category::getRootNode(); $root->reload(); $productCount = $root->totalProductCount->get(); // in array representation, parent product data is used where own data is not set $array = $child->toArray(); $this->assertEquals($array['name_en'], $this->product->getValueByLang('name', 'en')); // auto-generated SKU is based on parent SKU $child->save(); $this->assertEquals($child->sku->get(), $this->product->sku->get() . '-1'); // category counters should not change $root->reload(); $this->assertEquals($root->totalProductCount->get(), $productCount); // parent product price used if not defined $this->assertEquals($child->getPrice($this->usd), $this->product->getPrice($this->usd)); // parent shipping weight used if not defined $this->assertEquals($child->getShippingWeight(), $this->product->getShippingWeight()); // add/substract parent prices/shipping weights $child->setChildSetting('test', 'value'); $this->assertEquals($child->getChildSetting('test'), 'value'); // prices $child->setChildSetting('price', Product::CHILD_ADD); $child->setPrice($this->usd, 5); $this->assertEquals(20, $this->product->getPrice($this->usd)); $this->assertEquals($child->getPrice($this->usd), $this->product->getPrice($this->usd) + 5); $child->setChildSetting('price', Product::CHILD_SUBSTRACT); $this->assertEquals($child->getPrice($this->usd), $this->product->getPrice($this->usd) - 5); $child->setChildSetting('price', Product::CHILD_OVERRIDE); $this->assertEquals($child->getPrice($this->usd), 5); // shipping weight $child->setChildSetting('weight', Product::CHILD_ADD); $child->shippingWeight->set(5); $this->assertEquals(200, $this->product->getShippingWeight()); $this->assertEquals($child->getShippingWeight(), $this->product->getShippingWeight() + 5); $child->setChildSetting('weight', Product::CHILD_SUBSTRACT); $this->assertEquals($child->getShippingWeight(), $this->product->getShippingWeight() - 5); $child->setChildSetting('weight', Product::CHILD_OVERRIDE); $this->assertEquals($child->getShippingWeight(), 5); }
/** * Assign price and tax to the template */ protected function assignPriceAndTax() { $id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0; $id_group = isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_; $id_country = (int) $id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'); $group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group); if ($group_reduction == 0) { $group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100; } // Tax $tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $this->context->smarty->assign('tax_rate', $tax); $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $product_price_with_tax = Tools::ps_round($product_price_with_tax, 2); } $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax; $ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotax_tax_amount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) { $ecotax_tax_amount = Tools::ps_round($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2); } $id_currency = (int) $this->context->cookie->id_currency; $id_product = (int) $this->product->id; $id_shop = $this->context->shop->id; $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount['id_product_attribute']) { $combination = new Combination((int) $quantity_discount['id_product_attribute']); $attributes = $combination->getAttributesName((int) $this->context->language->id); foreach ($attributes as $attribute) { $quantity_discount['attributes'] = $attribute['name'] . ' - '; } $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - '); } } $product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false); $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $this->context->smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax), 'ecotax_tax_inc' => $ecotax_tax_amount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'productPriceWithoutEcoTax' => (double) $product_price_without_eco_tax, 'group_reduction' => 1 - $group_reduction, 'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address), 'ecotax' => !count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'tax_enabled' => Configuration::get('PS_TAX'))); }
public function create(SubCategory $sub_category, $name, $description, $price, $img, $stock) { $errors = array(); $product = new Product($this->db); try { $product->setSubCategory($sub_category); $product->setName($name); $product->setDescription($description); $product->setPrice($price); $product->setImg($img); $product->setStock($stock); } catch (Exception $e) { $errors[] = $e->getMessage(); } $errors = array_filter($errors, function ($val) { return $val !== true; }); if (count($errors) == 0) { $idSubCategory = intval($product->getIdSubCategory()); $name = $this->db->quote($product->getName()); $description = $this->db->quote($product->getDescription()); $price = $this->db->quote($product->getPrice()); $img = $this->db->quote($product->getImg()); $stock = $this->db->quote($product->getStock()); $query = "INSERT INTO product(id_sub_category, name, description, price, img, stock) VALUES('" . $idSub_category . "', " . $name . ", " . $description . ", " . $price . ", " . $img . ", " . $stock . ")"; $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->findById($id); } else { return "Internal Server error"; } } } else { return $errors; } }
/** * Get the form variables for the purchase button. * * @uses PaymentGw::_Supports() * @uses _encButton() * @uses getActionUrl() * @return string HTML for purchase button */ public function CheckoutButton($cart) { global $_PP_CONF, $_USER, $_TABLES; if (!$this->_Supports('checkout')) { return ''; } $cartItems = $cart->Cart(); $cartID = $cart->CartID(); $custom_arr = array('uid' => $_USER['uid'], 'transtype' => 'cart_upload', 'cart_id' => $cartID); $fields = array('cmd' => '_cart', 'upload' => '1', 'cancel_return' => PAYPAL_URL . '/index.php?view=cart', 'return' => PAYPAL_URL . '/index.php?thanks=paypal', 'rm' => '2', 'paymentaction' => 'sale', 'notify_url' => $this->ipn_url, 'currency_code' => $this->currency_code, 'custom' => str_replace('"', '\'', serialize($custom_arr))); $address = $cart->getAddress('shipto'); if (!empty($address)) { list($fname, $lname) = explode(' ', $address['name']); $fields['first_name'] = htmlspecialchars($fname); $fields['last_name'] = htmlspecialchars($lname); $fields['address1'] = htmlspecialchars($address['address1']); $fields['address2'] = htmlspecialchars($address['address2']); $fields['city'] = htmlspecialchars($address['city']); $fields['state'] = htmlspecialchars($address['state']); $fields['country'] = htmlspecialchars($address['country']); $fields['zip'] = htmlspecialchars($address['zip']); } $i = 1; $total_amount = 0; $shipping = 0; $weight = 0; foreach ($cartItems as $cart_item_id => $item) { //$opt_str = ''; list($db_item_id, $options) = explode('|', $item['item_id']); if (is_numeric($db_item_id)) { $P = new Product($db_item_id); $db_item_id = DB_escapeString($db_item_id); $oc = 0; if (is_array($item['options'])) { $opts = explode(',', $options); foreach ($opts as $optval) { $opt_info = $P->getOption($optval); if ($opt_info) { $opt_str .= ', ' . $opt_info['value']; $fields['on' . $oc . '_' . $i] = $opt_info['name']; $fields['os' . $oc . '_' . $i] = $opt_info['value']; $oc++; } } //$item['descrip'] .= $opt_str; } else { $opts = array(); } $fields['amount_' . $i] = $P->getPrice($opts, $item['quantity']); if ($P->taxable == 0) { $fields['tax_' . $i] = '0.00'; } } else { // Plugin item $fields['amount_' . $i] = $item['price']; } //$fields['item_number_' . $i] = htmlspecialchars($item['item_id']); $fields['item_number_' . $i] = (int) $cart_item_id; $fields['item_name_' . $i] = htmlspecialchars($item['descrip']); $total_amount += $item['price']; if (is_array($item['extras']['custom'])) { foreach ($item['extras']['custom'] as $id => $val) { $fields['on' . $oc . '_' . $i] = $P->getCustom($id); $fields['os' . $oc . '_' . $i] = $val; $oc++; } } $fields['quantity_' . $i] = $item['quantity']; if (isset($item['shipping'])) { $fields['shipping_' . $i] = $item['shipping']; $shipping += $item['shipping']; } if (isset($item['weight']) && $item['weight'] > 0) { $weight += $item['weight']; } if (isset($item['tax'])) { $fields['tax_' . $i] = $item['tax']; } elseif (isset($item['options']['tax'])) { $fields['tax_' . $i] = $item['options']['tax']; } $i++; } if ($shipping > 0) { $total_amount += $shipping; } if ($weight > 0) { $fields['weight_cart'] = $weight; $fields['weight_unit'] = $_PP_CONF['weight_unit'] == 'kgs' ? 'kgs' : 'lbs'; } // Set the business e-mail address based on the total puchase amount // There must be an address configured; if not then this gateway can't // be used for this purchase $this->setReceiver($total_amount); $fields['business'] = $this->receiver_email; if (empty($fields['business'])) { return ''; } $gatewayVars = array(); $enc_btn = ''; if ($this->config['encrypt']) { $enc_btn = self::_encButton($fields); if (!empty($enc_btn)) { $gatewayVars[] = '<input type="hidden" name="cmd" value="_s-xclick" />'; $gatewayVars[] = '<input type="hidden" name="encrypted" ' . 'value="' . $enc_btn . '" />'; } } if (empty($enc_btn)) { // If we didn't get an encrypted button, set the plaintext vars foreach ($fields as $name => $value) { $gatewayVars[] = '<input type="hidden" name="' . $name . '" value="' . $value . '" />'; } } $gateway_vars = implode("\n", $gatewayVars); $T = new Template(PAYPAL_PI_PATH . '/templates/buttons/' . $this->gw_name); $T->set_file(array('btn' => 'btn_checkout.thtml')); $T->set_var('paypal_url', $this->getActionUrl()); $T->set_var('gateway_vars', $gateway_vars); $retval = $T->parse('', 'btn'); return $retval; }
public function displayProducts() { global $currentIndex, $cookie; if (isset($this->_list['obj'])) { $nbProducts = sizeof($this->_list['obj']); echo '<h3>' . $this->_list['message'] . ' ' . $nbProducts . ' ' . $this->l('found') . '</h3>'; if (!$nbProducts) { return; } $this->fieldsDisplay = array('ID' => array('title' => $this->l('ID')), 'manufacturer' => array('title' => $this->l('Manufacturer')), 'reference' => array('title' => $this->l('Reference')), 'name' => array('title' => $this->l('Name')), 'price' => array('title' => $this->l('Price')), 'tax' => array('title' => $this->l('Tax')), 'stock' => array('title' => $this->l('Stock')), 'weight' => array('title' => $this->l('Weight')), 'status' => array('title' => $this->l('Status')), 'action' => array('title' => $this->l('Actions'))); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); echo ' <table class="table" cellpadding="0" cellspacing="0"> <tr>'; foreach ($this->fieldsDisplay as $field) { echo '<th' . (isset($field['width']) ? 'style="width: ' . $field['width'] . '"' : '') . '>' . $field['title'] . '</th>'; } echo ' </tr>'; foreach ($this->_list['obj'] as $k => $prod) { $product = new Product(intval($prod['id_product'])); $product->name = $product->name[intval($cookie->id_lang)]; $tax = new Tax(intval($product->id_tax)); echo ' <tr> <td>' . $product->id . '</td> <td align="center">' . ($product->manufacturer_name != NULL ? stripslashes($product->manufacturer_name) : '--') . '</td> <td>' . $product->reference . '</td> <td><a href="index.php?tab=AdminCatalog&id_product=' . $product->id . '&addproduct&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '">' . stripslashes($product->name) . '</a></td> <td>' . Tools::displayPrice($product->getPrice(), $currency) . '</td> <td>' . stripslashes($tax->name[intval($cookie->id_lang)]) . '</td> <td align="center">' . $product->quantity . '</td> <td align="center">' . $product->weight . ' ' . Configuration::get('PS_WEIGHT_UNIT') . '</td> <td align="center"><a href="index.php?tab=AdminCatalog&id_product=' . $product->id . '&status&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '"><img src="../img/admin/' . ($product->active ? 'enabled.gif' : 'disabled.gif') . '" alt="" /></a></td> <td> <a href="index.php?tab=AdminCatalog&id_product=' . $product->id . '&addproduct&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '"> <img src="../img/admin/edit.gif" alt="' . $this->l('Modify this product') . '" /></a> <a href="index.php?tab=AdminCatalog&id_product=' . $product->id . '&deleteproduct&token=' . Tools::getAdminToken('AdminCatalog' . intval(Tab::getIdFromClassName('AdminCatalog')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . addslashes($this->l('Do you want to delete') . ' ' . $product->name) . ' ?\');"> <img src="../img/admin/delete.gif" alt="' . $this->l('Delete this product') . '" /></a> </td> </tr>'; } echo '</table><br /><br />'; } }
function priceWithTax($id_product) { $product = new Product(NULL, FALSE, $this->lang); $product->id = $id_product; return Tools::convertPrice($product->getPrice(TRUE), $this->currency); }
public function testPriceCannotBecomeNegative() { $instance = new Product(); $instance->setPrice(-1); $this->assertEquals(-1, $instance->getPrice()); }
/** * Convert the entities data into an xml object and return the xml object as a string * * @param array $aEntity Entity data */ public function formatEntityToXML($aEntity) { $sReturn = ''; $dom = new DOMDocument('1.0', 'utf-8'); $bUseRoutes = (bool) Configuration::get('PS_REWRITING_SETTINGS'); $oDispatcher = Dispatcher::getInstance(); // Force the dispatcher to use custom routes because the use of custom routes is disabled in the BO Context foreach ($oDispatcher->default_routes as $route_id => $route_data) { if ($custom_route = Configuration::get('PS_ROUTE_' . $route_id)) { foreach (Language::getLanguages() as $lang) { $oDispatcher->addRoute($route_id, $custom_route, $route_data['controller'], $lang['id_lang'], $route_data['keywords'], isset($route_data['params']) ? $route_data['params'] : array()); } } } $oPrediggoConfig = $this->aPrediggoConfigs[(int) $aEntity['id_shop']]; $link = $oPrediggoConfig->getContext()->link; $oProduct = new Product((int) $aEntity['id_product'], true, null, (int) $aEntity['id_shop'], $oPrediggoConfig->getContext()); if ((int) StockAvailable::getQuantityAvailableByProduct((int) $aEntity['id_product'], 0, (int) $aEntity['id_shop']) < (int) $oPrediggoConfig->export_product_min_quantity) { $this->nbEntitiesTreated--; $this->nbEntities--; return ' '; } $ps_tax = (int) Configuration::get('PS_TAX'); foreach ($this->aLanguages as $aLanguage) { $id_lang = (int) $aLanguage['id_lang']; // Set the root of the XML $root = $dom->createElement($this->sEntity); $dom->appendChild($root); $root->setAttribute('timestamp', (int) strtotime($oProduct->date_add)); $id = $dom->createElement('id', (int) $oProduct->id); $root->appendChild($id); $profile = $dom->createElement('profile', (int) $aEntity['id_shop']); $root->appendChild($profile); $name = $dom->createElement('name'); $name->appendChild($dom->createCDATASection($oProduct->name[$id_lang])); $root->appendChild($name); $oCategory = new Category((int) $oProduct->id_category_default); $aCategories = $oCategory->getParentsCategories($id_lang); if (is_array($aCategories) && count($aCategories) > 0) { foreach ($aCategories as $aCategory) { $oCategoryTmp = new Category((int) $aCategory['id_category'], $id_lang); if (!empty($oCategoryTmp->name)) { $genre = $dom->createElement('genre'); $genre->appendChild($dom->createCDATASection($oCategoryTmp->name)); $root->appendChild($genre); } unset($oCategoryTmp); } } unset($aCategories); unset($oCategory); if (!empty($oProduct->ean13)) { $ean = $dom->createElement('ean'); $ean->appendChild($dom->createCDATASection($oProduct->ean13)); $root->appendChild($ean); } $price = $dom->createElement('price', number_format($oProduct->getPrice($ps_tax), 2, '.', '')); $root->appendChild($price); if (isset($oProduct->tags[$id_lang]) && ($aTags = $oProduct->tags[$id_lang])) { $tag = $dom->createElement('tag'); $tag->appendChild($dom->createCDATASection(join(',', $aTags))); $root->appendChild($tag); } $sDesc = trim(strip_tags($oProduct->description[$id_lang])); if ($oPrediggoConfig->export_product_description && !empty($sDesc)) { $description = $dom->createElement('description'); $description->appendChild($dom->createCDATASection($sDesc)); $root->appendChild($description); } if (!empty($oProduct->id_manufacturer)) { $supplierid = $dom->createElement('supplierid', (int) $oProduct->id_manufacturer); $root->appendChild($supplierid); } $recommendable = $dom->createElement('recommendable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_recommendable)) ? 'false' : 'true'); $root->appendChild($recommendable); $searchable = $dom->createElement('searchable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_searchable)) ? 'false' : 'true'); $root->appendChild($searchable); // Set product URL $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName', 'producturl'); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($link->getProductLink((int) $oProduct->id, $oProduct->link_rewrite[$id_lang], Category::getLinkRewrite((int) $oProduct->id_category_default, $id_lang), NULL, $id_lang, (int) $aEntity['id_shop'], 0, $bUseRoutes))); $attribute->appendChild($attValue); // Set product picture if ($oPrediggoConfig->export_product_image) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName', 'imageurl'); $attribute->appendChild($attName); $aCover = $oProduct->getCover((int) $oProduct->id); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($link->getImageLink($oProduct->link_rewrite[$id_lang], (int) $aCover['id_image'], 'large'))); $attribute->appendChild($attValue); } // Set combinations $aProductCombinations = Product::getAttributesInformationsByProduct((int) $oProduct->id); if (sizeof($aProductCombinations)) { foreach ($aProductCombinations as $aProductCombination) { if (!empty($oPrediggoConfig->attributes_groups_ids) && in_array((int) $aProductCombination['id_attribute_group'], explode(',', $oPrediggoConfig->attributes_groups_ids))) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection($aProductCombination['group'])); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($aProductCombination['attribute'])); $attribute->appendChild($attValue); } } } unset($aProductCombinations); // Set features $aProductFeatures = $oProduct->getFrontFeatures($id_lang); if (sizeof($aProductFeatures)) { foreach ($aProductFeatures as $aProductFeature) { if (!empty($oPrediggoConfig->features_ids) && in_array((int) $aProductFeature['id_feature'], explode(',', $oPrediggoConfig->features_ids))) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection($aProductFeature['name'])); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection($aProductFeature['value'])); $attribute->appendChild($attValue); } } } unset($aProductFeatures); $aAccessories = Product::getAccessoriesLight($id_lang, (int) $oProduct->id); if (sizeof($aAccessories)) { foreach ($aAccessories as $aAccessory) { $attribute = $dom->createElement('attribute'); $root->appendChild($attribute); $attName = $dom->createElement('attName'); $attName->appendChild($dom->createCDATASection('accessory')); $attribute->appendChild($attName); $attValue = $dom->createElement('attValue'); $attValue->appendChild($dom->createCDATASection((int) $aAccessory['id_product'])); $attribute->appendChild($attValue); } } unset($aAccessories); $sReturn .= $dom->saveXML($root); } unset($dom); unset($oProduct); return $sReturn; }
public function generateFlux() { if (Tools::getValue('token') == '' || Tools::getValue('token') != Configuration::get('SHOPPING_FLUX_TOKEN')) { die('Invalid Token'); } $titles = array(0 => 'id_produit', 1 => 'nom_produit', 2 => 'url_produit', 3 => 'url_image', 4 => 'description', 5 => 'description_courte', 6 => 'prix', 7 => 'prix_barre', 8 => 'frais_de_port', 9 => 'delaiLiv', 10 => 'marque', 11 => 'rayon', 12 => 'stock', 13 => 'qte_stock', 14 => 'EAN', 15 => 'poids', 16 => 'ecotaxe', 17 => 'TVA', 18 => 'Reference constructeur', 19 => 'Reference fournisseur'); echo implode("|", $titles) . "\r\n"; //For Shipping $configuration = Configuration::getMultiple(array('PS_TAX_ADDRESS_TYPE', 'PS_CARRIER_DEFAULT', 'PS_COUNTRY_DEFAULT', 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT')); $products = Product::getSimpleProducts($configuration['PS_LANG_DEFAULT']); $defaultCountry = new Country($configuration['PS_COUNTRY_DEFAULT'], Configuration::get('PS_LANG_DEFAULT')); $id_zone = (int) $defaultCountry->id_zone; $carrier = new Carrier((int) $configuration['PS_CARRIER_DEFAULT']); $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id, (int) $this->{$configuration['PS_TAX_ADDRESS_TYPE']}); foreach ($products as $key => $produit) { $product = new Product((int) $produit['id_product'], true, $configuration['PS_LANG_DEFAULT']); //For links $link = new Link(); //For images $cover = $product->getCover($product->id); $ids = $product->id . '-' . $cover['id_image']; //For shipping if ($product->getPrice(true, NULL, 2, NULL, false, true, 1) >= (double) $configuration['PS_SHIPPING_FREE_PRICE'] and (double) $configuration['PS_SHIPPING_FREE_PRICE'] > 0) { $shipping = 0; } elseif (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $product->weight >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] and (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) { $shipping = 0; } else { if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) { $shipping = (double) $configuration['PS_SHIPPING_HANDLING']; } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping += $carrier->getDeliveryPriceByWeight($product->weight, $id_zone); } else { $shipping += $carrier->getDeliveryPriceByPrice($product->getPrice(true, NULL, 2, NULL, false, true, 1), $id_zone); } $shipping *= 1 + $carrierTax / 100; $shipping = (double) Tools::ps_round((double) $shipping, 2); } $data = array(); $data[0] = $product->id; $data[1] = $product->name; $data[2] = $link->getProductLink($product); $data[3] = $link->getImageLink($product->link_rewrite, $ids, 'large'); $data[4] = $product->description; $data[5] = $product->description_short; $data[6] = $product->getPrice(true, NULL, 2, NULL, false, true, 1); $data[7] = $product->getPrice(true, NULL, 2, NULL, false, false, 1); $data[8] = $shipping; $data[9] = $carrier->delay[2]; $data[10] = $product->manufacturer_name; $data[11] = $product->category; $data[12] = $product->quantity > 0 ? 'oui' : 'non'; $data[13] = $product->quantity; $data[14] = $product->ean13; $data[15] = $product->weight; $data[16] = $product->ecotax; $data[17] = $product->tax_rate; $data[18] = $product->reference; $data[19] = $product->supplier_reference; foreach ($data as $key => $value) { $data[$key] = $this->clean($value); } echo implode("|", $data) . "\r\n"; } }
} $doc->product_link = $productObj->getLink(); $idImage = $productObj->getCoverWs(); if ($idImage) { $idImage = $productObj->id . '-' . $idImage; } else { $idImage = Language::getIsoById(1) . '-default'; } $thickbox_image = $link->getImageLink($productObj->link_rewrite, $idImage, 'thickbox'); $large_image = $link->getImageLink($productObj->link_rewrite, $idImage, 'large'); $id_manufacturer = $productObj->id_manufacturer; $manufacturer = ''; if (!empty($id_manufacturer)) { $manufacturer = Manufacturer::getNameById($id_manufacturer); } $productRec = array($id_product, $productObj->reference, $productObj->supplier_reference, $productObj->name, $productObj->getLink(), $productObj->getPriceWithoutReduct(), round($productObj->getPrice()), round($mrp_in_rs), round($offer_price_in_rs), strip_tags($productObj->description), '0', $availability, $manufacturer, $category, $categories, $color, $fabric, (int) $productObj->active === 1 ? 'ACTIVE' : 'INACTIVE', $quantity, $productObj->shipping_sla, $productObj->is_customizable, $large_image, $thickbox_image, date('Y-m-d', strtotime($productObj->date_add))); $images = $productObj->getImages(1); foreach ($images as $image) { $oImage = $link->getImageLink($productObj->link_rewrite, $image['id_image'], 'thickbox'); if ($thickbox_image !== $oImage) { array_push($productRec, $oImage); } } //echo '"'.implode($productRec,'","').'"'; //echo PHP_EOL; fputcsv($outstream, $productRec, ',', '"'); ob_flush(); flush(); } fclose($outstream); } elseif (Tools::getValue('getPartnerProducts')) {
/** * View the cart. * This function shows the shopping cart, either with the quantity fields * and option to update, or with the checkout buttons depending on the * value of $checkout. * * @uses getCheckoutButtons() * @param boolean $checkout True to indicate this is the final checkout * @return string HTML for the "view cart" form */ public function View($checkout = false) { global $_CONF, $_PP_CONF, $_USER, $LANG_PP, $_TABLES, $_SYSTEM; USES_paypal_class_product(); USES_paypal_class_currency(); $currency = new ppCurrency(); $T = new Template(PAYPAL_PI_PATH . '/templates'); $tpltype = $_SYSTEM['framework'] == 'uikit' ? '.uikit' : ''; $T->set_file('cart', $checkout ? "order{$tpltype}.thtml" : "viewcart{$tpltype}.thtml"); if (!isset($this->m_cart) || empty($this->m_cart)) { return $LANG_PP['cart_empty']; } if ($checkout) { foreach ($_PP_CONF['workflows'] as $key => $value) { $T->set_var('have_' . $value, 'true'); foreach ($this->_addr_fields as $fldname) { $T->set_var($value . '_' . $fldname, $this->m_info[$value][$fldname]); } } $T->set_var('not_final', 'true'); } $T->set_block('order', 'ItemRow', 'iRow'); // Get the workflows so we show the relevant info. if (!isset($_PP_CONF['workflows']) || !is_array($_PP_CONF['workflows'])) { USES_paypal_class_workflow(); ppWorkflow::Load(); } $T->set_block('cart', 'ItemRow', 'iRow'); $counter = 0; $subtotal = 0; $shipping = 0; foreach ($this->m_cart as $id => $item) { $counter++; $attr_desc = ''; list($item_id, $attr_keys) = PAYPAL_explode_opts($item['item_id']); if (is_numeric($item_id)) { // a catalog item, get the "right" price $P = new Product($item_id); $item_price = $P->getPrice($attr_keys, $item['quantity']); if (!empty($attr_keys)) { foreach ($attr_keys as $attr_key) { if (!isset($P->options[$attr_key])) { continue; } // invalid? //$attr_price = (float)$P->options[$attr_key]['attr_price']; $attr_name = $P->options[$attr_key]['attr_name']; $attr_value = $P->options[$attr_key]['attr_value']; $attr_desc .= "<br /> -- {$attr_name}: {$attr_value}"; /*if ($attr_price != 0) { $item_price += $attr_price; }*/ } } $text_names = explode('|', $P->custom); if (!empty($text_names) && is_array($item['extras']['custom'])) { foreach ($item['extras']['custom'] as $tid => $val) { $attr_desc .= '<br /> -- ' . htmlspecialchars($text_names[$tid]) . ': ' . htmlspecialchars($val); } } $item['descrip'] .= $attr_desc; // Get shipping amount and weight if ($P->shipping_type == 2 && $P->shipping_amt > 0) { // fixed shipping amount per item. Update actual cart $this->m_cart[$id]['shipping'] = $P->shipping_amt * $item['quantity']; $shipping += $this->m_cart[$id]['shipping']; // for display } elseif ($P->shipping_type == 1 && $P->weight > 0) { // using gateway profile, save the item's weight in the cart $this->m_cart[$id]['weight'] = $P->weight * $item['quantity']; } $this->m_cart[$id]['taxable'] = $P->taxable ? 'Y' : 'N'; $this->m_cart[$id]['type'] = $P->prod_type; } else { // A plugin item, it's not something we can look up $item_price = (double) $item['price']; if (isset($item['extras']['shipping'])) { $shipping += (double) $item['extras']['shipping']; $this->m_cart[$id]['shipping'] = $item['extras']['shipping']; } } $item_total = $item_price * $item['quantity']; $T->set_var(array('cart_item_id' => $id, 'pi_url' => PAYPAL_URL, 'cart_id' => $item['item_id'], 'pp_id' => $counter, 'item_id' => $item_id, 'item_descrip' => $item['descrip'], 'item_price' => COM_numberFormat($item_price, 2), 'item_quantity' => $item['quantity'], 'item_total' => COM_numberFormat($item_total, 2), 'item_link' => is_numeric($item_id) ? 'true' : '')); $T->parse('iRow', 'ItemRow', true); $subtotal += $item_total; } $custom_info = array('uid' => $_USER['uid'], 'transtype' => 'cart_upload', 'cart_id' => $this->cartID()); $total = $subtotal + $shipping; // A little hack to show only the total if there are no other // charges //if ($total == $subtotal) $subtotal = 0; // Format the TOC link, if any if (!empty($_PP_CONF['tc_link'])) { $tc_link = str_replace('{site_url}', $_CONF['site_url'], $_PP_CONF['tc_link']); } else { $tc_link = ''; } $T->set_var(array('paypal_url' => $_PP_CONF['paypal_url'], 'receiver_email' => $_PP_CONF['receiver_email'][0], 'custom' => serialize($custom_info), 'shipping' => $shipping > 0 ? $currency->Format($shipping) : '', 'subtotal' => $subtotal > 0 ? $currency->Format($subtotal) : '', 'total' => $currency->Format($total), 'order_instr' => htmlspecialchars($this->getInstructions()), 'tc_link' => $tc_link)); // If this is the final checkout, then show the payment buttons if ($checkout) { $T->set_var(array('gateway_vars' => $this->getCheckoutButtons(), 'checkout' => 'true')); } $T->parse('output', 'cart'); $form = $T->finish($T->get_var('output')); return $form; }
/** * Returns -1, 0, or 1 if the first Product title is smaller, equal to, * or greater than the second, respectively * @param Product $objProduct1 Product #1 * @param Product $objProduct2 Product #2 * @return integer -1, 0, or 1 */ static function cmpPrice($objProduct1, $objProduct2) { return $objProduct1->getPrice() == $objProduct2->getPrice() ? 0 : ($objProduct1->getPrice() < $objProduct2->getPrice() ? -1 : 1); }
} public function getShippingCost() { return $this->_product->getPrice() + $this->_size + $this->_weight; } } class ProdWithDiscount extends Product { public function __construct(Product $product) { $this->_product = $product; $this->setPrice(); } public function setPrice() { $price = $this->_product->getPrice(); $this->_price = $price - $this->getDiscount(); } public function getDiscount() { return 2; } } $product = new Product(10); echo "Standard Product Price: " . $product->getPrice(); $productWithVat = new ProdWithVat($product); echo "<br/>Price After addind 5% VAT: " . $productWithVat->getPrice(); $productWithShipping = new ProdWithShippingCost($productWithVat); echo "<br/>Price After addind Shipping Cost: " . $productWithShipping->getPrice(); $productWithDiscount = new ProdWithShippingCost(new ProdWithVat(new ProdWithDiscount($product))); echo '<br/><br/>Final Price after discount: ' . $productWithDiscount->getPrice();
if (Tools::getValue('DownloadProductStock')) { $filename = "SnapDeal_ProductStock.csv"; $outstream = fopen("php://output", 'w'); if ($id_category === 2) { $header = array("Web page Number", "SKU Code", "Product Name", "WEIGHT (grams)", "MRP", "SELLING PRICE", "FULFILLMENT MODE", "COURIER TYPE", "Wooden Packaging", "Volumetric Weight", "Inventory", "Shipping Time in Days"); fputcsv($outstream, $header, ',', '"'); while ($line = fgetcsv($f)) { $id_product = (int) $line[0]; $product = new Product($id_product, true, 1); $data = array(); $data[] = $id_product; $data[] = $product->reference; $data[] = $product->name; $data[] = (double) $product->weight * 1000; $data[] = (int) round(Tools::convertPrice($product->getPriceWithoutReduct(), 4)); $data[] = (int) round(Tools::convertPrice($product->getPrice(), 4)); $data[] = "Dropshipment"; $data[] = "Surface"; $data[] = "No"; $data[] = ""; $data[] = (int) Product::getQuantity($id_product); $data[] = (int) $product->shipping_sla; fputcsv($outstream, $data, ',', '"'); } } else { if ($id_category === 4) { $header = array("Web page Number", "SKU Code", "Product Name", "WEIGHT (grams)", "MRP", "SELLING PRICE", "FULFILLMENT MODE", "COURIER TYPE", "Wooden Packaging", "Volumetric Weight", "Inventory", "Shipping Time in Days"); fputcsv($outstream, $header, ',', '"'); while ($line = fgetcsv($f)) { $id_product = (int) $line[0]; $product = new Product($id_product, true, 1);
/** * @param \Product $product * * @return float * @throws \Exception * @author Panagiotis Vagenas <*****@*****.**> * @since 150213 */ protected function getProductPrice(\Product &$product) { $option = $this->Options->getValue('map_price_with_vat'); switch ($option) { case 1: $price = round($product->price, 2); break; case 2: $price = round($product->wholesale_price, 2); break; default: $price = $product->getPrice(true, null, 2); break; } return $price; }
protected function getOrderTotal($id_product, $id_product_attribute = NULL, $qty) { if ($id_product != 0) { $p = new Product($id_product); return $p->getPrice(true, $id_product_attribute, 6, NULL, false, true, $qty) * $qty; } else { return $this->context->cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING); } }
/** * @param Product $product to get the product properties * @param array $combination to get particular properties from a declination * @param int $lang id lang to take all text in good language * @param Link $link to set the link of the product and its images. * @param Carrier $carrier not used now, but usable for next version, needed for calculate the shipping cost, * But for now it's not sure enough. * @return array with good value for the XML. */ private function preparedValues(Product $product, $combination, $lang, Link $link, Carrier $carrier) { $arr_return = array(); $str_features = array(); $model = array(); $version = str_replace('.', '', _PS_VERSION_); // To build description and model tags. if (isset($combination['attributes'])) { foreach ($combination['attributes'] as $attribut) { $str_features[] = $attribut['group_name'] . ' : ' . $attribut['name']; $model[] = $attribut['name']; } } if (isset($combination['weight']) && (int) $combination['weight'] !== 0) { $str_features[] = 'weight : ' . $combination['weight']; } elseif ($product->weight !== 0) { $str_features[] = 'weight : ' . $product->weight; } $features = $product->getFrontFeatures($lang); foreach ($features as $feature) { $str_features[] = $feature['name'] . ' : ' . $feature['value']; } // Category tag $category = new Category((int) $product->id_category_default, $lang); $category_path = (isset($category->id) and $category->id) ? Tools::getFullPath((int) $category->id, $product->name[$lang]) : Tools::getFullPath((int) $product->id_category_default, $product->name[$lang]); $category_path = Configuration::get('PS_NAVIGATION_PIPE') != false && Configuration::get('PS_NAVIGATION_PIPE') !== '>' ? str_replace(Configuration::get('PS_NAVIGATION_PIPE'), '>', $category_path) : $category_path; // image tag $id_image = isset($combination['id_image']) ? $combination['id_image'] : 0; if ($id_image === 0 || $id_image < 0) { $image = $product->getCover((int) $product->id); $id_image = $image['id_image']; } $quantity = Product::getQuantity($product->id, isset($combination['id_combination']) ? $combination['id_combination'] : NULL); $condition = ''; if (strlen((string) $version) < 2) { $version = (string) $version . '0'; } if ((int) substr($version, 0, 2) >= 14) { $condition = $product->condition === 'new' ? 0 : 1; } $price = $product->getPrice(true, isset($combination['id_combination']) ? $combination['id_combination'] : NULL, 2); $upc_ean = strlen((string) $product->ean13) == 13 ? $product->ean13 : ''; $arr_return['product_url'] = $link->getProductLink((int) $product->id, $product->link_rewrite[$lang], $product->ean13, $lang); $arr_return['designation'] = Tools::htmlentitiesUTF8($product->name[$lang] . ' ' . Manufacturer::getNameById($product->id_manufacturer) . ' ' . implode(' ', $model)); $arr_return['price'] = $price; $arr_return['category'] = Tools::htmlentitiesUTF8(strip_tags($category_path)); if (substr(_PS_VERSION_, 0, 3) == '1.3') { if (!Configuration::get('PS_SHOP_DOMAIN')) { Configuration::updateValue('PS_SHOP_DOMAIN', $_SERVER['HTTP_HOST']); } $prefix = 'http://' . Configuration::get('PS_SHOP_DOMAIN') . '/'; $arr_return['image_url'] = $prefix . $link->getImageLink('', $product->id . '-' . $id_image, 'large'); } else { $arr_return['image_url'] = $link->getImageLink($product->link_rewrite[$lang], $product->id . '-' . $id_image, 'large'); } // Must description added since Twenga-module v1.1 $arr_return['description'] = is_array($product->description) ? strip_tags($product->description[$lang]) : strip_tags($product->description); $arr_return['description'] = trim($arr_return['description'] . ' ' . strip_tags(implode(', ', $str_features))); $arr_return['description'] = Tools::htmlentitiesUTF8($arr_return['description']); $arr_return['brand'] = Manufacturer::getNameById($product->id_manufacturer); $arr_return['merchant_id'] = $product->id; $arr_return['manufacturer_id'] = $product->id_manufacturer; $arr_return['shipping_cost'] = 'NC'; $arr_return['in_stock'] = $quantity > 0 ? 'Y' : 'N'; $arr_return['stock_detail'] = $quantity; $arr_return['condition'] = $condition; $arr_return['upc_ean'] = $upc_ean; $arr_return['eco_tax'] = $product->ecotax; // for prestashop 1.4 and previous version these fields are not managed. // So default values are set. $arr_return['product_type'] = '1'; $arr_return['isbn'] = ''; return $arr_return; }
/** * Load simulator on product page if KWIXO_SHOW_SIMULATOR is enabled * * @global type $smarty * @param type $params * @return boolean */ public function hookExtraRight($params) { if (Configuration::get('KWIXO_SHOW_SIMULATOR') == '1') { if (_PS_VERSION_ < '1.5') { $kwixo = new KwixoPayment(); } else { $kwixo = new KwixoPayment($params['cart']->id_shop); } $product = new Product(Tools::getValue('id_product')); //check if price > 150 euro if ($product->getPrice() >= '150' && Configuration::get('KWIXO_OPTION_CREDIT') == '1') { $this->smarty->assign('urlsimul', "https://secure.kwixo.com/credit/calculator.htm?merchantId=" . $kwixo->getSiteId() . "&amount=" . $product->getPrice()); $this->smarty->assign('logo_simul_credit', __PS_BASE_URI__ . 'modules/' . $this->name . '/img/simulcred.jpg'); return $this->display(__FILE__, '/views/templates/hook/simulcred.tpl'); } else { return false; } } else { return false; } }
/** * Récupération du prix de shipping pour un produit id * @param $shipping * @return float */ public function getShippingPrice($product_id, $attribute_id, $id_carrier = 0, $id_zone = 0) { $product = new Product($product_id); $shipping = 0; $carrier = new Carrier((int) $id_carrier); if ($id_zone == 0) { $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); $id_zone = (int) $defaultCountry->id_zone; } $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id); $free_weight = Configuration::get('PS_SHIPPING_FREE_WEIGHT'); $shipping_handling = Configuration::get('PS_SHIPPING_HANDLING'); if ($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1) >= (double) $free_weight and (double) $free_weight > 0) { $shipping = 0; } elseif (isset($free_weight) and $product->weight >= (double) $free_weight and (double) $free_weight > 0) { $shipping = 0; } else { if (isset($shipping_handling) and $carrier->shipping_handling) { $shipping = (double) $shipping_handling; } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping += $carrier->getDeliveryPriceByWeight($product->weight, $id_zone); } else { $shipping += $carrier->getDeliveryPriceByPrice($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1), $id_zone); } $shipping *= 1 + $carrierTax / 100; $shipping = (double) Tools::ps_round((double) $shipping, 2); } unset($product); return $shipping; }
public function getPrice() { return parent::getPrice(); }