Product PHP Class Code Examples

This page contains top rated real world PHP examples of class Product extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: StocksAPITest.php Project: booko/pasteque-server
0
 protected function setUp()
 {
     // Products
     $taxCat = new TaxCat("Tax");
     $tax = new Tax(null, "Tax", stdtimefstr("2001-01-01 00:00:00"), 0.1);
     $taxCat->addTax($tax);
     $taxCat->id = TaxesService::createCat($taxCat);
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd1 = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, true, 0.3, null, "12345", false, true, 0.2);
     $prd1->id = ProductsService::create($prd1);
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 3, $taxCat->id, true, false);
     $prd2->id = ProductsService::create($prd2);
     $this->products = array($prd1, $prd2);
     // Locations
     $locSrv = new LocationsService();
     $loc1 = new Location("Location1");
     $loc1->id = $locSrv->create($loc1);
     $loc2 = new Location("Location2");
     $loc2->id = $locSrv->create($loc2);
     $this->locations = array($loc1, $loc2);
     // Stocks
     $lvl11 = new StockLevel($prd1->id, $loc1->id, null, null, 10);
     $lvl11->id = StocksService::createLevel($lvl11);
     $lvl12 = new StockLevel($prd1->id, $loc2->id, null, 5.2, null);
     $lvl12->id = StocksService::createLevel($lvl12);
     $lvl21 = new StockLevel($prd2->id, $loc1->id, null, 7, 20);
     $lvl21->id = StocksService::createLevel($lvl21);
     $move = new StockMove(stdtimefstr("2014-01-01 00:00:00"), StockMove::REASON_IN_BUY, $loc1->id, $prd1->id, null, 3.5, 2.1);
     StocksService::addMove($move);
     $this->levels = array($lvl11, $lvl12, $lvl21);
 }
Example #2
Show file File: CartContainsCategoriesTest.php Project: margery/thelia
0
 /**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $stubFacade->expects($this->any())->method('getCartTotalPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $category1 = new Category();
     $category1->setId(10);
     $category2 = new Category();
     $category2->setId(20);
     $category3 = new Category();
     $category3->setId(30);
     $product1 = new Product();
     $product1->addCategory($category1)->addCategory($category2);
     $product2 = new Product();
     $product2->addCategory($category3);
     $cartItem1Stub = $this->getMockBuilder('\\Thelia\\Model\\CartItem')->disableOriginalConstructor()->getMock();
     $cartItem1Stub->expects($this->any())->method('getProduct')->will($this->returnValue($product1));
     $cartItem1Stub->expects($this->any())->method('getQuantity')->will($this->returnValue(1));
     $cartItem2Stub = $this->getMockBuilder('\\Thelia\\Model\\CartItem')->disableOriginalConstructor()->getMock();
     $cartItem2Stub->expects($this->any())->method('getProduct')->will($this->returnValue($product2));
     $cartItem2Stub->expects($this->any())->method('getQuantity')->will($this->returnValue(2));
     $cartStub = $this->getMockBuilder('\\Thelia\\Model\\Cart')->disableOriginalConstructor()->getMock();
     $cartStub->expects($this->any())->method('getCartItems')->will($this->returnValue([$cartItem1Stub, $cartItem2Stub]));
     $stubFacade->expects($this->any())->method('getCart')->will($this->returnValue($cartStub));
     return $stubFacade;
 }
Example #3
Show file File: ProductsTableSeeder.php Project: sanderdekroon/yourfoodbox
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $ratatouille = new App\Product();
     $ratatouille->week_no = date('W');
     $ratatouille->year = date('Y');
     $ratatouille->name = 'Ratatouille';
     $ratatouille->description = 'Ratatouille is een Frans gerecht van gestoofde groenten, dat vooral in de Provence veel wordt bereid.';
     $ratatouille->city_id = 1;
     $ratatouille->save();
     $spaghetti = new App\Product();
     $spaghetti->week_no = date('W');
     $spaghetti->year = date('Y');
     $spaghetti->name = 'Spaghetti';
     $spaghetti->description = 'Lorem ipsum.';
     $spaghetti->city_id = 1;
     $spaghetti->save();
     $visgerecht = new App\Product();
     $visgerecht->week_no = date('W');
     $visgerecht->year = date('Y');
     $visgerecht->name = 'Visgerecht';
     $visgerecht->description = 'Lorem ipsum.';
     $visgerecht->city_id = 2;
     $visgerecht->save();
     $testgerecht = new App\Product();
     $testgerecht->week_no = date('W');
     $testgerecht->year = date('Y');
     $testgerecht->name = 'Test gerecht';
     $testgerecht->description = 'Lorem ipsum.';
     $testgerecht->city_id = 2;
     $testgerecht->save();
 }
Example #4
Show file File: candystore.php Project: NaszvadiG/candystore
0
 function update($id)
 {
     $this->load->library('form_validation');
     $this->form_validation->set_rules('name', 'Name', 'required');
     $this->form_validation->set_rules('description', 'Description', 'required');
     $this->form_validation->set_rules('price', 'Price', 'required');
     // If form data is valid, update the database with new details
     if ($this->form_validation->run() == true) {
         $product = new Product();
         $product->id = $id;
         $product->name = $this->input->get_post('name');
         $product->description = $this->input->get_post('description');
         $product->price = $this->input->get_post('price');
         $this->product_model->update($product);
         //Then we redirect to the index page again
         redirect('', 'refresh');
     } else {
         // Otherwise go back to edit page (with old data)
         $product = new Product();
         $product->id = $id;
         $product->name = set_value('name');
         $product->description = set_value('description');
         $product->price = set_value('price');
         $data['product'] = $product;
         $this->load->view('product/editForm.php', $data);
     }
 }
Example #5
Show file File: AdvancedQueryTest.php Project: Dren-x/mobit
0
 private function populate()
 {
     $em = $this->getMockSqliteEntityManager();
     $cheep = new Tag();
     $cheep->setName('Cheep');
     $new = new Tag();
     $new->setName('New');
     $special = new Tag();
     $special->setName('Special');
     $starship = new Product();
     $starship->setTitle('Starship');
     $starship->setPrice(277.66);
     $starship->addTag($new);
     $starship->addTag($special);
     $cheese = new Product();
     $cheese->setTitle('Cheese');
     $cheese->setPrice(7.66);
     $cheese->addTag($cheep);
     $shoe = new Product();
     $shoe->setTitle('Shoe');
     $shoe->setPrice(2.66);
     $shoe->addTag($special);
     $em->persist($special);
     $em->persist($cheep);
     $em->persist($new);
     $em->persist($starship);
     $em->persist($cheese);
     $em->persist($shoe);
     $em->flush();
 }
Example #6
Show file File: AdminOrdersController.php Project: jicheng17/pengwine
0
 protected function reinjectQuantity($order_detail, $qty_cancel_product)
 {
     // Reinject product
     $reinjectable_quantity = (int) $order_detail->product_quantity - (int) $order_detail->product_quantity_reinjected;
     $quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
     // @since 1.5.0 : Advanced Stock Management
     $product_to_inject = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
     $product = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) {
         $manager = StockManagerFactory::getManager();
         $movements = StockMvt::getNegativeStockMvts($order_detail->id_order, $order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject);
         $left_to_reinject = $quantity_to_reinject;
         foreach ($movements as $movement) {
             if ($left_to_reinject > $movement['physical_quantity']) {
                 $quantity_to_reinject = $movement['physical_quantity'];
             }
             $left_to_reinject -= $quantity_to_reinject;
             $manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
         }
         StockAvailable::synchronize($order_detail->product_id);
     } elseif ($order_detail->id_warehouse == 0) {
         StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject, $order_detail->id_shop);
     } else {
         $this->errors[] = Tools::displayError('Cannot re-stock product');
     }
 }
Example #7
Show file File: dialogmanager.php Project: lxthien/batdongsan
0
 function productMultiDialog($productId = 0)
 {
     $chooseProduct = new Product($productId);
     $product = new Product();
     $dis['searchKey'] = "";
     $dis['searchProductCat'] = "";
     $dis['searchProductCatId'] = "";
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $searchKey = $this->input->post('searchName');
         $searchProductCat = $this->input->post('searchProductCat');
         $searchProductCatId = $this->input->post('searchProductCatId');
         $product->like("name", $searchKey);
         if ($searchProductCatId != "") {
             $product->where_related_productcat('id', $searchProductCatId);
         }
         $dis['searchKey'] = $searchKey;
         $dis['searchProductCat'] = $searchProductCat;
         $dis['searchProductCatId'] = $searchProductCatId;
         $dis['isSearch'] = true;
     }
     if ($productId != 0 && $chooseProduct->accessory->result_count() > 0) {
         $product->where_not_in('id', $chooseProduct->accessory);
     }
     $product->order_by("name", "asc");
     $product->get_iterated(100);
     $dis['chooseProduct'] = $chooseProduct;
     $dis['base_url'] = base_url();
     $dis['product'] = $product;
     $this->load->view("admin/layout/dialogContent/productMultiSelectDialogContent", $dis);
 }
Example #8
Show file File: SearchControllerTest.php Project: ollietb/sulu
0
 private function indexProducts()
 {
     $product = new Product();
     $product->id = 6;
     $product->title = 'Product Xeon';
     $product->body = 'To be or not to be, that is the question';
     $product->url = '/foobar';
     $product->locale = 'fr';
     $product->created = new \DateTime('2015-04-10T00:00:00+00:00');
     $product->changed = new \DateTime('2015-04-12T00:00:00+00:00');
     $product->changer = $this->user;
     $product->creator = $this->user;
     $this->searchManager->index($product);
     $product = new Product();
     $product->id = 7;
     $product->title = 'Car Xeon';
     $product->body = 'To be or not to be, that is the question';
     $product->url = '/foobar';
     $product->locale = 'fr';
     $product->created = new \DateTime('2015-04-10T00:00:00+00:00');
     $product->changed = new \DateTime('2015-04-12T00:00:00+00:00');
     $product->changer = $this->user;
     $product->creator = $this->user;
     $this->searchManager->index($product);
 }
Example #9
Show file File: Link.php Project: jicheng17/vipinsg
0
 /**
  * Create a link to a product
  *
  * @param mixed $product Product object (can be an ID product, but deprecated)
  * @param string $alias
  * @param string $category
  * @param string $ean13
  * @param int $id_lang
  * @param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart
  * @param int $ipa ID product attribute
  * @return string
  */
 public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0, $force_routes = false)
 {
     $dispatcher = Dispatcher::getInstance();
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     if (!$id_shop) {
         $shop = Context::getContext()->shop;
     } else {
         $shop = new Shop($id_shop);
     }
     $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang);
     if (!is_object($product)) {
         if (is_array($product) && isset($product['id_product'])) {
             $product = new Product($product['id_product'], false, $id_lang);
         } else {
             if (is_numeric($product) || !$product) {
                 $product = new Product($product, false, $id_lang);
             } else {
                 throw new PrestaShopException('Invalid product vars');
             }
         }
     }
     // Set available keywords
     $params = array();
     $params['id'] = $product->id;
     $params['rewrite'] = !$alias ? $product->getFieldByLang('link_rewrite') : $alias;
     $params['ean13'] = !$ean13 ? $product->ean13 : $ean13;
     $params['category'] = !$category ? $product->category : $category;
     $params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords'));
     $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title'));
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'manufacturer')) {
         $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'supplier')) {
         $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'price')) {
         $params['price'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specificPrice);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'tags')) {
         $params['tags'] = Tools::str2url($product->getTags($id_lang));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'reference')) {
         $params['reference'] = Tools::str2url($product->reference);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories')) {
         $cats = array();
         foreach ($product->getParentCategories() as $cat) {
             $cats[] = $cat['link_rewrite'];
         }
         $params['categories'] = implode('/', $cats);
     }
     $anchor = $ipa ? $product->getAnchor($ipa) : '';
     return $url . $dispatcher->createUrl('product_rule', $id_lang, $params, $force_routes, $anchor);
 }
Example #10
Show file File: ProductTest.php Project: matsubo/spike-php
0
 public function testJsonSerialize()
 {
     $product = new Product('product');
     $product->setTitle('title')->setDescription('description')->setPrice(new Money(100, 'JPY'))->setLanguage('JP')->setCount(1)->setStock(9);
     $expectedJson = json_encode(['id' => 'product', 'title' => 'title', 'description' => 'description', 'language' => 'JP', 'price' => 100, 'currency' => 'JPY', 'count' => 1, 'stock' => 9]);
     $this->assertEquals($expectedJson, json_encode($product));
     $product = new Product('product');
     $expectedJson = json_encode(['id' => 'product', 'title' => null, 'description' => null, 'language' => null, 'price' => null, 'currency' => null, 'count' => null, 'stock' => null]);
     $this->assertEquals($expectedJson, json_encode($product), 'Should be serializable as json even if has not set any value at all');
 }
Example #11
Show file File: Link.php Project: carloslastresDev/HealthyTaiwan_UsingPrestaShop
0
 /**
  * Create a link to a product
  *
  * @param mixed $product Product object (can be an ID product, but deprecated)
  * @param string $alias
  * @param string $category
  * @param string $ean13
  * @param int $id_lang
  * @param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart
  * @param int $ipa ID product attribute
  * @return string
  */
 public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null, $ipa = 0, $force_routes = false)
 {
     $dispatcher = Dispatcher::getInstance();
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     $url = $this->getBaseLink($id_shop) . $this->getLangLink($id_lang, null, $id_shop);
     if (!is_object($product)) {
         if (is_array($product) && isset($product['id_product'])) {
             $product = new Product($product['id_product'], false, $id_lang, $id_shop);
         } elseif ((int) $product) {
             $product = new Product((int) $product, false, $id_lang, $id_shop);
         } else {
             throw new PrestaShopException('Invalid product vars');
         }
     }
     // Set available keywords
     $params = array();
     $params['id'] = $product->id;
     $params['rewrite'] = !$alias ? $product->getFieldByLang('link_rewrite') : $alias;
     $params['ean13'] = !$ean13 ? $product->ean13 : $ean13;
     $params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords'));
     $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title'));
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'manufacturer', $id_shop)) {
         $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'supplier', $id_shop)) {
         $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'price', $id_shop)) {
         $params['price'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specificPrice);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'tags', $id_shop)) {
         $params['tags'] = Tools::str2url($product->getTags($id_lang));
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'category', $id_shop)) {
         $params['category'] = !is_null($product->category) && !empty($product->category) ? Tools::str2url($product->category) : Tools::str2url($category);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'reference', $id_shop)) {
         $params['reference'] = Tools::str2url($product->reference);
     }
     if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories', $id_shop)) {
         $params['category'] = !$category ? $product->category : $category;
         $cats = array();
         foreach ($product->getParentCategories() as $cat) {
             if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) {
                 //remove root and home category from the URL
                 $cats[] = $cat['link_rewrite'];
             }
         }
         $params['categories'] = implode('/', $cats);
     }
     $anchor = $ipa ? $product->getAnchor($ipa) : '';
     return $url . $dispatcher->createUrl('product_rule', $id_lang, $params, $force_routes, $anchor, $id_shop);
 }
Example #12
Show file File: ChargeRequestTest.php Project: matsubo/spike-php
0
 public function testOtherAccessors()
 {
     $request = new ChargeRequest();
     $this->assertTrue($request->isCapture());
     $this->assertSame([], $request->getProducts());
     $request->setCapture(false)->addProduct($productA = new Product('product-a-id'))->addProduct($productB = new Product('product-b-id'));
     $this->assertFalse($request->isCapture());
     $this->assertCount(2, $request->getProducts());
     $this->assertSame($productA, $request->getProducts()[0]);
     $this->assertSame($productB, $request->getProducts()[1]);
 }
Example #13
Show file File: sendtoafriend2.php Project: greench/prestashop
0
 public function displayFrontForm()
 {
     global $smarty;
     $error = false;
     $confirm = false;
     if (isset($_POST['submitAddtoafriend'])) {
         global $cookie, $link;
         /* Product informations */
         $product = new Product((int) Tools::getValue('id_product'), false, (int) $cookie->id_lang);
         $productLink = $link->getProductLink($product);
         /* Fields verifications */
         if (empty($_POST['email']) or empty($_POST['name'])) {
             $error = $this->l('You must fill in all fields.');
         } elseif (empty($_POST['email']) or !Validate::isEmail($_POST['email'])) {
             $error = $this->l('The e-mail given is invalid.');
         } elseif (!Validate::isName($_POST['name'])) {
             $error = $this->l('The name given is invalid.');
         } elseif (!isset($_GET['id_product']) or !is_numeric($_GET['id_product'])) {
             $error = $this->l('An error occurred during the process.');
         } else {
             /* Email generation */
             $subject = ($cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : $this->l('A friend')) . ' ' . $this->l('sent you a link to') . ' ' . $product->name;
             $templateVars = array('{product}' => $product->name, '{product_link}' => $productLink, '{customer}' => $cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : $this->l('A friend'), '{name}' => Tools::safeOutput($_POST['name']));
             /* Email sending */
             if (!Mail::Send((int) $cookie->id_lang, 'send_to_a_friend', Mail::l('A friend sent you a link to') . ' ' . $product->name, $templateVars, $_POST['email'], NULL, $cookie->email ? $cookie->email : NULL, $cookie->customer_firstname ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : NULL, NULL, NULL, dirname(__FILE__) . '/mails/')) {
                 $error = $this->l('An error occurred during the process.');
             } else {
                 Tools::redirect(_MODULE_DIR_ . '/' . $this->name . '/sendtoafriend-form.php?id_product=' . (int) $product->id . '&submited');
             }
         }
     } else {
         global $cookie, $link;
         /* Product informations */
         $product = new Product((int) Tools::getValue('id_product'), false, (int) $cookie->id_lang);
         $productLink = $link->getProductLink($product);
     }
     /* Image */
     $images = $product->getImages((int) $cookie->id_lang);
     foreach ($images as $k => $image) {
         if ($image['cover']) {
             $cover['id_image'] = (int) $product->id . '-' . (int) $image['id_image'];
             $cover['legend'] = $image['legend'];
         }
     }
     if (!isset($cover)) {
         $cover = array('id_image' => Language::getIsoById((int) $cookie->id_lang) . '-default', 'legend' => 'No picture');
     }
     $smarty->assign(array('cover' => $cover, 'errors' => $error, 'confirm' => $confirm, 'product' => $product, 'productLink' => $productLink));
     return $this->display(__FILE__, 'sendtoafriend.tpl');
 }
Example #14
Show file File: LoadProductData.php Project: wizardcoding/newSite
0
 public function load(ObjectManager $manager)
 {
     $product = new Product();
     $product->setName('ProductOne');
     $product->setPrice(8.550000000000001);
     $product->setQuanity(50);
     $product2 = new Product();
     $product2->setName('ProductTwo');
     $product2->setPrice(9.25);
     $product2->setQuanity(8);
     $manager->persist($product);
     $manager->persist($product2);
     $manager->flush();
 }
Example #15
Show file File: AdminOrdersController.php Project: ekachandrasetiawan/BeltcareCom
0
 /**
  * @param OrderDetail $order_detail
  * @param int $qty_cancel_product
  * @param bool $delete
  */
 protected function reinjectQuantity($order_detail, $qty_cancel_product, $delete = false)
 {
     // Reinject product
     $reinjectable_quantity = (int) $order_detail->product_quantity - (int) $order_detail->product_quantity_reinjected;
     $quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
     // @since 1.5.0 : Advanced Stock Management
     $product_to_inject = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
     $product = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) {
         $manager = StockManagerFactory::getManager();
         $movements = StockMvt::getNegativeStockMvts($order_detail->id_order, $order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject);
         $left_to_reinject = $quantity_to_reinject;
         foreach ($movements as $movement) {
             if ($left_to_reinject > $movement['physical_quantity']) {
                 $quantity_to_reinject = $movement['physical_quantity'];
             }
             $left_to_reinject -= $quantity_to_reinject;
             if (Pack::isPack((int) $product->id)) {
                 // Gets items
                 if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) {
                     $products_pack = Pack::getItems((int) $product->id, (int) Configuration::get('PS_LANG_DEFAULT'));
                     // Foreach item
                     foreach ($products_pack as $product_pack) {
                         if ($product_pack->advanced_stock_management == 1) {
                             $manager->addProduct($product_pack->id, $product_pack->id_pack_product_attribute, new Warehouse($movement['id_warehouse']), $product_pack->pack_quantity * $quantity_to_reinject, null, $movement['price_te'], true);
                         }
                     }
                 }
                 if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)) {
                     $manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
                 }
             } else {
                 $manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
             }
         }
         $id_product = $order_detail->product_id;
         if ($delete) {
             $order_detail->delete();
         }
         StockAvailable::synchronize($id_product);
     } elseif ($order_detail->id_warehouse == 0) {
         StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject, $order_detail->id_shop);
         if ($delete) {
             $order_detail->delete();
         }
     } else {
         $this->errors[] = Tools::displayError('This product cannot be re-stocked.');
     }
 }
Frequently Used Methods